ST_AsGML

更新时间:
复制 MD 格式

Returns the Geography Markup Language (GML) representation of a geometry or geography object as a text string.

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.
geogThe geography object to convert.
versionThe GML version. Default value: 2 (GML 2.1.2). Set to 3 for GML 3.1.1.
maxdecimaldigitsThe maximum number of decimal places in coordinate values. Default value: 15.
optionsA bitmask that controls the coordinate reference system (CRS) format and output structure. Valid values: 0, 1, 2, 4, 16, 32. See Options for details.
nprefixThe namespace prefix. Default value: NULL.
idThe GML element ID. Default value: NULL. Valid only when GML version 3 is used.

Options

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

ValueDescription
0Returns the CRS in short format, for example, EPSG:4326.
1Returns the CRS in long format, for example, urn:ogc:def:crs:EPSG::4326.
2Removes the srsDimension attribute. Applies to GML version 3 only.
4Uses <LineString> instead of <Curve> for line geometries. Applies to GML version 3 only.
16Outputs coordinates in latitude-first order. Use when the SRID (spatial reference identifier) is 4326.
32Includes the bounding box of the geometry object in the output.

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 or later.

Examples

Return a GML element with CRS in long format, a bounding box, and coordinates in latitude-first order:

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)

The query passes 32|16|1 as options: 32 adds the bounding box, 16 places latitude before longitude, and 1 uses the long CRS format.