Name

ST_AsKML — Return the geometry as a KML element. Several variants. Default version=2, default precision=15

Synopsis

text ST_AsKML(geometry g1);

text ST_AsKML(geometry g1, integer precision);

text ST_AsKML(integer version, geometry geom1);

text ST_AsKML(integer version, geometry geom1, integer precision);

Description

Return the geometry as a Keyhole Markup Language (KML) element. There are several variants of this function. maximum number of decimal places used in output (defaults to 15) and version default to 2.

Version 1: ST_AsKML(geom) / version=2 precision=15

Version 2: ST_AsKML(geom, max_sig_digits) / version=2

Version 3: ST_AsKML(version, geom) / precision=15

Version 4: ST_AsKML(version, geom, precision)

[Note]

Requires PostGIS be compiled with Proj support. Use PostGIS_Full_Version to confirm you have proj support compiled in.

[Note]

Availability: 1.2.2 - later variants that include version param came in 1.3.2

[Note]

AsKML output will not work with geometries that do not have an SRID

This function supports 3d and will not drop the z-index.

Examples

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

		st_askml
		--------
		<Polygon><outerBoundaryIs><LinearRing><coordinates>0,0 0,1 1,1 1,0 0,0</coordinates></LinearRing></outerBoundaryIs></Polygon>

		--3d linestring
		SELECT ST_AsKML('SRID=4326;LINESTRING(1 2 3, 4 5 6)');
		<LineString><coordinates>1,2,3 4,5,6</coordinates></LineString>
		
		

See Also

ST_AsSVG, ST_AsGML