Geometric objects, predicates, and operations
Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is not concerned with data formats or coordinate systems. It is based on the widely deployed GEOS (the engine of PostGIS) and JTS (from which GEOS is ported) libraries. This C dependency is traded for the ability to execute with blazing speed.
In a nutshell: Shapely lets you do PostGIS-ish stuff outside the context of a database using idiomatic Python. For more details, see:
Shapely 1.2 depends on:
- Python >=2.5,<3
- libgeos_c >=3.1 (3.0 and below have not been tested, YMMV)
Windows users should use the executable installer, which contains the required GEOS DLL. Other users should acquire libgeos_c by any means, make sure that it is on the system library path, and install from the Python package index:
$ pip install Shapely
or from a source distribution with the setup script:
$ python setup.py install
Here is the canonical example of building an approximately circular patch by buffering a point:
>>> from shapely.geometry import Point >>> patch = Point(0.0, 0.0).buffer(10.0) >>> patch <shapely.geometry.polygon.Polygon object at 0x...> >>> patch.area 313.65484905459385
Shapely does not read or write data files, but it can serialize and deserialize using several well known formats and protocols. The shapely.wkb and shapely.wkt modules provide dumpers and loaders inspired by Python’s pickle module.:
>>> from shapely.wkt import dumps, loads >>> dumps(loads('POINT (0 0)')) 'POINT (0.0000000000000000 0.0000000000000000)'
All linear objects, such as the rings of a polygon (like patch above), provide the Numpy array interface.:
>>> from numpy import asarray >>> ag = asarray(patch.exterior) >>> ag array([[ 1.00000000e+01, 0.00000000e+00], [ 9.95184727e+00, -9.80171403e-01], [ 9.80785280e+00, -1.95090322e+00], ... [ 1.00000000e+01, 0.00000000e+00]])
That yields a numpy array of [x, y] arrays. This is not always exactly what one wants for plotting shapes with Matplotlib, so Shapely 1.2 adds a xy property for getting separate arrays of coordinate x and y values.:
>>> x, y = patch.exterior.xy >>> ax = asarray(x) >>> ax array([ 1.00000000e+01, 9.95184727e+00, 9.80785280e+00, ...])
Numpy arrays can also be adapted to Shapely linestrings:
>>> from shapely.geometry import asLineString >>> asLineString(ag).length 62.806623139095073 >>> asLineString(ag).wkt 'LINESTRING (10.0000000000000000 0.0000000000000000, ...)'
Shapely uses a Zope-stye suite of unittests and doctests, excercised via setup.py.:
$ python setup.py test
Nosetests won’t run the tests properly; Zope doctest suites are not currently supported well by nose.
For current information about this project, see the wiki.
If you have questions, please consider joining our community list:
Shapely is written by:
- Sean Gillies
- Aron Bierbaum
- Kai Lautaportti
Patches contributed by:
- Howard Butler
- Frédéric Junod
- Eric Lemoine
- Jonathan Tartley
- Kristian Thy
- Oliver Tonnhofer
Additional help from:
- Justin Bronn (GeoDjango) for ctypes inspiration
- Martin Davis (JTS)
- Jaakko Salli for the Windows distributions
- Sandro Santilli, Mateusz Loskot, Paul Ramsey, et al (GEOS Project)
- Remove extra glob import.
- Move examples to shapely.examples.
- Add box() constructor for rectangular polygons.
- Fix extraneous imports.
- New parallel_offset method (#6).
- Support for Python 2.4.
- Support for Windows eggs.
- The geoms property of an empty collection yields  instead of a ValueError (#3).
- The coords and geometry type sproperties have the same behavior as above.
- Ensure that z values carry through into products of operations (#4).
- Stop distributing docs/_build.
- Include library fallbacks in test_dlls.py for linux platform.
- Raise AttributeError when there’s no backend support for a method.
- Raise OSError if libgeos_c.so (or variants) can’t be found and loaded.
- Add geos_c DLL loading support for linux platforms where find_library doesn’t work.
- Add mapping function.
- Fix problem with GEOSisValidReason symbol for GEOS < 3.1.
- Add representative_point method.
- Fixed bounds of singular polygons.
- Added shapely.validation.explain_validity function (#226).
- Final release.
- Add examples and tests to MANIFEST.in.
- Release candidate 2.
- Release candidate.
- Memory leak associated with new empty geometry state fixed.
- Broken GeometryCollection fixed.
- Objects can be constructed from others of the same type, thereby making copies. Collections can be constructed from sequences of objects, also making copies.
- Collections are now iterators over their component objects.
- New code for manual figures, using the descartes package.
- Adds support for the “sunos5” platform.
- Only provide simplification implementations for GEOS C API >= 1.5.
- Fix cascaded_union bug introduced in 1.2b1 (#212).
- Update the README. Remove cruft from setup.py. Add some version 1.2 metadata regarding required Python version (>=2.5,<3) and external dependency (libgeos_c >= 3.1).
- Add accessor for separate arrays of X and Y values (#210).
TODO: fill gap here
- Proper prototyping of WKB writer, and avoidance of errors on 64-bit systems (#191).
- Prototype libgeos_c functions in a way that lets py2exe apps import shapely (#189).
1.2 Branched (2009-09-19)
- Fix for references held by topology and predicate descriptors.
- Work around bug in GEOS 2.2.3, GEOSCoordSeq_getOrdinate not exported properly (#178).
- Fixed compatibility with GEOS 2.2.3 that was broken in 1.0.8 release (#176).
- Find and load MacPorts libgeos.
- Fill out GEOS function result and argument types to prevent faults on a 64-bit arch.
- Polygon rings now have the same dimensions as parent (#168).
- Eliminated reference cycles in polygons (#169).
- Fixed adaptation of multi polygon data.
- Raise exceptions earlier from binary predicates.
- Beginning distributing new windows DLLs (#166).
- Added access to GEOS polygonizer function.
- Raise exception when insufficient coordinate tuples are passed to LinearRing constructor (#164).
- Disentangle Python and topological equality (#163).
- Add shape(), a factory that copies coordinates from a geo interface provider. To be used instead of asShape() unless you really need to store coordinates outside shapely for efficient use in other code.
- Cache GEOS geometries in adapters (#163).
- Do not release GIL when calling GEOS functions (#158).
- Prevent faults when chaining multiple GEOS operators (#159).
- Fix loss of dimensionality in polygon rings (#155).
- Allow chaining expressions involving coordinate sequences and geometry parts (#151).
- Protect against abnormal use of coordinate accessors (#152).
- Coordinate sequences now implement the numpy array protocol (#153).
- Final release.
1.0 RC2 (2008-01-16)
- Added temporary solution for #149.
1.0 RC1 (2008-01-14)
- First release candidate
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size Shapely-1.2.9-py2.5-win32.egg (817.6 kB)||File type Egg||Python version 2.5||Upload date||Hashes View|
|Filename, size Shapely-1.2.9-py2.6-win32.egg (817.5 kB)||File type Egg||Python version 2.6||Upload date||Hashes View|
|Filename, size Shapely-1.2.9-py2.6-win-amd64.egg (1.3 MB)||File type Egg||Python version 2.6||Upload date||Hashes View|
|Filename, size Shapely-1.2.9-py2.7-win32.egg (817.4 kB)||File type Egg||Python version 2.7||Upload date||Hashes View|
|Filename, size Shapely-1.2.9-py2.7-win-amd64.egg (1.3 MB)||File type Egg||Python version 2.7||Upload date||Hashes View|
|Filename, size Shapely-1.2.9.tar.gz (63.1 kB)||File type Source||Python version None||Upload date||Hashes View|
|Filename, size Shapely-1.2.9.win32.exe (973.9 kB)||File type Windows Installer||Python version any||Upload date||Hashes View|
|Filename, size Shapely-1.2.9.win-amd64.exe (1.5 MB)||File type Windows Installer||Python version any||Upload date||Hashes View|
Hashes for Shapely-1.2.9-py2.6-win-amd64.egg
Hashes for Shapely-1.2.9-py2.7-win-amd64.egg