I'm trying to iterate through all the features of a layer to change the value of some of its attributes. I'm using the following code:
from qgis.core import *
import os
working_folder = r'C:\myFolder'
fc_Opt_Prospect = os.path.join(working_folder, 'Equipm.gdb|layername=Prosp')
layer = QgsVectorLayer(fc_Opt_Prospect, 'Optimity_Prospect', 'ogr')
layer.startEditing()
for f in layer.getFeatures():
layer.changeAttributeValue(f.id(), 4, 3)
layer.changeAttributeValue(f.id(), 5, 6)
layer.commitChanges()
QgsProject.instance().addMapLayer(layer)
from qgis.core import *
import os
working_folder = r'C:\myFolder'
fc_Opt_Prospect = os.path.join(working_folder, 'Equipm.gdb|layername=Prosp')
layer = QgsVectorLayer(fc_Opt_Prospect, 'Optimity_Prospect', 'ogr')
layer.startEditing()
for f in layer.getFeatures():
layer.changeAttributeValue(f.id(), 4, 3)
layer.changeAttributeValue(f.id(), 5, 6)
layer.commitChanges()
QgsProject.instance().addMapLayer(layer)
When I check the attribute table of the layer I can see that no value has been changed. No error is thrown by the script.