Manipulation and analysis of geometric objects
Python PowerShell Other
Permalink
Failed to load latest commit information.
DLLs_AMD64_VC9 Directory changes to support new Windows build system Aug 9, 2011
DLLs_x86_VC7 Directory changes to support new Windows build system Aug 9, 2011
DLLs_x86_VC9 Directory changes to support new Windows build system Aug 9, 2011
_vendor Use automatic formatters (py2.7+) Mar 5, 2018
appveyor Added appveyor configuration (#626) Aug 11, 2018
build-scripts First take on a build script for OS X. Jan 5, 2015
docs https all the links, plus updates (#619) Jul 30, 2018
shapely Disallow sequences of MultiPolygon as argument to ctor. Aug 12, 2018
tests Disallow sequences of MultiPolygon as argument to ctor. Aug 12, 2018
tools Directory changes to support new Windows build system Aug 9, 2011
.dockerignore Build manylinux1 wheels Jul 7, 2016
.gitignore Added venv/, .coverage, and ignore/ to .gitignore and use setup.cfg t… Jul 19, 2016
.travis.yml Added Python 3.7 to Travis (#627) Aug 12, 2018
CHANGES.txt Disallow sequences of MultiPolygon as argument to ctor. Aug 12, 2018
CITATION.txt missing `}` Jun 29, 2016
CODE_OF_CONDUCT.md Add code of conduct. Nov 6, 2015
CREDITS.txt Update credits Aug 21, 2017
Dockerfile.wheels Build manylinux1 wheels Jul 7, 2016
GEOS-C-API.txt Remove reference to GEOSCoordSeq_getOrdinate (#178) Nov 19, 2008
ISSUE_TEMPLATE.md Add an issue template Feb 24, 2017
LICENSE.txt Add new files, increment version to 1.0b1 Nov 20, 2007
MANIFEST.in Added appveyor configuration (#626) Aug 11, 2018
README.rst Drop support for EOL Python 3.3 Mar 5, 2018
appveyor.yml Added appveyor configuration (#626) Aug 11, 2018
build-linux-wheels.sh Build manylinux1 wheels Jul 7, 2016
build-wheels.sh Build script for wheels, bump version. Jan 13, 2015
environment.yml Add descartes Aug 2, 2017
readthedocs.yml Relocate config files Aug 21, 2017
requirements-dev.txt Added appveyor configuration (#626) Aug 11, 2018
setup.cfg Full vendorization of packaging Feb 15, 2017
setup.py Add a runtime Python version check in setup.py (#610) Jul 18, 2018

README.rst

Shapely

https://travis-ci.org/Toblerity/Shapely.svg?branch=master https://coveralls.io/repos/github/Toblerity/Shapely/badge.svg?branch=master

Manipulation and analysis of geometric objects in the Cartesian plane.

https://c2.staticflickr.com/6/5560/31301790086_b3472ea4e9_c.jpg

Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is based on the widely deployed GEOS (the engine of PostGIS) and JTS (from which GEOS is ported) libraries. Shapely is not concerned with data formats or coordinate systems, but can be readily integrated with packages that are. For more details, see:

Requirements

Shapely 1.6 requires

  • Python 2.7, >=3.4
  • GEOS >=3.3

Installing Shapely 1.6

Shapely may be installed from a source distribution or one of several kinds of built distribution.

Built distributions

Windows users have two good installation options: the wheels at http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely and the Anaconda platform's conda-forge channel.

OS X and Linux users can get Shapely wheels with GEOS included from the Python Package Index with a recent version of pip (8+):

$ pip install shapely

A few extra speedups that require Numpy can be had by running

$ pip install shapely[vectorized]

Shapely is available via system package management tools like apt, yum, and Homebrew, and is also provided by popular Python distributions like Canopy and Anaconda.

Source distributions

If you want to build Shapely from source for compatibility with other modules that depend on GEOS (such as cartopy or osgeo.ogr) or want to use a different version of GEOS than the one included in the project wheels you should first install the GEOS library, Cython, and Numpy on your system (using apt, yum, brew, or other means) and then direct pip to ignore the binary wheels.

$ pip install shapely --no-binary shapely

If you've installed GEOS to a standard location, the geos-config program will be used to get compiler and linker options. If geos-config is not on your executable, it can be specified with a GEOS_CONFIG environment variable, e.g.:

$ GEOS_CONFIG=/path/to/geos-config pip install shapely

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

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)'

Shapely can also integrate with other Python GIS packages using GeoJSON-like dicts.

>>> import json
>>> from shapely.geometry import mapping, shape
>>> s = shape(json.loads('{"type": "Point", "coordinates": [0.0, 0.0]}'))
>>> s
<shapely.geometry.point.Point object at 0x...>
>>> print(json.dumps(mapping(s)))
{"type": "Point", "coordinates": [0.0, 0.0]}

Development and Testing

Dependencies for developing Shapely are listed in requirements-dev.txt. Cython and Numpy are not required for production installations, only for development. Use of a virtual environment is strongly recommended.

$ virtualenv .
$ source bin/activate
(env)$ pip install -r requirements-dev.txt
(env)$ pip install -e .

We use py.test to run Shapely's suite of unittests and doctests.

(env)$ python -m pytest

Support

Questions about using Shapely may be asked on the GIS StackExchange using the "shapely" tag.

Bugs may be reported at https://github.com/Toblerity/Shapely/issues.