Skip to main content

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

Release files for shapely 1.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shapely 1.2.9
File Size Uploaded
Shapely-1.2.9.tar.gz 63.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for shapely 1.2.9
File
Shapely-1.2.9.win-amd64.exe Details
Shapely-1.2.9.win32.exe Details
Shapely-1.2.9-py2.7-win-amd64.egg Legacy Egg format - - Details
Shapely-1.2.9-py2.7-win32.egg Legacy Egg format - - Details
Shapely-1.2.9-py2.6-win-amd64.egg Legacy Egg format - - Details
Shapely-1.2.9-py2.6-win32.egg Legacy Egg format - - Details
Shapely-1.2.9-py2.5-win32.egg Legacy Egg format - - Details

Total release size: 7.7 MB

Release files / Shapely-1.2.9.tar.gz

Download URL Shapely-1.2.9.tar.gz
Size 63.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e53490a8fbc9f10db6ed55e8f586d2474402e3c01af406e8d7ce000eccea3a0a
BLAKE2b-256 checksum
How to use checksums
d357404aa35c0ca2e50dae9b93be4754506cb03226434644a82384f1b2355ffe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Shapely-1.2.9.win-amd64.exe

Download URL Shapely-1.2.9.win-amd64.exe
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
79d278c648770f0945f774f00b9072ea38fc702d1ac86d136465cd9674a2b83a
BLAKE2b-256 checksum
How to use checksums
7ec2a8c3066a881a1cd88236966dc1cc4f088282fa3e4611055ae1f0ffdd69d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Shapely-1.2.9.win32.exe

Download URL Shapely-1.2.9.win32.exe
Size 973.9 kB
Tags Source
SHA-256 checksum
How to use checksums
11c7db73cc87466d63cc5ee3a6256103ef56ed4795fd7a4bf7c02164ab83b3de
BLAKE2b-256 checksum
How to use checksums
92c5c5fabcdb17779bbf6b036de5e8b5907ab94d05d1ff804bf7431cee204090
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Shapely-1.2.9-py2.7-win-amd64.egg

Download URL Shapely-1.2.9-py2.7-win-amd64.egg
Size 1.3 MB
Tags Egg
SHA-256 checksum
How to use checksums
bffb5f0286ae68390bb4c0986d2a5043773a4c31eb5e006228e2f0f83b1cc8df
BLAKE2b-256 checksum
How to use checksums
ffc8d0fb178df594a3f8704c8a04250ada8b4b5c7a6b3f68e8c6fa5718ed671e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Shapely-1.2.9-py2.7-win32.egg

Download URL Shapely-1.2.9-py2.7-win32.egg
Size 817.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
8e82ca099418ae061fdf16619f5e5c6f352fe61557738cfff7bb983cb6a4b95f
BLAKE2b-256 checksum
How to use checksums
339eabd848c003622f362d3bad92f6ea356b6c8d47b629c0c007bf355f670e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Shapely-1.2.9-py2.6-win-amd64.egg

Download URL Shapely-1.2.9-py2.6-win-amd64.egg
Size 1.3 MB
Tags Egg
SHA-256 checksum
How to use checksums
aa195e8b18fd1f487f43bd1ce75f951b376ea944bce46602372e1d20d2eb350d
BLAKE2b-256 checksum
How to use checksums
6eeac0bf6f7cf122b40ab6339eaaa5f08a85080d524b80e38f71dbf8c72e251c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Shapely-1.2.9-py2.6-win32.egg

Download URL Shapely-1.2.9-py2.6-win32.egg
Size 817.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
3bc688237172d65bbe58901e064453037f04b5ae05a74d9ac95253b8b0127b50
BLAKE2b-256 checksum
How to use checksums
5280a49794ac69d49cd1031dbb517d7679d234a3ba8eac4adfd70a89003a4c0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Shapely-1.2.9-py2.5-win32.egg

Download URL Shapely-1.2.9-py2.5-win32.egg
Size 817.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
e6439bdf30595a0a14f46b4c482859436530323031d34d81e539235ea0b4538f
BLAKE2b-256 checksum
How to use checksums
f9beaeb2bd40ee23b213816945894c2a12bf11cce3032faf111d3a62fcb71d8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.1.2

57 release files

2.1.1

41 release files

2.0.7

42 release files

2.0.6

42 release files

2.0.5

36 release files

2.0.4

41 release files

2.0.3

41 release files

2.0.2

41 release files

2.0.1

38 release files

2.0.0

38 release files

1.8.5

34 release files

1.8.4

34 release files

1.8.3

31 release files

1.8.1

26 release files

1.8.0

21 release files

1.7.1

23 release files

1.7.0

19 release files

1.6.4

10 release files

1.6.2

6 release files

1.6.1

6 release files

1.6.0

6 release files

1.5.17

4 release files

1.5.16

4 release files

1.5.15

4 release files

1.5.14

4 release files

1.5.13

4 release files

1.5.12

3 release files

1.5.11

3 release files

1.5.10

3 release files

1.5.9

3 release files

1.5.8

3 release files

1.5.7

3 release files

1.5.6

3 release files

1.5.5

3 release files

1.5.4

3 release files

1.5.3

3 release files

1.5.2

2 release files

1.5.1

1 release file

1.5.0

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.3.3

11 release files

1.3.2

5 release files

1.3.1

5 release files

1.3.0

5 release files

1.2.19

1 release file

1.2.18

9 release files

1.2.17

5 release files

1.2.16

1 release file

1.2.15

1 release file

1.2.10

8 release files

This release

1.2.9 This release

8 release files

1.2.8

8 release files

1.2.7

6 release files

1.2.6

3 release files

1.2.5

3 release files

1.2.4

1 release file

1.2.3

3 release files

1.2.2

3 release files

1.2.1

3 release files

1.2

3 release files

1.0.15

1 release file

1.0.13

1 release file

1.0.11

2 release files

1.0.8

1 release file

1.0.7

2 release files

1.0.6

2 release files

1.0.5

1 release file

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page