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

1 Answer 1

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 at 1:07

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.