Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a rotated rectangle in lat/lon coordinates.

Basically, I have the coordinates of the center and rotation angle around the center.

Is it possible to do using, shapely or gdal, or something else?

share|improve this question
up vote 4 down vote accepted

Unfortunately no. Shapely is basically an extension of GEOS, which does not offer any affine transformation abilities. If you are wondering if "how is this done in PostGIS?", they have this capability in liblwgeom, which is a general lightweight geometry function library (DB independent).

The most direct way to rotate (x,y) coordinates is to dig into the mathematics a bit, and use from math import cos, sin. If you are rotating about a non-origin (0,0) coordinate, then you need to add some +/- offsets to transform your coordinates before performing the trig functions.


As of Shapely version 1.2.17 there is an affinity module to do just this.

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))

See help(affinity) for documentation.

share|improve this answer
Unfortunately, a rotation in (lat, lon) is not performed with an affine transformation. You either have to project the data and rotate the projected coordinates or else perform a spherical rotation. – whuber Aug 11 '11 at 15:05
Oh right, I missed the (lat, lon) part of the question. I've never seen a affine transformation function built for geographic inputs, so the tips you provided are essential. – Mike T Aug 11 '11 at 22:27
Since v1.2.17, Shapely has had affine transformations, although they're not documented yet - – Alex L Apr 28 '13 at 7:49
Also see the author's blog: – Alex L Apr 28 '13 at 7:50
@AlexL type help(shapely.affinity). Actually I'm nearly done preparing the manual update for the module. – Mike T Apr 28 '13 at 10:19

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

You can download the soft here and launch 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. may help you to make the glue beetween python code and java (because one implementation use Jython)

share|improve this answer

Grass can do it using v.transform.

share|improve this answer

You can use the gdal python bindings to do affine transformations

Since it is built on top of proj/geos/gdal you can do the same things as in shapely + more

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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