All Products
Search
Document Center

ApsaraDB RDS:ST_AsGML

Last Updated:Mar 28, 2026

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

ParameterDescription
geomThe geometry object to convert to GML.
geogThe geography object to convert to GML.
versionThe GML version to use. Default: 2 (GML 2.1.2). Set to 3 for GML 3.1.1.
maxdecimaldigitsThe maximum number of decimal places to keep in coordinates. Default: 15.
optionsA bitmask controlling coordinate reference system (CRS) output and geometry representation. See Options below.
nprefixThe namespace prefix. Default: NULL.
idThe ID of the GML element. Default: NULL. Valid only when using GML version 3.

Options

Combine multiple flags 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 the spatial reference identifier (SRID) is 4326.
32Return 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).