Skip to main content

Geometric objects, predicates, and operations

Project description

PostGIS-ish operations outside a database context for Pythoneers and Pythonistas.

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 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. Shapely is not concerned with data formats or coordinate systems, but can be readily integrated with packages that are. 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 (for example), so Shapely 1.2 adds a xy property for obtaining 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, exercised 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

Bugs may be reported and questions asked via https://github.com/Toblerity/Shapely.

Credits

Shapely is written by:

  • Sean Gillies

  • Aron Bierbaum

  • Kai Lautaportti

  • Oliver Tonnhofer

Patches contributed by:

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.14 (2012-01-23)

  • A geometry’s coords property is now sliceable, yielding a list of coordinate values.

  • Homogeneous collections are now sliceable, yielding a new collection of the same type.

1.2.13 (2011-09-16)

  • Fixed errors in speedups on 32bit systems when GEOS references memory above 2GB.

  • Add shapely.__version__ attribute.

  • Update the manual.

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.14.tar.gz (93.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Source

Shapely-1.2.14.win-amd64-py2.6.exe (1.5 MB view details)

Uploaded Source

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

Uploaded Source

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

Uploaded Source

Shapely-1.2.14.win32-py2.5.exe (919.5 kB view details)

Uploaded Source

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

Uploaded Egg

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

Uploaded Egg

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

Uploaded Egg

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

Uploaded Egg

Shapely-1.2.14-py2.5-win32.egg (922.3 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for Shapely-1.2.14.tar.gz
Algorithm Hash digest
SHA256 dc417f9ffafb79de989a8fb1c7a0a10dc5029f085abd831964d7e40c7ea78846
MD5 be8efc68e83b3db086ec092a835ae4e5
BLAKE2b-256 59d7b55171d4baa1ac3a4ca3db03406a48d505bf26816756672dbbbce5b317f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 df9ed4ee9ae27c30a8ea92d5fc50d33f9244ff83a6f9297edf37ad0cff241bca
MD5 01faf8efdbad1df72bb3c2c63ba7feff
BLAKE2b-256 d7c5013a5f3fa2401c18147abac5d2cfdd4050c54e35cf8957a088cbe405c091

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 5825980ea1201b3ab1a9aa6f4073185d629b9ffde4e5216283955ffb6ec6ebb5
MD5 06fbad3431dc91a787bf7cd3d1be8bbd
BLAKE2b-256 5011ed0df42e4810b99d02e2490c93a1b62f03b2641c586c466eeb332e75c9c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14.win32-py2.7.exe
Algorithm Hash digest
SHA256 76df1e8af1eabc05ebeb5bbdb96d8090fe4b0c4e227d5a69f693d06dc861af37
MD5 a0334123bf64f4d76fde521b1c5e6c77
BLAKE2b-256 cae69ef1e4c92fadad4f8bf26684f384effa81dba9b23ab04cd37dbfeb3c5614

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14.win32-py2.6.exe
Algorithm Hash digest
SHA256 fb828c4720e2d0c980cc1bf91d1532c682629956d0432f786b3c38af4fb5bf10
MD5 40af4ce9f6c26487a1c78c7e1ccbea86
BLAKE2b-256 72826a84b83d1f59e0c6a8b42e2eb0a9cc00aa6136f29602aa40c68052fc278b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14.win32-py2.5.exe
Algorithm Hash digest
SHA256 e60b8cb3b5f992558a43aa20aad6e799d9256b836622688d0367bfe09089a4e7
MD5 f053b43fa2e11bc6f04e3997454be8fc
BLAKE2b-256 72c4288c2ec5d64781aa324eea64a672eabbdc73b7c8342695817a94698eb24e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 9e20fc7535d71ace9ea3ff92455a05a4d15624e5962a81248373aa7e74cfe757
MD5 fc146bd016d751832451910e52d30a70
BLAKE2b-256 317cc3f424b4c412cf87e5b8957fe4c86319b5df5484139fe17e02b847a0108d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14-py2.7-win32.egg
Algorithm Hash digest
SHA256 bf1d664ce7f189bf17aec2b0850339dba12727071b06323351dcce00823815eb
MD5 3c025d772889ebaccc57b0acb7604408
BLAKE2b-256 6c33a0b4a616384497c39ef61d912ac9d6286e4ef1f72241c50a68e5642da9cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 5219a6b995a435d81ffe78cb168f0dc577c28ca29e3fcd5c654e0352f9ef0880
MD5 9175d095ef916a52033ec39bbf4ab09c
BLAKE2b-256 455bd9b19e80fb8c152084ebd65c28be2f654fa97d6ee51575390c47766d8579

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14-py2.6-win32.egg
Algorithm Hash digest
SHA256 7c6d37f9dd5335a2e9bbee66733ebd58ea839a0d4d0690789e6beeaa1b526abc
MD5 23aa16afaecb90e41136e60616096d13
BLAKE2b-256 e3c12f66b52bd2f6214adea55d0704ca894807c35ac23646a710dfd74336f29c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.14-py2.5-win32.egg
Algorithm Hash digest
SHA256 4eec01395b7d22cf7891e5ae142ab50bc435607ada861e6f6dbd6bc03acdb760
MD5 bbe19e0bd6e92da6ef61f6740c8907f7
BLAKE2b-256 c397f3aa9ce6b69922f550b3ec0d8281758cb3fe9046eb84a588cc3b7acbdf7f

See more details on using hashes here.

Supported by

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