Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


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.