I am working with Landusefc
and Class
columns (ref table).
What I want is: Selecting all water from "Class"
and giving a value say '8'
in the "Landusefc"
column for these selected features.
Table looks like
I have tried the following code, it works till the selection part but doesn't seem to change the attribute value using the ChangeAttributeValue
.
from qgis.core import *
import processing
layer=processing.getObject('test1')
query= ' "class" = \'Water\' '
selection = layer.getFeatures(QgsFeatureRequest().setFilterExpression(query))
layer.setSelectedFeatures([k.id() for k in selection])
#using change Attribute to change the value of the selected feature
layer.startEditing()
for feat in selection:
layer.changeAttributeValue(feat.id(), 5, 8)
layer.commitChanges()