Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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;
share|improve this answer
    
This is everything I need, thank you! –  Brad Koch Apr 22 '13 at 15:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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