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()
vl.startEditing()
fet = QgsFeature()
fet.setGeometry( QgsGeometry.fromMultiPolyline( [[ QgsPoint(x3,y3),QgsPoint(x4,y4) ]] ))
fet.setFeatureId(10001)
pr.addFeatures( [ fet ] )
vl.commitChanges()
share|improve this question
3  
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
add comment

1 Answer 1

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

share|improve this answer
add comment

Your Answer

 
discard

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.