ST_WellKnownText transform group

Use the ST_WellKnownText transform group to transmit data using the well-known text (WKT) representation.

When binding out a value from the database to a client application, the same function provided by ST_AsText() is used to convert a geometry to the WKT representation. When the well-known text representation of a geometry is transferred to the database, the ST_Geometry(CLOB) function is implicitly used to perform the conversions to an ST_Geometry value. Using the transform group for binding in values causes the geometries to be represented in the spatial reference system with the numeric identifier 0 (zero).

Examples

In the following examples, the lines of results have been reformatted for readability. The spacing in your results might vary according to your online display.

Example 1
The following SQL script shows how to use the ST_WellKnownText transform group to retrieve a geometry in its well-known text representation without using the explicit ST_AsText function.

CREATE TABLE transforms_sample (
   id		 INTEGER,
   geom	 db2gse.ST_Geometry)

INSERT
   INTO	  transforms_sample
   VALUES (1, db2gse.ST_LineString('linestring 
          (100 100, 200 100)', 0))

SET CURRENT DEFAULT TRANSFORM GROUP = ST_WellKnownText

SELECT id, geom
  FROM   transforms_sample
  WHERE  id = 1

Results:

ID	  GEOM
---  -------------------------------------------------------------------
  1  LINESTRING ( 100.00000000 100.00000000, 200.00000000 100.00000000)
Example 2
The following C code shows how to use the ST_WellKnownText transform group to insert geometries using the explicit ST_Geometry function for the host-variable wkt_buffer, which is of type CLOB and contains the well-known text representation of the point (10 10) that is to be inserted.

EXEC SQL BEGIN DECLARE SECTION;
   sqlint32 id = 0;
   SQL TYPE IS db2gse.ST_Geometry AS CLOB(1000) wkt_buffer;
EXEC SQL END DECLARE SECTION;

// set the transform group for all subsequent SQL statements
EXEC SQL
   SET CURRENT DEFAULT TRANSFORM GROUP = ST_WellKnownText;

id = 100;
strcpy(wkt_buffer.data, "point ( 10 10 )");
wkt_buffer.length = strlen(wkt_buffer.data);

// insert point using WKT into column of type ST_Geometry
EXEC SQL
   INSERT
	   INTO	  transforms_sample(id, geom)
	   VALUES (:id, :wkt_buffer);