6

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

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

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Dharmarajan
  • 447
  • 5
  • 9
  • http://gis.stackexchange.com/questions/23587/how-do-i-rotate-the-polygon-about-an-anchor-point-using-python-script – klewis Sep 10 '14 at 22:26

2 Answers2

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.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
dakcarto
  • 7,754
  • 26
  • 34
  • QgsMapToolRotateFeature option is seems to be semi-automatic[Using mouse events]. But I want to a rotate feature automatically to a specific angle. – Dharmarajan Sep 18 '14 at 04: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. – Snorfalorpagus Mar 19 '15 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)

Dharmarajan
  • 447
  • 5
  • 9