5

I have a QGIS project with circle polygons of different sizes, and some of them overlap . Where the circle polygons overlap, I want to retain the largest of the circles and delete the smaller circle.

Is there any way to do this?

I can only see methods for deleting the portion of the polygons that overlaps.

picture showing a portion of my map with circles on

3 Answers 3

3

Cluster all contiguos polygons together to larger polygons, then identify for each of these clusters which is the largest of the initial polygons it contains. To do so, follow these steps:

  1. To cluster contiguous polygons together, create a dissolved buffer (Menu Vector > Geoprocessing Tools > Buffer) around your polygons with a very small buffer size: the resulting buffer should be only slightly larger than the input. This is to make sure that each of the initial polygons is completely inside the resulting buffer (cluster). Be sure to check the Dissolve result checkbox.

  2. Convert the result using Menu Geometry > Geometry Tools > Multpart to Single parts. You get a series of "clusters" that contain all contiguous polygons (outlined in red in the screenshot).

  3. On the initial polygon layer, create a new attribute called cluster field that checks within which cluster each feature is. Use field calculator with this expression: overlay_within('Single parts', $id)[0] - replace Single parts with the name of the layer created in step 2.

  4. Select the polygon with the largest area inside each cluster. Use Select by expression with this expression: area ($geometry) = array_max (array_agg (area($geometry), group_by:=cluster)).

For each cluster (outlined in red), the largest polygon is selected (highlighted in yellow): enter image description here

1
  • Thanks for the suggestion!
    – user210471
    Aug 18, 2022 at 13:28
2

Another option:

  1. Dissolve to create blobs/groups of nearby polygon with "Keep disjoint features separate" checked
  2. Give each group a id (integer field type) using @row_number
  3. Join this group attribute to the original polygons
  4. Order the output by the expression $area with "Sort ascending"=No
  5. Delete duplicates by expression group. The first polygon of each group will be kept, which is the one with the largest area

enter image description here

1
  • 1
    Thanks for your help :)
    – user210471
    Aug 19, 2022 at 7:41
1

You can achieve this using a virtual layer.

Go to the menu Layer > Add Layer > Add/Edit Virtual Layer... and enter the following query.

It selects all polygons from mylayer provided that there is no other polygon from the same layer that intersects it and has a greater area.

select * 
from mylayer as a
where NOT EXISTS (
  select 1 
  from mylayer as a2 
  where st_intersects(a.geometry, a2.geometry)
    AND st_area(a.geometry) < st_area(a2.geometry)
 )

enter image description here

3
  • Thanks for the help, this worked well when I tested on a small selection of my polygons, however when I try to run for my whole layer it caused QGIS to stop responding completely, I guess my layer probably has more features than QGIS can cope with.
    – user210471
    Aug 17, 2022 at 14:27
  • 1
    @user210471 It can help if there is a spatial index, and maybe to pre-compute the area and store it in a field
    – JGH
    Aug 17, 2022 at 14:55
  • This method worked well for me, just had to be patient, thanks!
    – user210471
    Aug 18, 2022 at 13:28

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.