5

I am working on a layer with many polygons (circles). I would like to create a polygon containing only the areas where 3 or more circles overlap (in my example there would be only 1 area in the east). Each circle has a specific "ID".

I don't know if QGIS allows such specific conditions.

Example

2

5 Answers 5

6

You can use QGIS expressions with either Geometry generator or Geometry by expression (see here for details and differences between these two options). Use this expression with Geometry generator (see below for Geometry by expression) and replace @layer with the name of your polygon layer:

with_variable (
    'poly',
    array_foreach (
        case
        when 
            array_length(
                overlay_intersects(
                    @layer, 
                    $geometry, limit:=-1
                )
            ) = 2
        then
            overlay_intersects(
                @layer, 
                $geometry, limit:=-1
            )
        end,
        intersection (
            $geometry,
            @element
        )
    ),
    intersection (
        array_get (@poly,0),
        array_get (@poly,1)
    )
)

If you use the expression with Geometry by expression, use this expression, where you have to replace poly in lines 8 and 14 with the name of your polygon layer:

with_variable (
    'poly',
    array_foreach (
        case
        when 
            array_length(
                overlay_intersects(
                    'poly', 
                    $geometry, limit:=-1
                )
            ) = 3
        then
            overlay_intersects(
                'poly', 
                $geometry, limit:=-1
            )
        end,
        intersection (
            $geometry,
            @element
        )
    ),
    intersection (
        array_get (@poly,1),
        array_get (@poly,2)
    )
)

Red hached area created with Geometry generator: enter image description here

2
  • Thank you Babel. Is there a way that I could select the wanted area? My goal would be to copy paste the area meeting the condition into another shapefile. I tried to use your expression in "select with an expression" but it didn't work there. For those with the same issue, don't forget to use QGIS 3.16.
    – Split24
    Commented Dec 9, 2021 at 13:35
  • See updated answer, the second expression
    – Babel
    Commented Dec 9, 2021 at 15:22
4

Let's assume there is a polygon layer called 'test' with six features in it, see image below.

input

Solution #1. Getting the feature with three and more overlaps

This solution was partially derived from @johns's comment

Step 1. Perform an intersection by means of the SAGA's "Polygon Self-Intersection" geoalgorithm

step_11

Step 2. Use the "Extract by expression" geoalgorithm with the following expression:

array_length(string_to_array("ID", delimiter:='|')) >= 3

step_21

and get the output

result1

Solution #2. Dissolving only features that contain a feature with three and more overlaps

Step 1. Create a field "test" with this expression:

array_sum(overlay_intersects(@layer, 1))

step_12

Step 2. Use the the GDAL's "Dissolve" (GDAL > Vector geoprocessing > Dissolve) from the Processing Toolbox (Ctrl+Alt+T) with field "test" from the Step 1, and do not forget to tick the Produce one feature for each geometry in any kind of geometry collection in the source file.

step_22

Press Run and get the output

result2


References:

2
  • 2
    Hello Taras, I see that my question wasn't clear enough. I want to only have the area where 3 or more polygon are overlapping. As shown in the example of Babel. I'll be more specific next time.
    – Split24
    Commented Dec 9, 2021 at 13:39
  • 1
    Okay! I think I got you now @_@
    – Taras
    Commented Dec 9, 2021 at 13:45
2

So, if I understand your question correctly, follow me.

My initial data is a layer called "buf" type - multipolygons;

  1. Polygons in simple polygons - Vector->Processing geometry->Split composite objects with saving layer "buf_parts", see figure 1; enter image description here

Figure 1

  1. Next, polygons into lines, see Figure 2;

enter image description here

Figure 2

  1. Then analysis tools->Vector-Overlay->Cut with lines, see figure 3;

enter image description here

Figure 3

Result

enter image description here

Figure 4

  1. Then create centroids for each of the split parts and save the result, named as "center_parts", see the result shown in figure 4;

enter image description here

Figure 4

  1. Next, Layer->Create Layer->New Virtual Layer, import the results of steps 1 and 4 and run the SQL script, see figure 5 (it will help you count the number of points that fall into the composite circles);

enter image description here

Figure 5

SELECT count(*) cnt, b.geometry from "center_parts" a JOIN "buf_parts" b ON st_intersects(a.geometry, b.geometry) group by b.geometry 
  1. Next, run the following SQL-script on the "virtual_layer", with saving the result in the layer "buf_sel" , see figure 6 (in this case, we work with copies of points, based on the number of intersections);

enter image description here

Figure 6

SELECT cnt, geometry from "buf_sel" WHERE cnt>='8' 
  1. Next, on the layer "buf_sel" run the SQL-script, which combines the circles in common polygons and this is your final result, be sure to save it and then act yourself :-).

enter image description here

Figure 7

SELECT cnt, st_union(geometry) geom FROM "buf_sel"

Result

enter image description here

Figure 8

Original spatial solutions...

2
  • I though you gonna add your famous translator: Translated with www.DeepL.com/Translator (free version) @_@
    – Taras
    Commented Dec 15, 2021 at 12:56
  • @Taras, Sometimes, when I post my question-answer, the link is added automatically, sometimes not :-)...+1 to whom this answer became clear :-), the main thing is to understand the idea... Commented Dec 15, 2021 at 12:58
2
  1. Convert the polygons to lines with Polygon to lines.

  2. Split the polygons with the lines from 1: Split with lines.

  3. Create a Buffer with a very small, negative distance from the output of step 2.

  4. Check within how many of the initial polygons the output geometries of step 3 are: create a new field called within using Field calculator with this expression (replace poly with the name of the initial polygon layer): array_length (overlay_within ('poly', $id)).

  5. Go back to the layer created in step 2. Use Select by expression with the following expression: array_first (overlay_contains ('Buffered', "within")) >=3 (adapt the number for how many overlapping polygons you want to have).

Now the parts that have 3 or more overlaps are selected - you can copy and paste them to a new layer. Don't forget that you have duplicate geometries: use Delete duplicate geometries.

Area where 3 or more polygons overlap (hatched in pink):

enter image description here

2

Using the Union Geoprocessing tool is probably the fastest way:

  1. Run Menu Vector / Geoprocessing Tools / Union

  2. On the output of step 1, use Select by expression with this expression to select those parts where 3 or more polygon overlap: array_length (overlay_equals(@layer, $id))+1 >=3

Blue circles = output of Union. The labels are created by the expression above (minus the >=3 part) and shows how many polygons overlap in each part. Highlighted in yellow: polygons selected as described in step 2: 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.