For a QGIS 2.0/2.2 and Python 2.7 plugin, I am trying to update one layer's field attribute with another layer's field attribute based on geometry function QgsGeometry.intersects(). My first layer is a point layer, the second layer is a buffer of a vector polyline layer containing azimuth measurements. I would like to update the point layer to include azimuth information of the buffer polygon it intersects (essentially a spatial join). It is to automatize the process described here. Currently, only the first feature in my points layer's bearing field is updated after committing changes (i expected all features to be updated).
rotateBUFF = my buffer polygon layer
pointLayer = my point layer to obtain azimuth data
rotate_IDX = rotateBUFF.fieldNameIndex('bearing')
point_IDX = pointLayer.fieldNameIndex('bearing')
rotate_pr = rotateBUFF.dataProvider()
point_pr = pointLayer.dataProvider()
rotate_caps = rotate_pr.capabilities()
point_caps = point_pr.capabilities()
pointFeatures = pointLayer.getFeatures()
rotateFeatures = rotateBUFF.getFeatures()
for rotatefeat in rotateFeatures:
for pointfeat in pointFeatures:
if pointfeat.geometry().intersects(rotatefeat.geometry()) == True:
pointID = pointfeat.id()
if point_caps & QgsVectorDataProvider.ChangeAttributeValues:
bearing = rotatefeat.attributes()[rotate_IDX]
attrs = {point_IDX : bearing}
point_pr.changeAttributesValues({pointID : attrs})