All Products
Search
Document Center

PolarDB:ST_AsGML

Last Updated:Mar 28, 2026

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

ParameterDescription
geomThe geometry object to convert.
geogThe geography object to convert.
versionThe GML version. 2 (default) outputs GML 2.1.2. 3 outputs GML 3.1.1.
maxdecimaldigitsThe maximum number of decimal digits in coordinates. Default: 15.
optionsA bitmask that controls coordinate reference system (CRS) output and geometry representation. Default: 0. See the Options section for valid values.
nprefixThe namespace prefix. Default: null.
idThe GML element ID. Default: null. Valid only with GML version 3.

Options

Combine multiple options using the bitwise OR operator (|).

ValueEffect
0Include CRS using a short expression, for example EPSG:4326.
1Include CRS using a long URN expression, for example urn:ogc:def:crs:EPSG::4326.
2Remove the srsDimension attribute (GML version 3 only).
4Use <LineString> instead of <Curve> for line objects (GML version 3 only).
16Output latitude before longitude. Valid when using spatial reference identifier (SRID) 4326.
32Include 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