I went through different Stack Overflow questions, tutorials and the official PyQGIS cookbook. Somehow I cannot make a basic manipulation of the geometry of a layer's features.
This is the code I try to run. All that happens is that the layer is loaded into the project totally unchanged and the print(new)
gives me the old coordinate values (but the print(geometry())
inside the loop gives me the correct new geometry). Is it because it is a .kmz
file?
import os
from qgis.core import (
QgsVectorLayer
)
layer = QgsVectorLayer("/my_layer.kmz", "myLayer", "ogr")
layer.startEditing()
for f in layer.getFeatures():
id = f.id()
geom = f.geometry()
geom.translate(10,10)
f.setGeometry(geom)
layer.dataProvider().changeGeometryValues({ id : geom })
print(f.geometry())
layer.commitChanges()
#Check if new geometry was written into layer
for f in layer.getFeatures():
new = f.geometry()
print(new)
QgsProject.instance().addMapLayers([layer])
I am using QGIS 3.16
"/my_layer.shp"
instead of"/my_layer.kmz"
after saving kmz to shp to confirm the issue is with the kmz format not elsewhere?