ST_WellKnownBinary transform group

Use the ST_WellKnownBinary transform group to transmit data using the well-known binary (WKB) representation.

When binding out a value from the database to a client application, the same function provided by ST_AsBinary() is used to convert a geometry to the WKB representation. When the well-known binary representation of a geometry is transferred to the database, the ST_Geometry(BLOB) function is used implicitly 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).

Example

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_WellKnownBinary transform group to retrieve a geometry in its well-known binary representation without using the explicit ST_AsBinary function.

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

INSERT
   INTO transforms_sample
   VALUES ( 1, db2gse.ST_Polygon('polygon ((10 10, 20 10, 20 20, 
             10 20, 10 10))', 0))

SET CURRENT DEFAULT TRANSFORM GROUP = ST_WellKnownBinary

SELECT id, geom
   FROM transforms_sample
   WHERE id = 1
Results:

ID		  GEOM
----   ----------------------------------------------
   1   x'01030000000100000005000000000000000000244000
       0000000000244000000000000024400000000000003440
       0000000000003440000000000000344000000000000034
       4000000000000024400000000000002440000000000000
       2440'
Example 2
The following C code shows how to use the ST_WellKnownBinary transform group for inserting geometries using the explicit ST_Geometry function for the host-variable wkb_buffer, which is of type BLOB and contains the well-known binary representation of a geometry that is to be inserted.

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

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

// initialize host variables
...
// insert geometry using WKB into column of type ST_Geometry

EXEC SQL
   INSERT
	   INTO transforms_sample(id, geom)
	   VALUES ( :id, :wkb_buffer );