ST_MPolyFromWKB
ST_MPolyFromWKB takes a well-known binary representation of a multipolygon and a spatial reference system identifier as input parameters and returns the corresponding multipolygon.
If the given well-known binary representation is null, then null is returned.
Syntax
Parameters
- wkb
- A value of type BLOB(4M) that contains the well-known binary representation of the resulting multipolygon.
- srs_id
- A value of type INTEGER that identifies the spatial reference system for the resulting multipolygon.
Return type
db2gse.ST_MultiPolygon
Example
In the following example, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display.
This example
illustrates how ST_MPolyFromWKB can be used to create a multipolygon
from its well-known binary representation. The geometry is a multipolygon
in spatial reference system 1. In this example, the multipolygon gets
stored with ID = 10 in the GEOMETRY column of the SAMPLE_MPOLYS table,
and then the WKB column is updated with its well-known binary representation
(using the ST_AsBinary function). Finally, the ST_MPolyFromWKB function
is used to return the multipolygon from the WKB column. The X and
Y coordinates for this geometry are:
- Polygon 1: (1, 72) (4, 79) (5, 76) (1, 72)
- Polygon 2: (10, 20) (10, 40) (30, 41) (10, 20)
- Polygon 3: (9, 43) (7, 44) (6, 47) (9, 43)
The SAMPLE_MPOLYS table has a GEOMETRY column, where
the multipolygon is stored, and a WKB column, where the multipolygon's
well-known binary representation is stored.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_mpolys (id INTEGER,
geometry ST_MultiPolygon, wkb BLOB(32K))
INSERT INTO sample_mpolys
VALUES (10, ST_MultiPolygon ('multipolygon
(( (1 72, 4 79, 5 76, 1 72),
(10 20, 10 40, 30 41, 10 20),
(9 43, 7 44, 6 47, 9 43) ))', 1))
UPDATE sample_mpolys AS temporary_correlated
SET wkb = ST_AsBinary( geometry )
WHERE id = temporary_correlated.id
In the following SELECT statement, the ST_MPolyFromWKB
function is used to retrieve the multipolygon from the WKB column.
SELECT id, CAST( ST_AsText( ST_MPolyFromWKB (wkb) )
AS VARCHAR(320) ) MULTIPOLYGON
FROM sample_mpolys
WHERE id = 10
Results:
ID MULTIPOLYGON
---------- --------------------------------------------------------------------
10 MULTIPOLYGON ((( 10.00000000 20.00000000, 30.00000000
41.00000000, 10.00000000 40.00000000, 10.00000000
20.00000000)),
( 1.00000000 72.00000000, 5.00000000
76.00000000, 4.00000000 79.0000000, 1.00000000
72,00000000)),
( 9.00000000 43.00000000, 6.00000000
47.00000000, 7.00000000 44.00000000, 9.00000000
43.00000000 )))
