ST_AsBinary

ST_AsBinary takes a geometry as an input parameter and returns its well-known binary representation. The Z and M coordinates are discarded and will not be represented in the well-known binary representation.

If the given geometry is null, then null is returned.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_AsBinary(geometry)

Parameter

geometry
A value of one of the seven distinct spatial data types to be converted to the corresponding well-known binary representation.

Return type

BLOB(4M)

Examples

Example 1

The following code illustrates how to use the ST_AsBinary function to convert the points in the geometry columns of the SAMPLE_POINTS table into well-known binary (WKB) representation in the BLOB column.

SET CURRENT PATH = CURRENT PATH, db2gse;

CREATE TABLE SAMPLE_POINTS (id integer, geometry ST_POINT, wkb BLOB(32K));

INSERT INTO SAMPLE_POINTS (id, geometry)
VALUES
    (1100, ST_Point(10, 20, 1));

Example 2

This example populates the WKB column, with an ID of 1111, from the GEOMETRY column, with an ID of 1100.

INSERT INTO sample_points(id, wkb)
VALUES (1111,
  (SELECT  ST_AsBinary(geometry)
   FROM    sample_points
   WHERE   id = 1100));

SELECT id, cast(ST_AsText(ST_Point(wkb,1)) AS varchar(35)) AS point
FROM   sample_points
WHERE  id = 1111;

Results:

ID          Point
----------- -----------------------------------
       1111 POINT ( 10.00000000 20.00000000)

Example 3

This example displays the WKB binary representation.

SELECT id, HEX(substr(ST_AsBinary(geometry), 1, 21)) AS point_wkb
FROM   sample_points
WHERE  id = 1100;

Results:

ID     POINT_WKB
------ ---------------------------------------------
  1100 000000000140240000000000004034000000000000