The ST_MPolyFromKML() function

The ST_MPolyFromKML() function takes a MultiGeometry and Polygon combination and an optional spatial reference ID and returns a polygon object.

Syntax

ST_MPolyFromKML(kmlstring lvarchar)
ST_MPolyFromKML(kmlstring lvarchar, SRID integer)

Return type

ST_MultiPolygon

Example

The test_multipoly table is created with the INTEGER column id and the ST_MultiPolygon column geom:
CREATE TABLE test_multipoly (id INTEGER, geom ST_MultiPolygon);

INSERT INTO test_multipoly VALUES(1,ST_MPolyFromKML('<MultiGeometry>
              <Polygon><outerBoundaryIs><LinearRing><coordinates>
              -94.36,32.49 -92.65,32.68 -92.15,32.46 -93.09,33.08 
              -93.37,33.18 -94.36,32.49</coordinates>
             </LinearRing></outerBoundaryIs></Polygon><Polygon>
             <outerBoundaryIs><LinearRing><coordinates>-84.36,32.49 
             -82.65,32.68 -82.15,32.46 -83.09,33.08 -83.37,33.18 
             -84.3600000805,32.4900000536</coordinates>
             </LinearRing></outerBoundaryIs></Polygon><
             /MultiGeometry>',4));

This record specifies a spatial reference ID of 4 (WGS84) and both member polygons have two dimensions and six sides.

Output:
SELECT * FROM test_multipoly;

id    1
geom  4 MULTIPOLYGON (((-94.3600000805 32.4900000536, -92.6599999799 
        32.6899999866, -92.1500000335 32.4600000469, -93.0900000201 
        33.0800000738, -93.3700000268 33.1899999866, -94.3600000805 
        32.4900000536)),((-84.3600000805 32.4900000536, -82.6599999799 
        32.6899999866, -82.1500000335 32.4600000469, -83.0900000201 
        33.0800000738, -83.3700000268 33.1899999866, -84.3600000805 
        32.4900000536)))