Skip to main content

Geometric objects, predicates, and operations

Project description

README

http://farm3.static.flickr.com/2738/4511827859_b5822043b7_o_d.png

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:

Dependencies

Shapely 1.2 depends on:

  • Python >=2.5,<3

  • libgeos_c >=3.1 (3.0 and below have not been tested, YMMV)

Installation

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

Usage

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

See the manual for comprehensive usage snippets and the dissolve.py and intersect.py example apps.

Integration

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, ...)'

Testing

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.

Support

For current information about this project, see the wiki.

If you have questions, please consider joining our community list:

http://trac.gispython.org/projects/PCL/wiki/CommunityList

Credits

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)

Major portions of this work were supported by a grant (for Pleiades) from the U.S. National Endowment for the Humanities (http://www.neh.gov).

CHANGES

1.2.12 (2011-08-15)

  • Build Windows distributions with VC7 or VC9 as appropriate.

  • More verbose report on failure to speed up.

  • Fix for prepared geometries broken in 1.2.11.

  • DO NOT INSTALL 1.2.11

1.2.11 (2011-08-04)

  • Ignore AttributeError during exit.

  • PyPy 1.5 support.

  • Prevent operation on prepared geometry crasher (#12).

  • Optional Cython speedups for Windows.

  • Linux 3 platform support.

1.2.10 (2011-05-09)

  • Add optional Cython speedups.

  • Add is_cww predicate to LinearRing.

  • Add function that forces orientation of Polygons.

  • Disable build of speedups on Windows pending packaging work.

1.2.9 (2011-03-31)

  • Remove extra glob import.

  • Move examples to shapely.examples.

  • Add box() constructor for rectangular polygons.

  • Fix extraneous imports.

1.2.8 (2011-12-03)

  • New parallel_offset method (#6).

  • Support for Python 2.4.

1.2.7 (2010-11-05)

  • Support for Windows eggs.

1.2.6 (2010-10-21)

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

1.2.5 (2010-09-19)

  • Stop distributing docs/_build.

  • Include library fallbacks in test_dlls.py for linux platform.

1.2.4 (2010-09-09)

  • 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.

1.2.3 (2010-08-17)

  • Add mapping function.

  • Fix problem with GEOSisValidReason symbol for GEOS < 3.1.

1.2.2 (2010-07-23)

  • Add representative_point method.

1.2.1 (2010-06-23)

  • Fixed bounds of singular polygons.

  • Added shapely.validation.explain_validity function (#226).

1.2 (2010-05-27)

  • Final release.

1.2rc2 (2010-05-26)

  • Add examples and tests to MANIFEST.in.

  • Release candidate 2.

1.2rc1 (2010-05-25)

  • Release candidate.

1.2b7 (2010-04-22)

  • Memory leak associated with new empty geometry state fixed.

1.2b6 (2010-04-13)

  • Broken GeometryCollection fixed.

1.2b5 (2010-04-09)

  • 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.

1.2b4 (2010-03-19)

  • Adds support for the “sunos5” platform.

1.2b3 (2010-02-28)

  • Only provide simplification implementations for GEOS C API >= 1.5.

1.2b2 (2010-02-19)

  • Fix cascaded_union bug introduced in 1.2b1 (#212).

1.2b1 (2010-02-18)

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

1.2a6 (2010-02-09)

  • Add accessor for separate arrays of X and Y values (#210).

TODO: fill gap here

1.2a1 (2010-01-20)

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

1.0.12 (2009-04-09)

  • Fix for references held by topology and predicate descriptors.

1.0.11 (2008-11-20)

  • Work around bug in GEOS 2.2.3, GEOSCoordSeq_getOrdinate not exported properly (#178).

1.0.10 (2008-11-17)

  • Fixed compatibility with GEOS 2.2.3 that was broken in 1.0.8 release (#176).

1.0.9 (2008-11-16)

  • Find and load MacPorts libgeos.

1.0.8 (2008-11-01)

  • Fill out GEOS function result and argument types to prevent faults on a 64-bit arch.

1.0.7 (2008-08-22)

  • Polygon rings now have the same dimensions as parent (#168).

  • Eliminated reference cycles in polygons (#169).

1.0.6 (2008-07-10)

  • Fixed adaptation of multi polygon data.

  • Raise exceptions earlier from binary predicates.

  • Beginning distributing new windows DLLs (#166).

1.0.5 (2008-05-20)

  • Added access to GEOS polygonizer function.

  • Raise exception when insufficient coordinate tuples are passed to LinearRing constructor (#164).

1.0.4 (2008-05-01)

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

1.0.3 (2008-04-09)

  • Do not release GIL when calling GEOS functions (#158).

  • Prevent faults when chaining multiple GEOS operators (#159).

1.0.2 (2008-02-26)

  • Fix loss of dimensionality in polygon rings (#155).

1.0.1 (2008-02-08)

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

1.0 (2008-01-18)

  • Final release.

1.0 RC2 (2008-01-16)

  • Added temporary solution for #149.

1.0 RC1 (2008-01-14)

  • First release candidate

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Shapely-1.2.12.tar.gz (91.7 kB view details)

Uploaded Source

Built Distributions

Shapely-1.2.12.win-amd64-py2.7.exe (1.5 MB view details)

Uploaded Source

Shapely-1.2.12.win-amd64-py2.6.exe (1.4 MB view details)

Uploaded Source

Shapely-1.2.12.win32-py2.7.exe (1.2 MB view details)

Uploaded Source

Shapely-1.2.12.win32-py2.6.exe (1.2 MB view details)

Uploaded Source

Shapely-1.2.12.win32-py2.5.exe (917.6 kB view details)

Uploaded Source

Shapely-1.2.12-py2.7-win-amd64.egg (1.4 MB view details)

Uploaded Egg

Shapely-1.2.12-py2.7-win32.egg (1.0 MB view details)

Uploaded Egg

Shapely-1.2.12-py2.6-win-amd64.egg (1.4 MB view details)

Uploaded Egg

Shapely-1.2.12-py2.6-win32.egg (1.0 MB view details)

Uploaded Egg

Shapely-1.2.12-py2.5-win32.egg (917.8 kB view details)

Uploaded Egg

File details

Details for the file Shapely-1.2.12.tar.gz.

File metadata

  • Download URL: Shapely-1.2.12.tar.gz
  • Upload date:
  • Size: 91.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Shapely-1.2.12.tar.gz
Algorithm Hash digest
SHA256 8265094e9bebf0ab0957f0dc12ac320c226d457726f08bcd3295d1a6f6d3e6e7
MD5 6d75fafb06f87bd330aa258adcdd0d8b
BLAKE2b-256 60ca4f4872fc430954ba1e5945e5365ddd43d9b6deada4536cde44d6998d17a8

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for Shapely-1.2.12.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 966ed43a6b670bc3cad5df13e44d43bc5437d3365899eb9b2d254210e66b5e12
MD5 1d4205976e38b133e8f7c5931be1787c
BLAKE2b-256 78b340cab6c9ed723efe529874e162ba66766dde05f270ecf6d50d12503257a9

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12.win-amd64-py2.6.exe.

File metadata

File hashes

Hashes for Shapely-1.2.12.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 fc5dca9974b46d47b76459ed74a4af9205190c52cdfeabccfa451d9a1868a872
MD5 9738e8d67ceb7502d209efdb95152ceb
BLAKE2b-256 39c71a9218c8fda427134d2979c0191e5aeb13ecfb2aec3b4b867f293b506dd5

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12.win32-py2.7.exe.

File metadata

File hashes

Hashes for Shapely-1.2.12.win32-py2.7.exe
Algorithm Hash digest
SHA256 2ba70144d7e718f0915b96d680fce6c4e1105168cb9bde8486962cfbc71d657a
MD5 ba292a5842d4c00acc7be287b2634b65
BLAKE2b-256 46ae8eb6da30a41031ba5dd2f93c49f5a4bedd72820ad789aa72ae9e32cb61a1

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12.win32-py2.6.exe.

File metadata

File hashes

Hashes for Shapely-1.2.12.win32-py2.6.exe
Algorithm Hash digest
SHA256 6e67658de866e7311dcb7e63980fd26d0a347f04a19540c33004144d4432c1b6
MD5 01443dbe759b62a57b745d94d5605223
BLAKE2b-256 e45881a95c29fca93efff80e7242236d79e097d533b64aafdbd7dda7d82a6990

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12.win32-py2.5.exe.

File metadata

File hashes

Hashes for Shapely-1.2.12.win32-py2.5.exe
Algorithm Hash digest
SHA256 fb4b3b57e75ca367bed7da321cad61a6131756c14e5a95e010abc8c81f66580d
MD5 7ed58ce35dcd0a58d5adf245194f29d1
BLAKE2b-256 296eff6c657b24249be1e2376adfbba463603871165e915c79b5393c7c7d0a0f

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12-py2.7-win-amd64.egg.

File metadata

File hashes

Hashes for Shapely-1.2.12-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 1d780d9254b3239e224518e8c7646dd1e458a9aa81f7110cbcf8cfc57b18315d
MD5 0d15279b8fadff23b9d927fbf9e0e423
BLAKE2b-256 e53318b0a29ee62e18b369cce13b4b3d06f69b405b87fe9aaff3ed3a89fb9004

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12-py2.7-win32.egg.

File metadata

File hashes

Hashes for Shapely-1.2.12-py2.7-win32.egg
Algorithm Hash digest
SHA256 63554afd4ace85962a687aa993e749dd18d4c6be9a5fb4c47122135e567e8843
MD5 ee789ae25a2d957d5e220da5561141cb
BLAKE2b-256 858a388d84f96573b5cdd02c6142bd7d5166060480cbf0be393e92721b5f2ebf

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12-py2.6-win-amd64.egg.

File metadata

File hashes

Hashes for Shapely-1.2.12-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 9d0d09554ba7cc176e3cf942dc30c64b78df5eab34d6d96cc090ea5d5d7a5487
MD5 5231665c1f6fafbda3f8a3260178e2e7
BLAKE2b-256 b1b68a249a43f70a6362ba5a5a982d26e47ff6790b9d12cc6684d9864a13ac51

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12-py2.6-win32.egg.

File metadata

File hashes

Hashes for Shapely-1.2.12-py2.6-win32.egg
Algorithm Hash digest
SHA256 fac6dc87192e6d0095e1d093ebb93230d680786496a2ab7fc1e2ca955936a925
MD5 eb2a54d06e8fc0c259b4870d12f1af64
BLAKE2b-256 0fe56a3822f107e8d1a8edd92e14423954705d2cef5cdf0f660fa8c48a0439e4

See more details on using hashes here.

File details

Details for the file Shapely-1.2.12-py2.5-win32.egg.

File metadata

File hashes

Hashes for Shapely-1.2.12-py2.5-win32.egg
Algorithm Hash digest
SHA256 9a34bc8c8c81f31e32d58194182fcfa8b9b07f52ecfd2d2389419c8d4da5a820
MD5 efaa64914829bd1347719c8ad86044f5
BLAKE2b-256 1b34c700845ebd4129422518f6a6d5db5c63f80f3ab82c5b82f5efc5baa90470

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page