6

I do not know how to rotate a geometry using pyqgis.

Is there any sample/example code available to show me how?

1

2 Answers 2

3

While not in Python, you can review the C++ code used by the Rotate Feature map tool.

Note:

The tool is interactive, so it uses the user input press and move events (e.g. like with a mouse) to calculate the degree of rotation to be applied.

The QgsMapToolRotateFeature::canvasReleaseEvent, where the calculated rotation is applied to the feature, is probably the code you are looking for.

2
  • QgsMapToolRotateFeature option is seems to be semi-automatic[Using mouse events]. But I want to a rotate feature automatically to a specific angle. Commented Sep 18, 2014 at 4:42
  • Look at the code in the canvasReleaseEvent function. L203-210 define the affine transformation, L224-243 apply the transformation to each point in the geometry. This is what you'd need. Or, as you say, you can do it using Shapely. Commented Mar 19, 2015 at 10:16
2

It can be accomplish, by using a python package named shapely.

Eg: shapely.affinity.rotate(ring,degres,origin='centroid',use_radians=False)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.