I wrote the following python script to find intersections between two layers, and although the two layers have intersections, it returned an empty list.

intersections = []
for a in layer1.getFeatures():
    for b in layer2.getFeatures():
        if a.geometry.intersects(b.geometry()):
            intersection = a.geometry().intersection(b.geometry())

The same script returns intersections if I simply try it with different shapefiles.


If two layers have different projections, QGIS won't be able to find intersections between them. If you aren't sure how to change a shapefile's projection, check out this answer. After changing the projections of the two layers I was able to get intersections without any issue.

If any QGIS devs see this, they should consider throwing an exception if someone tries to find intersections between two layers with different projections.

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.