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
| Parameter | Description |
|---|---|
geom | The geometry object to convert. |
geog | The geography object to convert. |
version | The GML version. Default value: 2 (GML 2.1.2). Set to 3 for GML 3.1.1. |
maxdecimaldigits | The maximum number of decimal places in coordinate values. Default value: 15. |
options | A bitmask that controls the coordinate reference system (CRS) format and output structure. Valid values: 0, 1, 2, 4, 16, 32. See Options for details. |
nprefix | The namespace prefix. Default value: NULL. |
id | The GML element ID. Default value: NULL. Valid only when GML version 3 is used. |
Options
Combine multiple options using the bitwise OR operator (|).
| Value | Description |
|---|---|
0 | Returns the CRS in short format, for example, EPSG:4326. |
1 | Returns the CRS in long format, for example, urn:ogc:def:crs:EPSG::4326. |
2 | Removes the srsDimension attribute. Applies to GML version 3 only. |
4 | Uses <LineString> instead of <Curve> for line geometries. Applies to GML version 3 only. |
16 | Outputs coordinates in latitude-first order. Use when the SRID (spatial reference identifier) is 4326. |
32 | Includes 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.
该文章对您有帮助吗?