From charlesreid1

Shapely is a library for drawing shapes in Python.

Link: https://pypi.python.org/pypi/Shapely

Installing

Mac OS X

First install geos, to enable linking shapely with geographic libraries/coordinate systems:

$ brew install geos

==> Downloading https://homebrew.bintray.com/bottles/geos-3.6.1.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring geos-3.6.1.sierra.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
  mkdir -p /Users/charles/Library/Python/2.7/lib/python/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/charles/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary
🍺  /usr/local/Cellar/geos/3.6.1: 401 files, 7.2MB

Next, install shapely with Numpy add-ons to make it faster:

$ pip install shapely[vectorized]==1.6b2

Collecting shapely[vectorized]==1.6b2
  Downloading Shapely-1.6b2-cp27-cp27m-macosx_10_6_intel.whl (2.2MB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 2.2MB 263kB/s
Requirement already satisfied: numpy; extra == "vectorized" in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from shapely[vectorized]==1.6b2)
Installing collected packages: shapely
Successfully installed shapely-1.6b2

Using

To use, see documentation for basics: https://pypi.python.org/pypi/Shapely

Points

To create an approximately circular patch, start by creating a point where the patch will be centered. By setting the point coordinates, you set the patch location. By setting the buffer, you set the radius of the circular patch.

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

>>> from math import pi

>>> pi*10.0*10.0
314.1592653589793

The area of the patch is approximately , where r is the patch buffer size.

Dissolve

Intersect

Integrating with GiS Packages

To integrate Shapely with other Python GIS packages, you can load from and dump to JSON files.

>>> 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]}

Links

Shapely

Shapely github link: https://github.com/Toblerity/Shapely

Shapely tags on GIS stack overflow: https://gis.stackexchange.com/questions/tagged/shapely

Shapely with GIS

Interactive data visualization of Kaggle data set with Geojson, D3.js, DC.js, Leaflet: http://adilmoujahid.com/posts/2016/08/interactive-data-visualization-geospatial-d3-dc-leaflet-python/

Corresponding Github repo: https://github.com/adilmoujahid/kaggle-talkingdata-visualization

Maps and GIS with Python

Geopandas (extending Pandas datatypes to work with GIS data): https://github.com/geopandas/geopandas

(Basic) Python for Geo people from University of Helsinki: https://github.com/Python-for-geo-people/Course-information

(Advanced) Automating GIS course from University of Helsinki: https://automating-gis-processes.github.io/2016/index.html

Interactive maps with Bokeh: https://automating-gis-processes.github.io/2016/Lesson5-interactive-map-bokeh.html

Maps and GIS Generally

Geojson.io (geojson interactive map editor): http://geojson.io/#map=2/20.0/0.0

Flags