ST_GeomFromGML
What is ST_GeomFromGML?
ST_GeomFromGML parses a GML 2 or 3 XML string and returns the corresponding PostGIS geometry. An optional default SRID tags the output when the GML does not include one.
1ST_GeomFromGML(text gml) → geometry
2ST_GeomFromGML(text gml, integer srid) → geometryGML CRS declarations (e.g. srsName="EPSG:4326") are honoured when present.
When would you use ST_GeomFromGML?
Use ST_GeomFromGML when ingesting OGC Web Feature Service (WFS) responses, Inspire data packages, or European government open-data feeds that use GML as the exchange format. It understands both GML 2 and GML 3 encodings including arcs, compound curves, and surfaces.
It is also the preferred constructor for datasets with mixed geometry types where the GML schema drives the structure — GeoJSON is simpler but GML retains more OGC type fidelity.
FAQs
Which GML versions are supported?
Both GML 2 and GML 3, including GML 3 curve types (Arc, Circle, CompositeCurve, etc.).
How is axis order handled?
GML 3 with an EPSG srsName may imply latitude, longitude order. PostGIS follows the GML axis-order rules defined by the CRS authority unless the ?axis-order= hint overrides them.
Does it handle `srsName` URNs?
Yes. Common URN formats like urn:ogc:def:crs:EPSG::4326 are parsed and mapped to SRID 4326.
How is it different from ST_GMLToSQL?
ST_GMLToSQL is the SQL/MM spelling and functionally equivalent.