ST_GeomFromText

ST_GeomFromText takes a well-known text representation of a geometry and a spatial reference system identifier as input parameters and returns the corresponding geometry.

If the given well-known text representation is null, then null is returned.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_GeomFromText(wkt,srs_id)

Parameter

wkt
A value of type CLOB(8M) that contains the well-known text representation of the resulting geometry. If the well-known text representation is null, null is returned.
srs_id
A value of type INTEGER that identifies the spatial reference system for the resulting geometry. This parameter is required.

If srs_id does not identify a spatial reference system that is listed in the catalog view DB2GSE.ST_SPATIAL_REFERENCE_SYSTEMS, an error is returned (SQLSTATE 38SU1).

Return type

db2gse.ST_Geometry

Example

In this example the ST_GeomFromText function is used to create and insert a geometry from a well known text (WKT) point representation.

The following code inserts rows into the SAMPLE_POINTS table with IDs and geometries in spatial reference system 1 using WKT representation.

SET CURRENT PATH = CURRENT PATH, db2gse 

CREATE TABLE sample_geometries(id INTEGER, geometry ST_GEOMETRY)

INSERT INTO sample_geometries(id, geometry)
VALUES
    (1251, ST_GeomFromText('point(1 2)', 1) ),
    (1252, ST_GeomFromText('linestring(33 2, 34 3, 35 6)', 1) ),
    (1253, ST_GeomFromText('polygon((3 3, 4 6, 5 3, 3 3))', 1))

The following SELECT statement will return the ID and GEOMETRIES from the SAMPLE_GEOMETRIES table.

SELECT id, cast(DB2GSE.ST_AsText(geometry)  AS varchar(105)) 
   AS geometry 
FROM   sample_geometries  
Results:

ID          GEOMETRY
----------- ---------------------------------------------------------------
       1251 POINT ( 1.00000000 2.00000000)
                                          
       1252 LINESTRING ( 33.00000000 2.00000000, 34.00000000 3.00000000, 
              35.00000000 6.00000000)

       1253 POLYGON (( 3.00000000 3.00000000, 5.00000000 3.00000000, 
              4.00000000 6.00000000, 3.00000000 3.00000000))