Shapely 1.2a1

Update (2010-02-18): http://sgillies.net/blog/1001/shapely-1-2b1

Update (2010-02-09): 1.2a6 (12 cumulative bug fixes) is ready at http://gispython.org/dist/Shapely-1.2a6.tar.gz.

Shapely 1.2a1 has been tagged and uploaded to http://gispython.org/dist so that people don't get it by mistake from PyPI. To install and try it out (in a virtualenv):

$ pip install http://gispython.org/dist/Shapely-1.2a1.tar.gz

or

$ easy_install http://gispython.org/dist/Shapely-1.2a1.tar.gz

You'll need a GEOS version >= 3.1.1 to try the new prepared geometry class:

>>> from shapely.geometry import Point, Polygon
>>> triangle = Polygon(((0.0, 0.0), (1.0, 1.0), (1.0, -1.0)))
>>> from shapely.prepared import prep
>>> p = prep(triangle) # pre-analyze for efficient ops
>>> p.intersects(Point(0.5, 0.5))
True

Most of the work toward 1.2 has been done by Aron Bierbaum. Other features include geometry simplification, a switch to the new reentrant functions in libgeos_c, setup script consolidation, and more tests.

Comments

Re: Shapely 1.2a1

Author: Ian Bicking

Being new to this stuff, I'm a big vague on what Shapely is for, examples would be really helpful.

Re: Shapely 1.2a1

Author: Sean

Ian, I'm excited to see you crossing over into geographic applications! Anything I can do, please let me know.

All I've got for Shapely is a manual, a wiki page, and a readme. All of these, admittedly, lack a good "motivation" section (I'm as guilty of falling for the self-evidence of GIS as anyone), which could be reduced to this: Shapely allows you to do PostGIS-y stuff with idiomatic Python outside the context of a database. I should probably just replace all the GIS professional language with exactly that in the readme and wiki.

For example, you can pull a GeoRSS feed like this from Flickr and map the intersection of regions around items within it without importing it into a database.

The code for this app I was calling Mush is at http://sgillies.net/hg/mush/file/115d942603d3/mush/overlap.py.

Re: Shapely 1.2a1

Author: Michael Weisman

He Sean,

This looks great, but I think I'm missing something about when prepared geometries should be used.

I modified some code I have that does point on polygon overlays with n points to ~90,000 polygons to use prepared geometries and "time python script.py" tells me the that it actually takes 41.493 sec/point with prepared geoms vs 37.942 sec/point with standard shapely Polygon objects. The quick sample in your post also runs slightly slower with prepared geometries (0.098 sec vs 0.095 sec). When do the benefits of using prepared geoms outweigh the cost of creating them?

Thanks,

Michael

Re: Shapely 1.2a1

Author: Sean

Michael, you're prepping a point for comparison to many polygons? No gain there, I think. The feature is designed for the other case: preparing a complex polygon for comparison to many simpler geometries. We'll make sure that there's adequate documentation of this before a final 1.2.

Re: Shapely 1.2a1

Author: Michael Weisman

I was actually prepping 90,000 polys and leaving the points as standard Point geom objects. I'll play with this some more an see what I can work out.

Thanks!

Re: Shapely 1.2a1

Author: Sean

I've uploaded a prepared geometry benchmarking script to http://trac.gispython.org/lab/wiki/ShapelyBenchmarks. In the first, not entirely unrealistic case, I'm seeing 4x faster contains.