Returns a Geography Markup Language (GML) element representing a geometry or geography object.
Syntax
text ST_AsGML(geometry geom, integer maxdecimaldigits, integer options)
text ST_AsGML(geography geog, integer maxdecimaldigits, integer options)
text ST_AsGML(integer version, geometry geom, integer maxdecimaldigits, integer options, text nprefix, text id)
text ST_AsGML(integer version, geography geog, integer maxdecimaldigits, integer options, text nprefix, text id)Parameters
| Parameter | Description |
|---|---|
geom | The geometry object to convert to GML. |
geog | The geography object to convert to GML. |
version | The GML version to use. Default: 2 (GML 2.1.2). Set to 3 for GML 3.1.1. |
maxdecimaldigits | The maximum number of decimal places to keep in coordinates. Default: 15. |
options | A bitmask controlling coordinate reference system (CRS) output and geometry representation. See Options below. |
nprefix | The namespace prefix. Default: NULL. |
id | The ID of the GML element. Default: NULL. Valid only when using GML version 3. |
Options
Combine multiple flags using the bitwise OR operator (|).
| Value | Effect |
|---|---|
0 | Include CRS using a short expression, for example EPSG:4326. |
1 | Include CRS using a long URN expression, for example urn:ogc:def:crs:EPSG::4326. |
2 | Remove the srsDimension attribute. GML version 3 only. |
4 | Use <LineString> instead of <Curve> for line objects. GML version 3 only. |
16 | Output latitude before longitude. Valid when the spatial reference identifier (SRID) is 4326. |
32 | Return the bounding box of the geometry object. |
Supported geometry types
Circular strings
Curves
Polyhedral surfaces (GML version 3 or later only)
Triangles
Triangulated irregular network (TIN) surfaces (GML version 3 or later only)
3D objects
Examples
Envelope with long CRS, bounding box, and lat-lon order (GML 3)
This example combines three options: long CRS expression (1), bounding box (32), and latitude-before-longitude (16). The combined bitmask is 1 | 16 | 32 = 49.
SELECT ST_AsGML(3, ST_GeomFromText('POINT(116 40)', 4326), 5, 32|16|1);Output:
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326" srsDimension="2">
<gml:lowerCorner>40 116</gml:lowerCorner>
<gml:upperCorner>40 116</gml:upperCorner>
</gml:Envelope>The srsName uses the long URN format (option 1), the output is an Envelope bounding box (option 32), and coordinates appear as latitude then longitude (option 16).