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.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.10.tar.gz (90.7 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.10.win-amd64.exe (1.5 MB view details)

Uploaded Source

Shapely-1.2.10.win32.exe (975.1 kB view details)

Uploaded Source

Shapely-1.2.10-py2.7-win-amd64.egg (1.3 MB view details)

Uploaded Egg

Shapely-1.2.10-py2.7-win32.egg (819.6 kB view details)

Uploaded Egg

Shapely-1.2.10-py2.6-win-amd64.egg (1.3 MB view details)

Uploaded Egg

Shapely-1.2.10-py2.6-win32.egg (837.5 kB view details)

Uploaded Egg

Shapely-1.2.10-py2.5-win32.egg (819.8 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for Shapely-1.2.10.tar.gz
Algorithm Hash digest
SHA256 aa23ba21b725e69af747af09aed5377b8f61569583d30bb71f1ab39bf96be806
MD5 eabe87efd5e0808445363ea9fc72a6aa
BLAKE2b-256 2ba85f095b0fc5cfe1197f96208582c1bd161a505fc95a652cc98db682e9bd68

See more details on using hashes here.

File details

Details for the file Shapely-1.2.10.win-amd64.exe.

File metadata

File hashes

Hashes for Shapely-1.2.10.win-amd64.exe
Algorithm Hash digest
SHA256 3b93a3d3a95fb250adcbc3274347e57a0bbba0507715bfaecb0e684538aa43a3
MD5 c12e63ec509a68d838f70c7f6d6f3c9e
BLAKE2b-256 73b271c9eb8724f637cdb5b4074c7594f6c305d7acf431cf588b041b9644019b

See more details on using hashes here.

File details

Details for the file Shapely-1.2.10.win32.exe.

File metadata

  • Download URL: Shapely-1.2.10.win32.exe
  • Upload date:
  • Size: 975.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Shapely-1.2.10.win32.exe
Algorithm Hash digest
SHA256 18382abc7f933ed5e7303f6b57f6ffa9d739ee1dd084ed6c766fabdfe91183c0
MD5 45e9648b04f5d41593df45925d10d39d
BLAKE2b-256 fe624fc360780cd187ca09198ed3439a50c730bf2a387f0a3b5befebc29d6bb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.10-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 976ca4a2d1f1dd1304362b2386b972ddc4e8cbeff54934d9cd28872b93bf8a52
MD5 24c60d3a1e7faea21a740a03fba02169
BLAKE2b-256 62d0a1f82120f5e6046b9af95c30add5ed7ebbf5c6abe9cab3986f7093d0ac3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.10-py2.7-win32.egg
Algorithm Hash digest
SHA256 f66705f416528530576f20e281e0ded556054974fd288408b3846ec808b4ca2d
MD5 246388c73f9bef84ed2e9107983d9151
BLAKE2b-256 b9839c4d97a521fd7462c4dc41ba5b428ed321f62a7c29695af4294d8e7dea01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.10-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 0e5a16066630067daf222dc88c804e8175d756a44eb7dff6d861107f2441c7b6
MD5 fcdec094e67f61f44f23c166546a763c
BLAKE2b-256 1ab995a5bd19468fd34747ee56e5782117b264cd2022eecf647d83c5425a8e44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.10-py2.6-win32.egg
Algorithm Hash digest
SHA256 b39083fb0cf242f8ec7a9e910e1834759411ae01e8f8a88c4fa9c65808f398eb
MD5 0255fb1d451fb43e4ea2977f1050ae98
BLAKE2b-256 e7b6f7d407b6f4948b1293024f000b5ed22b8f0d908caf5c067c2341231691c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Shapely-1.2.10-py2.5-win32.egg
Algorithm Hash digest
SHA256 ffa6d3b2dfba2059ddaf3691f6a7894fd66ee66059e0fb0d58d92ebf1600065b
MD5 eda5fcd4e767ee428dcb9cff48f682a3
BLAKE2b-256 b301aca38d60b971d15d44cc480db5ddde07345a509a40bb68663fc5e54bd7e4

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