1

I have two layers (Buildings and Census areas) which are overlapped. I want to join them with a spatial join but, in some cases, buildings overlap two or more census units and I don't know which census unit associating to. So I thought that I could associate the building to the census area that is overlapped for the largest part. For doing this, I first want to evaluate if the intersected area is higher than the half of the building area. I tried in two ways (see code below) but they return different results.

does someone know why the two codes return different results?

1st trial

featuresC= Census_layer.getFeatures()
featuresB=Building_layer.getFeatures()
count=0
for fbuild in featuresB: 
    BuildingGeometry=fbuild.geometry()
    if intersection.area()>0.5*BuildingGeometry.area():
        print intersection.area(), "featInters"
    else:
        print BuildingGeometry.area(), "featBuild"

2nd trial

featuresC= Census_layer.getFeatures()
featuresB=Building_layer.getFeatures()
count=0
for fbuild in featuresB: 
    BuildingGeometry=fbuild.geometry()
    if intersection.area()*2.0>BuildingGeometry.area():
        print intersection.area(), "featInters"
    else:
        print BuildingGeometry.area(), "featBuild"

and, for instance, the results are:

         **1st trial             2nd trial**

    717.0162316 featBuild   717.0162316 featBuild
    215.4575371 featBuild   215.4575371 featBuild
    78.8431039  featBuild   50.23154609 featInters

Your Answer

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

Browse other questions tagged or ask your own question.