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

  • How about the difference method? – Ian Turton Sep 28 '16 at 12:59
  • where it is? is this built in i didnt find in geometry – Muhammad Faizan Khan Sep 28 '16 at 13:01
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

  • Thanks juls, i am checking it. is there not any build in function available – Muhammad Faizan Khan Sep 28 '16 at 10:16
  • 2
    This won't give the geographical overlap area just the percentage of one regions area compared to another. – T_Bacon Sep 28 '16 at 10:18
  • Thank for the logic. can u help me here gis.stackexchange.com/questions/212223/… – Muhammad Faizan Khan Sep 28 '16 at 10:43
  • it is perfectly valid but i got another problem i have one layer of polygon while other is line. now how can i compare? one consist of area while other consist of length – Muhammad Faizan Khan Sep 28 '16 at 11:41
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.

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
  • is there any way available to check that how much line contains inside polygon. actually I want to check that – Muhammad Faizan Khan Sep 28 '16 at 13:55
  • what do you mean by line ? is it another layer ? – Shiko Sep 28 '16 at 13:57
  • A polygon layer geomoery contains a line which is another layer. i want to check that how much that line contains in polygon. – Muhammad Faizan Khan Sep 28 '16 at 14:03
  • You can use Spatial query in QGIS to query lines intersecting with polygon and you will get all lines – Shiko Sep 28 '16 at 14:07
  • actually i have to update attribute table column value on this comparison basis – Muhammad Faizan Khan Sep 28 '16 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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