16

I am working in QGIS on a vector layer where areas are classified using an attribute "typo". The problem I'm encountering is that many polygons are duplicated or overlapping, with the result that some areas are classified as two or more "typo". This is an error.

In order to make some statistical analysis I need to clean this layer removing the overlapping/duplicates so that every inch of territory is classified as one and only one "typo"; which one is indifferent. How can I perform it?

2 Answers 2

28

To remove duplicates:

  • You can use the Delete duplicate geometries tool by accessing it via the Processing Toolbox:

    Delete duplicate geometries

  • Another option is to use the v.clean tool from GRASS and select the rmdupl option:

    v.clean from GRASS

To remove overlaps:

  • You can use the Dissolve tool, provided there are common attributes between the original polygon and the overlapping polygon:

    Dissolve

  • As always, you can manually remove them if there are only a handful. You can do this via the Attribute Table, find your overlapping polygons (useful in conjunction with a topology checker to highlight the overlaps) and select the option to delete features.

1
  • 3
    Unfortunately there are not common attributes between overlapping polygons and the manual editing is not suitable in my case for the high number of features that need to be modified. Anyway your reply was very helpful because, for my actual needs, just the geometry is important, not the attribute. Dissolve all the features and subsequently select them by location does solve my problem. Thank you!
    – Roberto
    Feb 5, 2015 at 13:24
2

In QGIS 3 and if you want to use a script, here is a code that generates a new layer that contains features which shows the location of double geometries:

source_layer = iface.activeLayer()

duplicate_geo_id = []
duplicate_id = []
for i in source_layer.getFeatures():
    g = i.geometry()
    if (g.asWkt() not in duplicate_geo_id):
        duplicate_geo_id.append(g.asWkt())
        duplicate_id.append(i.id())
source_layer.select(duplicate_id)
source_layer.invertSelection()

new_layer = source_layer.materialize(QgsFeatureRequest().setFilterFids(source_layer.selectedFeatureIds()))
source_layer.removeSelection()
new_layer.setName('Double Geometry')
QgsProject.instance().addMapLayer(new_layer)

Before executing the script: enter image description here

After executing the script: enter image description here

1
  • 2
    Thank you for the script. I modified it, removing the selection inversion on line eleven to output a layer with the duplicates removed.
    – tacarn
    Feb 17 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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