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.

I want to change vector attributes values.

i could not get the command fet.setAttribute indeed, it is mentionned in http://hub.qgis.org/issues/7223 that:

"The QgsFeature instance now must be first initialized with initAttributes() to know how many attributes it will contain. Then there's setFields() call that allows doing name-to-index mapping in QgsFeature."

however, i could not get fet.initAttributes() and fet.setFields() working. (newbie...)

the error message I get is "AttributeError: 'QgsFeature' object has no attribute 'initAttributes'".

any help appreciated.

qgis version: 1.8.0

gis-python version: 1.8.0-8

python: 2.7.3-7.2

os: fedora17

share|improve this question
add comment

2 Answers

That is the new QGIS 2.0 (not released) API. 1.8 uses a different method.


feature.changeAttribute(columnnumber, value)


layer.changeAttributeValue(feature.id(), columnnumber, value)


layer.changeAttributeValue(feature.id(), 3, "Hello World")
share|improve this answer
many thanks, this solved my problem ! –  user16542 Mar 26 '13 at 18:14
@user16542 Please upvote helpful answers and accept this answer if it solved your problem. –  underdark Mar 26 '13 at 18:29
add comment

@underdark: I cannot vote up for the answer because 15 reputation is needed. and i'm not sure i can accept the answer because the question was posted as a guest. or is it possible though ?

share|improve this answer
Please don't add comments on existing posts as a "new answer". –  BradHards Mar 27 '13 at 9:05
add comment

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.