ST_AsKML function
The ST_AsKML function converts a geometry object into Keyhole Markup Language (KML) notation.
Syntax
Parameter
- geometry
- A value of type ST_Geometry for which the KML representation is to be returned.
- precision
- A value of type INTEGER that specifies the number of digits to include after the decimal for the coordinates. The default is 16.
- annotation
- A value of type VARCHAR(255) that specifies annotation text. Note: KML supports the following notation:
<altitudeMode> <extrude> <tessellate> - header
- A value of type INTEGER that indicates whether the XML header is to be included in the results:
0indicates that header information is to be skipped, and1indicates that header information is to be included.
Return type
Returns a CLOB that provides the KML notation for the specified geography.
Examples
The examples operate on table kmltab, which is modified as follows:
INSERT INTO kmltab VALUES
(7001, db2gse.ST_Geometry('point(1 2)', 1003) ),
(7002, db2gse.ST_Geometry('linestring(33 2, 34 3, 35 6)', 1003) ),
(7003, db2gse.ST_Geometry('polygon((3 3, 4 6, 5 3, 3 3))', 1003))
;
INSERT INTO kmltab VALUES
(7004, db2gse.ST_Geometry('<gml:Point srsName=";EPSG:4269";><gml:coord>
<gml:X>50</gml:X><gml:Y>60</gml:Y></gml:coord> </gml:Point>', 1003))
;
INSERT INTO kmltab VALUES
(7005, db2gse.st_geometry('multilinestring ( (33 2, 34 3, 35 6), (28 4, 29 5,
31 8, 43 12), (39 3, 37 4, 36 7) )', 1003) ) ;- Convert to KML format with a precision of
3:
SELECT id, SUBSTR(db2gse.st_asKML(geo,3),1,350) FROM kmltab ID 2 --------- ------------------------------------------------------------------------------------------------------------- 7001 <Point><coordinates>1.000,2.000</coordinates></Point> 7002 <LineString><coordinates>33.000,2.000 34.000,3.000 35.000,6.000</coordinates></LineString> 7003 <Polygon><outerBoundaryIs><LinearRing><coordinates>3.000,3.000 4.000,6.000 5.000,3.000 3.000,3.000</coordinates></LinearRing></outerBoundaryIs></Polygon> 7004 <Point><coordinates>50.000,60.000</coordinates></Point> 7005 <MultiGeometry><LineString><coordinates>33.000,2.000 34.000,3.000 35.000,6.000</coordinates></LineString> <LineString><coordinates>28.000,4.000 29.000,5.000 31.000,8.000 43.000,12.000</coordinates></LineString> <LineString><coordinates>39.000,3.000 37.000,4.000 36.000,7.000</coordinates></LineString></MultiGeometry> 5 record(s) selected. - Convert to KML format with a precision of 4 and include a
header:
SELECT id, SUBSTR(db2gse.st_asKML(geo,1, null,3),1,350) FROM kmltab WHERE id = 7001 OR id = 7003 ID 2 --------- ------------------------------------------------------------------------------------------------------------- 7001 <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"><Point><coordinates> 1.000,2.000 </coordinates></Point><Point><coordinates>1.000,2.000</coordinates></Point></kml> 7003 <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"><Polygon><outerBoundaryIs> <LinearRing><coordinates>3.000,3.000 4.000,6.000 5.000,3.000 3.000,3.000</coordinates></LinearRing> </outerBoundaryIs></Polygon></Polygon></kml> 2 record(s) selected.
