ST_GeomFromWKB function
The ST_GeomFromWKB function takes a well-known binary representation of a geometry and, optionally, a spatial reference system identifier as input parameters and returns the corresponding geometry.
If the given well-known binary representation is null, then null is returned.
The preferred version for this functionality is ST_Geometry.
Syntax
Parameter
- wkb
- A value of type BLOB(2G) that contains the well-known binary representation of the resulting geometry.
- srs_id
- A value of type INTEGER that identifies the spatial reference system for the resulting geometry.
If the srs_id parameter is omitted, the spatial reference system with the numeric identifier 0 (zero) is used implicitly.
If the specified srs_id parameter does not identify a spatial reference system listed in the catalog view DB2GSE.ST_SPATIAL_REFERENCE_SYSTEMS, then an error is returned (SQLSTATE 38SU1).
Return type
db2gse.ST_Geometry
Examples
In the following examples, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display.
The following code illustrates how the ST_GeomFromWKB function can be used to create and insert a line from a well-known binary (WKB) line representation.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geometries (id INTEGER, geometry ST_GEOMETRY,
wkb BLOB(32K))
INSERT INTO sample_geometries(id, geometry)
VALUES
(1901, ST_GeomFromText('point(1 2)', 1) ),
(1902, ST_GeomFromText('linestring(33 2, 34 3, 35 6)', 1) ),
(1903, ST_GeomFromText('polygon((3 3, 4 6, 5 3, 3 3))', 1))
UPDATE sample_geometries AS temp_correlated
SET wkb = geometry..ST_AsBinary
WHERE id = temp_correlated.id
SELECT id, cast(ST_GeomFromWKB(wkb)..ST_AsText AS varchar(190))
AS geometry
FROM sample_geometries
ID GEOMETRY
----------- ----------------------------------------------------------
1901 POINT ( 1.00000000 2.00000000)
1902 LINESTRING ( 33.00000000 2.00000000, 34.00000000
3.00000000, 35.00000000 6.00000000)
1903 POLYGON (( 3.00000000 3.00000000, 5.00000000 3.00000000,
4.00000000 6.00000000, 3.00000000 3.00000000))