The ST_PolyFromGML() function

The ST_PolyFromGML() function takes a GML2 or GML3 string representation of an ST_Polygon and an optional spatial reference ID and returns a polygon object.

Syntax

ST_PolyFromGML(gmlstring lvarchar)
ST_PolyFromGML(gmlstring lvarchar, SRID integer)

Return type

ST_Polygon

Example

The test_poly table is created with the INTEGER column id and the ST_Polygon column geom:
CREATE TABLE test_poly(id INTEGER, geom ST_Polygon);

INSERT INTO test_poly VALUES(1,ST_PolyFromGML('<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>',4));

This record specifies a spatial reference id of 4 (WGS84) and represents a two-dimensional six-sided polygon.

Output:
SELECT * FROM test_poly;

id    1
geom  4 POLYGON ((-84.3600000805 32.4900000536, -82.6599999799 
                  32.6899999866, -82.1500000335 32.4600000469, 
                  -83.0900000201 33.0800000738, -83.3700000268 
                  33.1899999866, -84.3600000805 32.4900000536))