Returns the Keyhole Markup Language (KML) element for a geometry or geography object.
Syntax
text ST_AsKML(geometry geom, integer maxdecimaldigits=15);
text ST_AsKML(geography geog, integer maxdecimaldigits=15);
text ST_AsKML(integer version, geometry geom, integer maxdecimaldigits=15, text nprefix=NULL);
text ST_AsKML(integer version, geography geog, integer maxdecimaldigits=15, text nprefix=NULL);Parameters
| Parameter | Description | Default |
|---|---|---|
geom | The geometry object to convert to KML. | — |
geog | The geography object to convert to KML. | — |
maxdecimaldigits | The maximum number of decimal places in the output coordinates. | 15 |
version | The KML version. 2 uses GML 2.1.2; 3 uses GML 3.1.1. | 2 |
nprefix | The namespace prefix. Pass a custom string to qualify KML element names. | NULL |
Usage notes
ST_AsKML supports 3D objects and preserves the z-coordinate of the input geometry.
Examples
Convert a 2D polygon
SELECT ST_AsKML(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))',4326));Output:
st_askml
---------------------------------------------------------------
<Polygon><outerBoundaryIs>
<LinearRing><coordinates>1,1 1,2 2,.2 2,1 1,1</coordinates>
</LinearRing></outerBoundaryIs>
</Polygon>
(1 row)Convert a 3D linestring
SELECT ST_AsKML(ST_GeomFromText('LINESTRING(1 2 3, 4 5 6)',4326));Use a namespace prefix
SELECT ST_AsKML(2, ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))',4326), 15, 'kml');What's next
ST_AsGML — export geometry as Geography Markup Language (GML), the format underlying KML
ST_AsGeoJSON — export geometry as GeoJSON, the standard format for web mapping APIs
该文章对您有帮助吗?