I have a layer containing several small square geometries in QGIS. I want to tilt these ones by one to the same angle. So I wrote the following Python code for that, but it does not work properly. Could you please give me some suggestions for improvement?
#import processing
layer_name = "my_layer"
layer = QgsProject.instance().mapLayersByName(layer_name)[0]
features = layer.getFeatures()
for feature in features:
geometry = feature.geometry()
center = geometry.centroid().asPoint()
rotated_geometry = geometry.rotate(33, center)
feature.setGeometry(rotated_geometry)
layer.updateFeature(feature)
layer.updateExtents()