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.

Hello I have the following problem:

I created a grid in QGIS. For some unknown reason QGIS doesn't tesselate the plane correctly. Sometimes there are polygons with different "id" that represents the same portion of the area. I loaded the Shapefile into postgis (without noticing this) and began to have troubles in queries. When I look for the problem I saw that sometimes 2 or even 4 polygons represent exactly the same region. How could I delete those repeating polygons?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

For my_table where gid is the primary key and geom is the geometry column, try:

DELETE FROM my_table
WHERE gid NOT IN (
    select max(dup.gid)
    from my_table as dup
    group by geom);

Note: make a backup of this table beforehand, in case things go wrong.

share|improve this answer
    
I not sure if this really works in all situations. I think that group by, = , ... on geometries operates with the bounding box and not with the real geometry, lists.osgeo.org/pipermail/postgis-users/2008-June/020169.html –  Francisco Puga Aug 16 '13 at 15:34
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.