PostGIS MultiPolygon Conversion – How to Convert from MultiPolygon to Polygon in PostGIS

convertgeometrymulti-polygonpolygonpostgis

I have a table in PostGIS, where the data is currently stored as a MultiPolygon. Each Multipolygon has only a single Polygon in it.

How do I query and get the containing Polygon, and not MultiPolygon? I am ok ignoring the Edge case where there are Multiple Polygons in the Multi-Polygon Geometry. All I need is the first or only Polygon in that Geometry.

Best Answer

If you want to Ignore the edge cases, and get only the First (or only) Polygon, from the MultiPolygon geometry, then you need to use the ST_GeometryN() function.

A query like the following will give you the geometry as Polygons

SELECT ST_GeometryN(geom, 1)
FROM polygons;