ST_WKTToSQL function
The ST_WKTToSQL function takes a well-known text representation of a geometry and returns the corresponding geometry.
If the given well-known text representation is null, then null is returned.
The ST_WKTToSQL function is identical to the ST_GeomFromText function. ST_WKTToSQL(wkt) gives the same result as ST_Geometry(wkt,0). The use of the ST_Geometry function gives you more flexibility that the ST_WKTToSQL function because ST_Geometry takes additional forms of input as well as the well-known text representation.
Syntax
Parameter
- wkt
- A value of type CLOB(2G) that contains the well-known text representation of the resulting geometry.
- srsId
- A value of type INTEGER that uniquely identifies the spatial reference system. The spatial reference system with the identifier 0 (zero) is used for the resulting geometry. The default value for the srsID is ip7.
Return type
db2gse.ST_Geometry
Example
In the following example, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display.
This example illustrates how ST_WKTToSQL can create and insert geometries using their well-known
text representations.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geometries (id INTEGER, geometry ST_Geometry)
INSERT INTO sample_geometries
VALUES (10, ST_WKTToSQL( 'point (44 14)' ) ),
(11, ST_WKTToSQL ( 'point (24 13)' ) ),
(12, ST_WKTToSQL ('polygon ((50 20, 50 40, 70 30, 50 20))' ) )
This
SELECT statement returns the geometries that have been inserted.
SELECT id, CAST( ST_AsText(geometry) AS VARCHAR(120) ) GEOMETRIES
FROM sample_geometries
Results:
ID GEOMETRIES
----------- -------------------------------------------------------------
10 POINT ( 44.00000000 14.00000000)
11 POINT ( 24.00000000 13.00000000)
12 POLYGON (( 50.00000000 20.00000000, 70.00000000 30.00000000,
50.00000000 40.00000000, 50.00000000 20.00000000))