4

I have a large (30m+ records) spatial data set I have imported into a PostGIS database. I did not expect to find multipolygons in the data set, but it does have a few of them. I'd like to take a closer look at them to better understand the data I'm dealing with. However, shp2pgsql indiscriminately imported everything as a multipolygon.

How can I efficiently query the dataset to filter out the multipolygons that are actually simple polygons?

4

Just check and see if the number of elements is larger than one.

SELECT Count(*) FROM mytable WHERE ST_NumGeometries(geom) > 1;

If the answer is zero, create a new simple table:

CREATE TABLE mynewtable AS 
SELECT ST_GeometryN(geom, 1)::geometry(Polygon) AS geom, attr1, attr2
FORM mytable;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.