The ST_MPolyFromGML() function
The ST_MPolyFromGML() function takes a GML2 or GML3 string representation of an ST_MultiPoly and an optional spatial reference ID and returns a multipart polygon object.
Syntax
ST_MPolyFromGML(gmlstring lvarchar)
ST_MPolyFromGML(gmlstring lvarchar, SRID integer)
Return type
ST_MultiPolygon
Example
The test_multipoly table
is created with the INTEGER column id and the ST_MultiPolygon
column geom:
CREATE TABLE test_multipoly (id INTEGER, geom ST_MultiPolygon);
INSERT INTO test_multipoly VALUES(1,ST_MPolyFromGML
('<gml:MultiPolygon srsName="EPSG:4326" srsDimension="2">
<gml:PolygonMember><gml:Polygon srsName="EPSG:4326" srsDimension="2">
<gml:exterior><gml:LinearRing><gml:posList dimension="2">
-94.36 32.49 -92.66 32.69 -92.15 32.46 -93.09 33.08 -93.37 33.19
-94.36 32.49</gml:posList></gml:LinearRing>
</gml:exterior></gml:Polygon></gml:PolygonMember>
<gml:PolygonMember><gml:Polygon srsName="EPSG:4326" srsDimension="2">
<gml:exterior><gml:LinearRing><gml:posList dimension="2">
-84.36 32.49 -82.66 32.69 -82.15 32.46 -83.09 33.08 -83.37 33.19
-84.36 32.49</gml:posList></gml:LinearRing></gml:exterior>
< /gml:Polygon></gml:PolygonMember></gml:MultiPolygon>',4));
This
record specifies a spatial reference ID of 4
(WGS84)
and both member polygons have a dimension of 2
and
six sides.
Output:
SELECT * FROM test_multipoly;
id 1
geom 4 MULTIPOLYGON (((-94.3600000805 32.4900000536, -92.6599999799
32.6899999866, -92.1500000335 32.4600000469,
-93.0900000201 33.0800000738, -93.3700000268
33.1899999866, -94.3600000805 32.4900000536)),
((-84.3600000805 32.4900000536, -82.6599999799
32.6899999866, -82.1500000335 32.4600000469,
-83.0900000201 33.0800000738, -83.3700000268
33.1899999866, -84.3600000805 32.4900000536)))