ST_MPolyFromWKB function
The ST_MPolyFromWKB function takes a well-known binary (WKB) representation of a multipolygon and, optionally, a spatial reference system identifier as input parameters and returns the corresponding multipolygon.
If the specified WKB format is null, then null is returned.
The recommended function for achieving the same result is the ST_MultiPolygon function. It is recommended because of its flexibility: ST_MultiPolygon takes additional forms of input as well as the well-known binary format.
Syntax
Parameters
- wkb
- A value of type VARBINARY or BLOB(2G) that contains the well-known binary format of the resulting multipolygon.
- srs_id
- A value of type INTEGER that identifies the spatial reference
system for the resulting multipolygon.
If the srs_id parameter is omitted, the spatial reference system with the numeric identifier 4326 is used.
If the specified srs_id does not identify a spatial reference system listed in the catalog view SYSGEO.ST_SPATIAL_REFERENCE_SYSTEMS, then an exception condition is raised (SQLSTATE 38SU1).
Return type
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.
- 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)
CREATE TABLE sample_mpolys (id INTEGER,
geometry ST_MultiPolygon, wkb VARBINARY(32000))
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, 1) )
AS VARCHAR(320) ) MULTIPOLYGON
FROM sample_mpolys
WHERE id = 10
Results:
ID MULTIPOLYGON
--- --------------------------------------------------------------------
10 MULTIPOLYGON (((10.000000 20.000000, 30.000000 41.000000,
10.000000 40.000000, 10.000000 20.000000)),
((1.000000 72.000000, 5.000000 76.000000,
4.000000 79.000000, 1.000000 72.000000)),
((9.000000 43.000000, 6.000000 47.000000,
7.000000 44.000000, 9.000000 43.000000)))