PostGIS - convert multipolygon to single polygon

前端 未结 3 1331
孤街浪徒
孤街浪徒 2021-02-04 01:44

Is it possible to import a shape file containing multipolygons into single polygon in PostGIS? Whenever I try importing a shape file of a polygon, it is stored as a multipolygon

3条回答
  •  别跟我提以往
    2021-02-04 02:09

    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
    

提交回复
热议问题