PostGIS – convert multipolygon to single polygon

I used ST_DUMP to convert a table of multipolygon geometries in PostgreSQL to a new table with polygon geometries and other columns of data.

CREATE TABLE poly AS                       --poly will be the new polygon table
WITH dump AS (
    SELECT id, test,                       --columns from your multipolygon table 
      (ST_DUMP(geometry)).geom AS geometry 
    FROM multi                             --the name of your multipolygon table
) 
SELECT id, test, 
  geometry::geometry(Polygon,4326)         --type cast using SRID from multipolygon
FROM dump;

Update: I think this could be accomplished much easier with this query.

CREATE TABLE polygon_table AS 
    SELECT id, example_column, (ST_DUMP(geom)).geom::geometry(Polygon,4326) AS geom FROM multipolygon_table

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)