Skip to main content
added 29 characters in body; edited tags; edited title
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

How to permanently Permanently change attribute values using PyQGIS?

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.

How to permanently change attribute values using PyQGIS?

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.

Permanently change attribute values using PyQGIS

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.

Bumped by Community user
Bumped by Community user
Source Link
Pitrako Junior
  • 1.3k
  • 18
  • 31

How to permanently change attribute values using PyQGIS?

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.