This topic describes the ST_AsGML function. This function returns the Geography Markup Language (GML) element that represents a geometry object or a 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

Parameter Description
geom The geometry object whose GML representation you want to obtain.
maxdecimaldigits The maximum number of decimal places that you want to retain. Default value: 15.
options The type of coordinate reference system (CRS) information that you want to return in the GML element. Valid values:
  • 0: specifies to return the CRS of the GML element by using a short expression. An example expression is EPSG:4326.
  • 1: specifies to return the CRS of the GML element by using a long expression. An example expression is urn:ogc:def:crs:EPSG::4326.
  • 2: specifies to delete the srsDimension attribute of the GML element if GML version 3 is used.
  • 4: specifies to use <LineString> rather than <Curve> to mark line objects if GML version 3 is used.
  • 16: specifies that the latitude precedes the longitude in the GML element. For example, if the spatial reference identifier (SRID) is 4326, this value is valid.
  • 32: specifies to return the bounding box of the geometry object.
geog The geography object whose GML representation you want to obtain.
version The GML version that you want to use. The default value 2 specifies GML version 2.1.2. You can set this parameter to 3, which specifies GML version 3.1.1.
nprefix The prefix of the namespace. Default value: NULL. You can specify a custom prefix.
id The ID of the GML element. Default value: NULL. This parameter is valid only when GML version 3 is used.

Description

  • This function supports circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.
  • This function supports polyhedral surfaces and TIN surfaces only when GML version 3 or a later version is used.

Examples

Obtain a GML element that contains the CRS in a long expression, the bounding box, and the coordinates in which the latitude precedes the longitude.
SELECT ST_AsGML(3, ST_GeomFromText('POINT(116 40)',4326), 5, 32|16|1);
                           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)