Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

By using the following code, I want to change the id of the line when saving the line. But the setFeatureId command, gives a false when doing the commitChanges(). Any idea how to change the id?

vl = QgsVectorLayer("MultiLineString", layerName, "memory")
pr = vl.dataProvider()
fet = QgsFeature()
fet.setGeometry( QgsGeometry.fromMultiPolyline( [[ QgsPoint(x3,y3),QgsPoint(x4,y4) ]] ))
pr.addFeatures( [ fet ] )
share|improve this question
I'm not sure you should be setting the ID your self. Leave that up to the provider to do. Just call addFeatures then you can get the id back using fet.id() –  Nathan W Apr 2 '13 at 5:56

1 Answer 1

I added an attribute with the id i wanted instead of changing the existing id.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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