Skip to main content

Geospatial geometries, predicates, and operations

Project description

Shapely is a Python package for programming with 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, 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

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 Operations.txt and Predicates.txt under tests/ for more examples of the spatial operations and predicates provided by Shapely. Also see 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.

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

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

Uploaded Source

Built Distribution

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

Shapely-1.0b4-py2.4.egg (56.1 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for Shapely-1.0b4.tar.gz
Algorithm Hash digest
SHA256 65d9fe9aa4066dcff1ff9f3b49b49146690d836848cba73317ec666d68f737da
MD5 fd547787814c407bbe73539e99182a9a
BLAKE2b-256 d74304b4ef0c39f0be3832ecc140cfb3b14fe5d967fcbf6c8f74fdded2194093

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Shapely-1.0b4-py2.4.egg
  • Upload date:
  • Size: 56.1 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Shapely-1.0b4-py2.4.egg
Algorithm Hash digest
SHA256 e0a0b2e4d087e68651ddb9dbdb108e47fcd0253a7d17036671ee88641f992767
MD5 ab0592aca8771ed5f361cda5104b804a
BLAKE2b-256 7fc6a118f2367bdc75dd789e0c55f8476b71db53db048c0a9b8a876d149ae16f

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