I am using QGIS 3.4. I am new in gis and I am trying to rotate a feature of a vector layer.
Code:
for ft in feat:
vlayer.startEditing()
the_geom = ft.geometry()
pt = ft.geometry().centroid().asPoint()
the_geom.rotate(-90, pt)
ft.setGeometry(the_geom)
iface.mapCanvas().refresh()
vlayer.commitChanges()
break
The geometry of the feature seems to change. However, I can not see any difference on the canvas.
Is there a better way to do this?
-
What is a "crs layer"?Erik– Erik2019年10月21日 13:25:25 +00:00Commented Oct 21, 2019 at 13:25
-
Sorry you are right, it's a vector layer.p374– p3742019年10月21日 13:27:17 +00:00Commented Oct 21, 2019 at 13:27
1 Answer 1
Just figured it out. For anyone who would like to check the solution:
for ft in feat:
vlayer.startEditing()
the_geom = ft.geometry()
pt = ft.geometry().centroid().asPoint()
the_geom.rotate(180, pt)
vlayer.dataProvider().changeGeometryValues({ 0 : the_geom })
vlayer.commitChanges()
break
lang-py