The SE_AsKML() function
The SE_AsKML() function returns the Keyhole Markup Language (KML) representation of an ST_Geometry spatial type.
Typically, you use the SE_AsKML() function
to retrieve the KML representation of a spatial primitive from the
server and send it to a client, as in:
SELECT SE_AsKML(geomcol) FROM mytable
The return type of the SE_AsKML() function is defined as LVARCHAR. You can write user-defined routines (UDRs) in C or SPL to extend the functionality of the existing spatial data type functions.
Syntax
SE_AsKML(p ST_Geometry)
Return type
ST_Geometry
Example
In this example, the SE_AsKML() function
converts the location column of the table mytable into
its KML description.
CREATE TABLE mytable (id integer, location ST_Point);
INSERT INTO mytable VALUES(
1, ST_PointFromText('point (10.02 20.01)', 1000)
);
SELECT id, SE_AsKML(p1) FROM point_t ORDER BY id asc;
id 100_xy
<Point><coordinates>10.02,20.01</coordinates></Point>
CREATE TABLE line_t (id integer, p1 ST_LineString);
INSERT INTO line_t VALUES(
1,
ST_LineFromText('linestring (0.0 0.0,0.0 1.0,1.0 0.0,1.0 1.0)',1000)
);
1 row(s) inserted.
INSERT INTO line_t VALUES(
2,
ST_LineFromText('linestring z (0.0 0.0 0,0.0 1.0 1,1.0 0.0 1,1.0 1.0 1)',1000)
);
1 row(s) inserted.
INSERT INTO line_t VALUES(
3,
ST_LineFromText('linestring m (0.0 0.0 0,0.0 1.0 1,1.0 0.0 1,1.0 1.0 1)',1000)
);
1 row(s) inserted.
SELECT id, SE_AsKML(p1) FROM line_t ORDER BY id ASC;
id 1
<LineString><coordinates>0,0 0,1 1,0 1,1</coordinates></LineString>
id 2
<LineString>
<coordinates>0,0,0 0,1,1 1,0,1 1,1,1</coordinates>
</LineString>
id 3
<LineString><coordinates>0,0 0,1 1,0 1,1</coordinates></LineString>