I make two polylines features(in my example both consists of two points) with the add feature tool. Then I (with code) add some attribute values on the first feature, then changes the geometry of the second feature before I add values to the second values.
When I use layer.featureAtId() to get the second feature and then reads it, I get the values from the first feature.
I don't get this problem if I don't change the geometry or if I commit the two new polylines before doing the mentioned operations.
In the attribute table it is correct. If I use
layer.nextFeature(feat) to iterate through all the features I get the right value.
# creates two features with the add feature tool layer = qgis.utils.iface.activeLayer() #select the first feature with the select tool featId1 = layer.selectedFeaturesIds() # add values to the first feature for i in range(5): layer.changeAttributeValue(featId1, i, (i*10)) #select the second feature with the select tool featId2 = layer.selectedFeaturesIds() # changes the geometry of the second feature newGeom = QgsGeometry.fromPolyline([QgsPoint(1,1), QgsPoint(2,2)]) layer.changeGeometry(featId2, newGeom) qgis.utils.iface.mapCanvas().refresh () # add values to the second feature for i in range(5): layer.changeAttributeValue(featId2, i, (i*10 + 1000)) # get the second feature by using featureAtId... feat = QgsFeature() layer.featureAtId(featId2, feat, True, True) # print values from the second feature for i in range(5): print feat[i].toString() # for some reason the attributeValues to the first feature get printed out. # in the attribute table it looks correct. # feat.geometry().asPolyline() seems to return the right geometry # if I save edits after creating the two new features it works as it should
I used QGIS version 1.8.0-Lisboa and QGIS version 1.9.0-Master