ST_AsKML

更新时间:
复制 MD 格式

Returns the Keyhole Markup Language (KML) representation of 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

ParameterTypeDefaultDescription
geomgeometryThe geometry object to convert to KML.
geoggeographyThe geography object to convert to KML.
maxdecimaldigitsinteger15The maximum number of decimal places in the output coordinates.
versioninteger2The KML version. 2 uses GML version 2.1.2; 3 uses GML version 3.1.1.
nprefixtextNULLThe namespace prefix. Pass a custom string to add a prefix to KML elements.

Usage notes

  • Supports 3D objects and preserves the z-index of each point.

Examples

2D polygon

SELECT ST_AsKML(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))', 4326));

Output:

<Polygon><outerBoundaryIs>
    <LinearRing><coordinates>1,1 1,2 2,2 2,1 1,1</coordinates>
 </LinearRing></outerBoundaryIs>
</Polygon>

See also