Python, shapely library: is it possible to do an affine operation on shape polygon?

Shapely's affinity module supports affine transformations on any geometry, for example:

from shapely import affinity
from shapely.geometry import LineString

# Example geometry
line = LineString([(1, 3), (1, 1), (4, 1)])

# Rotate 30 degrees CCW from origin at the center of bbox
line_rot_center = affinity.rotate(line, 30, 'center')

# Rotate from origin at (1, 1)
line_rot_11 = affinity.rotate(line, 30, (1, 1))

Sextante has a tool that might work. It is called Transform, under the "Tools for Vector layers". To run the command, define the angle, anchor point, scale factor and translation. Sextante is an extension to gvsig, openjump, udig, others. It also runs from the command-line.


I don't see any features in Python or Shapely to do so but you can do this with JTS (Java Topology Suite) http://tsusiatsoftware.net/jts/main.html (GEOS, the lib used by Shapely is a port of JTS but JTS have more functions)

You can download the soft here http://sourceforge.net/projects/jts-topo-suite/ and launch testbuilder.sh or testbuilder.bat depending on your OS to play for discovering. After you understood, the basics you will have to do the same without GUI but with Java programming only.

http://geoscript.org/ may help you to make the glue beetween python code and java (because one implementation use Jython)