Returns the Geography Markup Language (GML) representation of a geometry or geography object.
Syntax
text ST_AsGML(geometry geom, integer maxdecimaldigits=15, integer options=0)
text ST_AsGML(geography geog, integer maxdecimaldigits=15, integer options=0)
text ST_AsGML(integer version, geometry geom, integer maxdecimaldigits=15, integer options=0, text nprefix=null, text id=null)
text ST_AsGML(integer version, geography geog, integer maxdecimaldigits=15, integer options=0, text nprefix=null, text id=null)Parameters
| Parameter | Description |
|---|---|
geom | The geometry object to convert. |
geog | The geography object to convert. |
version | The GML version. 2 (default) outputs GML 2.1.2. 3 outputs GML 3.1.1. |
maxdecimaldigits | The maximum number of decimal digits in coordinates. Default: 15. |
options | A bitmask that controls coordinate reference system (CRS) output and geometry representation. Default: 0. See the Options section for valid values. |
nprefix | The namespace prefix. Default: null. |
id | The GML element ID. Default: null. Valid only with GML version 3. |
Options
Combine multiple options 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 using spatial reference identifier (SRID) 4326. |
32 | Include the bounding box of the geometry object. |
To combine options, use the | operator or add their values. For example, 32 | 16 | 1 = 49 outputs the bounding box, reverses coordinate order, and uses the long CRS URN expression.
Usage notes
Supports circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.
Polyhedral surfaces and TIN surfaces require GML version 3.
Examples
The following example returns a GML envelope with the long CRS URN expression (1), the bounding box (32), and latitude-before-longitude coordinate order (16), using option value 32 | 16 | 1 = 49.
SELECT ST_AsGML(3, ST_GeomFromText('POINT(116 40)',4326), 5, 32|16|1);Output:
st_asgml
---------------------------------------------------------------
<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>
(1 row)Related topics
ST_GeomFromGML: Parse a GML string back into a geometry object.