I am selecting the features by "Property_T"
and its attribute is 'Open Land'
and I want to add some attribute to "SS"
field for same record. What is wrong?
from PyQt5.QtCore import QVariant
fn = "D:\Practice\Parcels.shp"
layer = iface.addVectorLayer(fn, '', 'ogr')
caps = layer.dataProvider().capabilities()
if caps & QgsVectorDataProvider.AddAttributes:
res = layer.dataProvider().addAttributes([QgsField('SS', QVariant.String)])
layer.updateFields()
query = "Property_T = 'Open Land'"
selection = layer.getFeatures(QgsFeatureRequest().setFilterExpression(query))
layer.selectByIds([s.id() for s in selection])
iface.mapCanvas().setSelectionColor(QColor('Blue'))
features = layer.selectedFeatures()
for feat in features:
if feat['Property_T'] == 'Open Land':
with edit(layer):
feat['SS'] = 'RR'
layer.updateFeature(feat)