ST_AsGML function

The ST_AsGML function takes a geometry as an input parameter and returns its representation using the geography markup language.

If the specified geometry is null, then null is returned.

Syntax

Read syntax diagramSkip visual syntax diagramST_AsGML(geometry, gmlLevelinteger )

Parameter

gmlLevel
An optional parameter specifying the GML specification level to be used for formatting the GML data to be returned. Valid values are:
2
Use GML specification level 2 with the <gml:coordinates> tag. This is the default.
3
Use GML specification level 3 with the <gml:poslist> tag.
geometry
A value of type ST_Geometry or one of its subtypes to be converted to the corresponding GML format.

Return type

CLOB(2G)

Example

In the following examples, some lines of results have been reformatted to improve readability. The spacing in your results will vary according to your online display.

The following code fragment illustrates how to use the ST_AsGML function to view the GML fragment. This example populates the GML column, from the geometry column, with an ID of 2222.
CREATE TABLE SAMPLE_POINTS (id integer, geometry ST_POINT, gml varchar(1024))

INSERT INTO SAMPLE_POINTS (id, geometry)
VALUES
    (1100, ST_Point(10, 20, 1))

INSERT INTO sample_points(id, gml)
VALUES (2222,
  (SELECT  ST_AsGML(geometry)
   FROM    sample_points
   WHERE   id = 1100))
The following SELECT statement lists the ID and the GML formats of the geometry.
SELECT id, cast(ST_AsGML(geometry) AS varchar(120)) AS gml_fragment
FROM   sample_points
WHERE  id = 1100
Results:
ID          GML_FRAGMENT                                                                                                                                            
----------- ----------------------------------------------------------------------------- 
       1100 <gml:Point srsName="EPSG:4269"><gml:coord><gml:X>10.000000</gml:X>
            <gml:Y>20.000000</gml:Y></gml:coord></gml:Point>   
The following SELECT statement returns the geometries in different GML formats.
SELECT id,
       cast(ST_AsGML(geometry) AS varchar(120)) AS gml,
       cast(ST_AsGML(geometry,2) AS varchar(120)) AS gml2,
       cast(ST_AsGML(geometry,3) AS varchar(120)) AS gml3
FROM   sample_points
WHERE  id = 1100
The SELECT statement returns the following result set:
ID          GML                                GML2                              GML3
----------- --------------------------------   --------------------------------  --------------------------------
       1100 <gml:Point srsName="EPSG:4269">    <gml:Point srsName="EPSG:4269">   <gml:Point srsName="EPSG:4269 
                                                                                 srsDimension="2">
            <gml:coord>                        <gml:coordinates>                 <gml:pos>
            <gml:X>10</gml:X><gml:Y>20</gml:Y> 10,20                             10,20
            </gml:coord></gml:Point>           </gml:coordinates></gml:Point>    </gml:pos></gml:Point>