Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 – Nathan W Apr 2 '13 at 5:56

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

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Would you be able to edit your answer to make it clear whether you are intending to provide an answer to your own question here, please? I think that is you intention but maybe you are instead trying to clarify your question, in which case an edit to your question rather than an answer would have been appropriate. – PolyGeo Feb 1 '15 at 1:07

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.