Let's say I have two polygons for Protected Areas in my country, one for a National Park and one for a National Forest and they have an overlapping part.

I want a tool that removes this overlap from the geometry of the National Forest because my first priority would be National Parks. I also have a priority field which I could use to get what I want.

  • No reason you couldn't code that, but what's your question?
    – Vince
    Jul 13, 2023 at 13:06
  • 2
    You could add your layer twice to a project, in one case using a definition query to limit the polygons to National Parks and in the other a query limiting it to National Forests. Or export it to two new layers, one of parks and one of forests. Then use the difference tool to get rid of National Forests that overlap the Parks. Merge that result to your National Parks defined layer. Recalculate any area fields.
    – John
    Jul 13, 2023 at 19:19
  • How many prio values do you have?
    – BERA
    Jul 21, 2023 at 9:42

1 Answer 1


You can use Union, Delete duplicates by attribute together with Sort, to delete duplicate geometries except the first.

I have a field named prio with values from 1-5. Where polygons overlap I want to keep the lowest prio polygon, for example 1 should be kept over 2.

  1. Field calculate an id field: @row_number to get a unique identifier for each polygon

  2. Union your polygon layer with itself as Input layer, no overlay layer. This will create duplicate geometries where polygons overlap

  3. Field Calculate a text field named wkt with the formula geom_to_wkt( $geometry ) Duplicate polygons from the Union will get the same wkt string.

  4. Order by expression with the expression concat("wkt","prio") so for each duplicate geometry, the lowest prio comes first (1,2,3,4,5)

  5. Delete duplicates by attribute wkt:

Deletes duplicate rows by only considering the specified field / fields. The first matching row will be retained, and duplicates will be discarded.

So for duplicate geometries, the first (lowest prio number) polygon will be kept.

  1. Dissolve by the id field created in step 1 to restore some of the split geometries created in the Union.

enter image description here

Your Answer

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

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