I am trying to assign attributes from features in one layer that intersect features in another layer. When I run my code, I do not get an errors but it does not update the attribute field as I am expecting. I wrote my code based on the example in this post https://stackoverflow.com/questions/23506358/pyqgis-for-spatial-join. It appears as though the program does not see that any features intersect, but when i compare them on the map canvas, they do. I'm not sure what's wrong. Here is my code:


idxGPS = GPSDegLyr.fieldNameIndex('UniqueID')
idxBuff = dsslvExplodeLyrWGS84.fieldNameIndex('UniqueID')


for b in dsslvExplodeLyrWGS84.getFeatures():
    for g in GPSDegLyr.getFeatures():
        if g.geometry().intersects(b.geometry()) == True:
            val = b.attributes()[idxBuff]
            print val



UPDATE: I solved the intersecting problem - now the programs sees the intersections and prints the values. But still doesn't write the values out to the attrribute table.

1 Answer 1


It was the indentation of the commitChanges line - it should have been dedented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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