Toblerity/Shapely — pull request #197 by snorfalorpagus (2014-11-23 01:19:45+00:00)
Title: Added Cython speedup for shapely.affinity.affine_transform

There is a longstanding issue requesting improvement to the performance of the `shapely.affinity.affine_transform` function: https://github.com/Toblerity/Shapely/issues/93

As a baseline, the following code takes **21.7 seconds** to run on my machine:
```
import timeit
setup = 'import shapely.geometry; import shapely.affinity; circle = shapely.geometry.Point([0, 0]).buffer(10, resolution=1000);'
rotate = 'shapely.affinity.rotate(circle, 0.1, origin=[0, 0])'
print timeit.timeit(rotate, setup=setup, number=1000)
```

With the addition of the speedups to the creation of `LineString` and `LinearRing` objects this is reduced down to only **1.4 seconds**.

This pull request goes the next step by Cythonising `affine_transform`, and notably the internal `affine_pts` loop. The result is that the above code takes only **0.16 seconds**.

The code is a little lazy in that it only speeds up the transforms for `Point`, `LineString` and `LinearRing` objects, but gets `Polygon` and `Multi*` geometry speedups for free with the existing code.

Also, it uses the `geom_factory` function from Cython - I'm assuming this is OK?