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.

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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