Name

ST_AsKML — Returns the Keyhole Markup Language (KML) representation of a Geometry object.

Synopsis

varchar ST_AsKML(bytea Geometry);

varchar ST_AsKML(double version, bytea Geometry);

varchar ST_AsKML(double version, bytea Geometry, integer precision);

Alias

AsKML

Description

Returns the Keyhole Markup Language (KML) representation of a Geometry object.

The input geometries must have an SRID. The resulting KML geometry will have SRID 4326 assigned, if it necessary the function ST_Transform is used automatically to convert geometries to EPSG:4326.

JASPA only supports KML version 2.1. The optional parameter version must be a number between 2 and 3. Otherwise, it throws an error.

The parameter precision is unused in JASPA. It is only mantained for PostGIS compatibility.

Coordinate Dimensions
2D3DM
-
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

--3D POINT
SELECT ST_AsKML(ST_GeomFromText('POINT(-5.843868 43.360758 250)',4326));
--Result:
<kml:Point xmlns:kml="http://earth.google.com/kml/2.1">
  <kml:coordinates>-5.843868,43.360758</kml:coordinates>
</kml:Point>


--2D POLYGON
SELECT ST_AsKML(ST_GeomFromText('POLYGON((
-5.850379847879675 43.35970362178223, 
-5.848336797975651 43.36161117272741, 
-5.850411866073801 43.36311451294508, 
-5.853216861450062 43.36175621008758, 
-5.850379847879675 43.35970362178223
))',4326));
--Result:
<kml:Polygon xmlns:kml="http://earth.google.com/kml/2.1">
 <kml:outerBoundaryIs>
  <kml:LinearRing>
    <kml:coordinates>-5.850379847879675,43.35970362178223 -5.848336797975651,43.36161117272741 
                     -5.850411866073801,43.36311451294508 -5.853216861450062,43.36175621008758 
                     -5.850379847879675,43.35970362178223
    </kml:coordinates>
  </kml:LinearRing>
 </kml:outerBoundaryIs>
</kml:Polygon>

Related functions

ST_GeomFromKML