3

I am able to check if two geometries are intersecting through:

 if a.geometry().intersects(b.geometry()):

Is there any method available that tell me if how much one geometry is overlapping with other. Like 10% 50% 90% etc

PolyGeo
  • 65,136
  • 29
  • 109
  • 338

3 Answers3

1

From inspection of this question it looks like you can do something like:

if a.geometry().intersects(f.geometry()):
        intersection = a.geometry().intersection(f.geometry())
        print intersection.area()

When you intersect two polygons this can return either a polygon, a line or a point (depending on how the two polygons intersect), if you intersect a polygon and a line it will return either the line that is within the polygon or a point if the line just touches the polygon. So you need to add some logic that decides whether to calculate the area of the overlap or the length of the line depending on what sort of geometry intersection has returned.

Ian Turton
  • 81,417
  • 6
  • 84
  • 185
0

Calculate area for all the features using a loop:

for f in layer.getFeatures()

Getting the area can be done with :

f.geometry().area()

F being the feature
Then simply do a.area()/b.area()*100

julsbreakdown
  • 1,496
  • 10
  • 21
0

Divide the overlapped area by the whole area to get the percentage of overlapping:

intersection = a.geometry().intersection(b.geometry())  
totalArea = a.geometry().area() + b.geometry().area()  
percetnage = (intersection/totalArea)*100
Shiko
  • 2,883
  • 13
  • 22