The SE_EnvelopeFromKML() function
The SE_EnvelopeFromKML() function takes a KML LatLonBox or LatLonAltBox and an optional spatial reference ID and returns a polygon.
The LatLonBox and LatLonAltBox contain four coordinates: north, south, east, and west, that are used to form the traditional pair of SW, NE coordinates usually found with bounding boxes. LatLonAltBox also contains the elements minAltitude and maxAltitude, and while those will be accepted as valid tags in the KML fragment, they are not used to form a Z-polygon. Only 2-D polygons are returned.
Syntax
SE_EnvelopeFromKML(kml_string lvarchar)
SE_EnvelopeFromKML(kml_string lvarchar, SRID integer)
Return type
A four sided ST_Polygon representing the envelope.
Example
In this example, the KML LatLonBox
includes four coordinates:
EXECUTE FUNCTION SE_EnvelopeFromKML('<LatLonBox><north>34.54356</north>
<south>33.543634</south>
<east>-83.21454</east>
<west>-86.432536</west>',4);
Output:
4 POLYGON ((-86.3253600195 33.5436340112, -83.2145400212 33.543630112,
-83.2145400212 34.5435600828, -86.3253600195 34.5435600828,
-86.3253600195 33.5436340112))
In this
example, the KML LatLonAltBox includes the four coordinates as well
as the minAltitude, maxAltitude, and altitudeMode attributes:
EXECUTE FUNCTION SE_EnvelopeFromKML('<LatLonAltBox><north>45.0</north>
<south>42.0</south><east>-80.0</east><west>-82.0</west>
<minAltitude>0</minAltitude><maxAltitude>0</maxAltitude>
<altitudeMode>clampToGround</altitudeMode>',4);
However,
the output only includes the four coordinates:
4 POLYGON((-82.0 42.0, -80.0 42.0, -80.0 45.0, -82.0 45.0, -82.0 42.0))