2

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?

2
  • What is a "crs layer"?
    – Erik
    Oct 21, 2019 at 13:25
  • Sorry you are right, it's a vector layer.
    – p374
    Oct 21, 2019 at 13:27

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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