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 (as opposed to a single polygon) in a geom
column. Thus, I am unable to extract it as a single polygon value from the multipolygon.
All helpful suggestions much appreciated
Import into a staging table and then use ST_DUMP to brake the multigeom into individual pieces and use that to populate the destination table.
UPDATE
You import all the data you need into a staging table (let's call it
multi
) and then useST_DUMP
to break the mutligeometry into single geometries: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.
Update: I think this could be accomplished much easier with this query.
You can use ST_GeometryN together with ST_NumGeometries and the generate_series function to obtain what you need.
Let's assume you have the table from Jakub's example:
This one contains a multipolygon, an id and another column.
To get each single polygon from the table including all other attributes try something like:
"id" and "test" are the values for each row in the original table. generate_series creates a series of numbers from 1 to the number of geometries in each row.
Therefore you will split each multi geometry in its separate single geometry parts and the values in the other columns remain the same.
Just replace the columns and table in the example with the columns from your exported shapefile and you will get the table with the single polygons.
Hope this answers your question.