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 ( 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:


  • libgeos_c (2.2.3 or 3.0.0+)
  • Python ctypes (standard in Python 2.5+)


Shapely can be installed from the Python package index:

$ sudo easy_install Shapely

with the setup script:

$ sudo python install

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

$ svn co shapely.buildout
$ cd shapely.buildout
$ python
$ ./bin/buildout


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

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
>>> 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
>>> tuple(shape.coords)
((0.0, 0.0),)

See for more details on the interface.


Several of the modules have docstring doctests:

$ cd shapely
$ python

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

$ python test


For current information about this project, see the wiki.

If you have questions, please consider joining our community list:


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 (

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Shapely-1.0rc1-py2.4.egg (56.5 kB) Copy SHA256 hash SHA256 Egg 2.4
Shapely-1.0rc1.tar.gz (30.6 kB) Copy SHA256 hash SHA256 Source None
Shapely-1.0rc1.win32.exe (683.0 kB) Copy SHA256 hash SHA256 Windows Installer any

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page