Skip to main content

Geospatial geometries, predicates, and operations

Project description

Shapely is a Python package for programming with 2D geospatial geometries. It is based on GEOS (http://geos.refractions.net). Shapely 1.0 is ignorant about coordinate and reference systems. Projection responsibility is left to specific applications. For more information, see:

Shapely requires Python 2.4+. (I’ve also begun to port it to Python 3.0: http://zcologia.com/news/564/shapely-for-python-3-0/.)

Dependencies

  • libgeos_c (2.2.3 or 3.0.0+)

  • Python ctypes (standard in Python 2.5+)

Installation

Shapely can be installed from the Python package index:

$ sudo easy_install Shapely

with the setup script:

$ sudo python setup.py install

or by using the development buildout on Linux, which also provides libgeos_c:

$ svn co http://svn.gispython.org/svn/gispy/buildout/shapely.buildout/trunk shapely.buildout
$ cd shapely.buildout
$ python bootstrap.py
$ ./bin/buildout

Usage

To buffer a point:

>>> from shapely.geometry import Point
>>> point = Point(-106.0, 40.0) # longitude, latitude
>>> point.buffer(10.0)
<shapely.geometry.polygon.Polygon object at ...>

See the manual for comprehensive examples of usage. See also Operations.txt and Predicates.txt under tests/ for more examples of the spatial operations and predicates provided by Shapely. See also Point.txt, LineString.txt, etc for examples of the geometry APIs.

Numpy integration

All Shapely geometry instances provide the Numpy array interface:

>>> from numpy import asarray
>>> a = asarray(point)
>>> a.size
3
>>> a.shape
(2,)

Numpy arrays can also be adapted to Shapely points and linestrings:

>>> from shapely.geometry import asLineString
>>> a = array([[1.0, 2.0], [3.0, 4.0]])
>>> line = asLineString(a)
>>> line.wkt
'LINESTRING (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)'

Python Geo Interface

Any object that provides the Python geo interface can be adapted to a Shapely geometry with the asShape factory:

>>> d = {"type": "Point", "coordinates": (0.0, 0.0)}
>>> from shapely.geometry import asShape
>>> shape = asShape(d)
>>> shape.geom_type
'Point'
>>> tuple(shape.coords)
((0.0, 0.0),)

>>> class GeoThing(object):
...     def __init__(self, d):
...         self.__geo_interface__ = d
>>> thing = GeoThing({"type": "Point", "coordinates": (0.0, 0.0)})
>>> shape = asShape(thing)
>>> shape.geom_type
'Point'
>>> tuple(shape.coords)
((0.0, 0.0),)

See http://trac.gispython.org/projects/PCL/wiki/PythonGeoInterface for more details on the interface.

Testing

Several of the modules have docstring doctests:

$ cd shapely
$ python point.py

There are also two test runners under tests/. test_doctests.py requires zope.testing. runalldoctests.py does not. Perhaps the easiest way to run the tests is:

$ python setup.py test

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

Sean Gillies (Pleiades) Howard Butler (Hobu, Inc.) Kai Lautaportti (Hexagon IT) Frederic Junod (Camptocamp SA) Eric Lemoine (Camptocamp SA) Justin Bronn (GeoDjango) for ctypes inspiration Artem Pavlenko (Mapnik) for help with GEOS DLLs

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

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.0rc1.tar.gz (30.6 kB view details)

Uploaded Source

Built Distributions

Shapely-1.0rc1.win32.exe (683.0 kB view details)

Uploaded Source

Shapely-1.0rc1-py2.4.egg (56.5 kB view details)

Uploaded Source

File details

Details for the file Shapely-1.0rc1.tar.gz.

File metadata

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

File hashes

Hashes for Shapely-1.0rc1.tar.gz
Algorithm Hash digest
SHA256 33a05265515bc707d1ed7d8c8ca60a1557900e55d566ec958456dff04a8ccad9
MD5 77ac0c1f34e04b592f437c0b4d23ef06
BLAKE2b-256 1113984249041caca7b4f9f3cbc6b725f2e62ebfeae97ee2d05f383c2cf9284f

See more details on using hashes here.

File details

Details for the file Shapely-1.0rc1.win32.exe.

File metadata

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

File hashes

Hashes for Shapely-1.0rc1.win32.exe
Algorithm Hash digest
SHA256 32e30fda09e7e9e6b4ad14d80575b040bfdfe713f1fdd169ed52f4c7bde21c4f
MD5 065a4d3deb3455eff7f51bf5bc9e477f
BLAKE2b-256 c0783251a67835a802da94e54b6f4f43059adc8037357af2136c67a34716434f

See more details on using hashes here.

File details

Details for the file Shapely-1.0rc1-py2.4.egg.

File metadata

  • Download URL: Shapely-1.0rc1-py2.4.egg
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Shapely-1.0rc1-py2.4.egg
Algorithm Hash digest
SHA256 5ad9badfecc1d464328ce2b71f1e83490088b397c8eb9faa7be250e7be59d0b4
MD5 a8d7b059c208251d066f4f57d7082cbc
BLAKE2b-256 6846716179017060373eec9992737c9737119ec4c0187ccff3b479110d7bc211

See more details on using hashes here.

Supported by

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