1

I've clicked on the Join attributes by location button and can join two layers. But in the merged layer, how do I find out percentage of overlap/intersect calculated for each feature?

enter image description here

For example, in the result, I'd like to know the "overlaps" score for each feature in the merged layer.

Taras
  • 32,823
  • 4
  • 66
  • 137
Username
  • 297
  • 2
  • 11

1 Answers1

3

This can be done with the field calculator.
Using the excellent guide here and some changes I got the percent of intersecting area,
which will be equivalent to the overlapping area.
I did the calculation for the orange polygon a layer.

enter image description here

The expression I used was:

array_first(
    aggregate(
     layer:= 'polygon b',
     aggregate:='array_agg',
     expression:=area(intersection($geometry, geometry(@parent)))/area(geometry(@parent)),
     filter:=intersects($geometry, geometry(@parent))
     )
 )

What it does is collect all the intersecting geometries from the other layer, and then divides the intersecting area from the area of polygon a (the @parent layer).
I had to wrap it all up in array_first since the output of aggregate is an array, in this case of length 1, so first is just as good as last.

These are the results of the calculation.
shown with a label of

'percent overlap: '+  to_string(  round( "precent_overlap"*100,2) )+'%'

enter image description here

Dror Bogin
  • 3,475
  • 10
  • 24