4

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

underdark
84.9k22 gold badges237 silver badges419 bronze badges
asked Mar 26, 2013 at 11:49

1 Answer 1

11

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

Use:

feature.changeAttribute(columnnumber, value)

or:

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

Example:

layer.changeAttributeValue(feature.id(), 3, "Hello World")
answered Mar 26, 2013 at 11:56
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.