17

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?

Taras
35.8k5 gold badges77 silver badges151 bronze badges
asked Feb 5, 2015 at 10:51

2 Answers 2

30

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.

answered Feb 5, 2015 at 12:05
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! Commented 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

answered Jun 7, 2021 at 6:59
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. Commented Feb 17, 2023 at 20:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.