I am trying to change the values of an attribute in one of my layers. My code is as follows:
from qgis.utils import iface
from PyQt4.QtCore import *
layer =iface.activeLayer()
pr=layer.dataProvider()
layer.startEditing()
for f in layer.getFeatures():
geom=f.geometry()
xval= geom.asPoint().x()
f['XX']=xval
layer.commitChanges()
print f['XX']
for f in layer.getFeatures():
print f['XX']
For my first print statement, I am getting the values out that I want, but when I run the second print statement, the values are what they were before running the code.
Am I Not committing changes correctly?