2

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)

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.

2 Answers 2

2

QGIS can't edit Esri file geodatabases, even at version 3.8:

enter image description here

1
  • 3.22 I believe editing was introduced to FGDB. Whether the above script will work though, not 100%.
    – nr_aus
    Aug 31, 2023 at 13:55
0

I have realised that "layer.startEditing()" is returning false. For some reason the layer is not editable. I guess that's the reason why values are not changed at all with the script above. Now remains the question of why the layer is not editable.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.