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 given geometry is null, then null is returned.
This function can also be called as a method.
Syntax
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.
- 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 representation.
Return type
CLOB(2G)
Example
In the following example, the lines of results have been reformatted for 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.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE SAMPLE_POINTS (id integer, geometry ST_POINT, gml CLOB(32K))
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 representations of the geometry.
SELECT id, cast(ST_AsGML(geometry) AS varchar(110)) AS gml_fragment
FROM sample_points
WHERE id = 1100
Results:
SELECT id,
cast(ST_AsGML(geometry) AS varchar(110)) AS gml,
cast(ST_AsGML(geometry,2) AS varchar(110)) AS gml2,
cast(ST_AsGML(geometry,3) AS varchar(110)) 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>