ST_AsBinary function

The ST_AsBinary function 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.

This function can also be called as a method.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_AsBinary(geometry)

Parameter

geometry
A value of type ST_Geometry or one of its subtypes to be converted to the corresponding well-known binary representation.

Return type

BLOB(2G)

Examples

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.

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 1
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_Point(wkb)..ST_AsText AS varchar(35)) AS point
FROM   sample_points
WHERE  id = 1111

Results:

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

Example 2
This example displays the WKB binary representation.

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

Results:

ID     POINT_WKB
------ ---------------------------------------------
  1100 x'010100000000000000000024400000000000003440'