Skip to main content

Convert OpenStreetMap objects to shapely objects.

Project description


esy.osm.shape is a Python library to convert OpenStreetMap primitives to shapely objects.


The following examples operate on a historic dataset for Andorra from geofabrik. Let's download the dataset first:

>>> import urllib.request
>>> filename, headers = urllib.request.urlretrieve(
...     '',
...     filename='andorra.osm.pbf'
... )

Open the file and generate linestrings for each highway OpenStreetMap entry.

>>> import shapely, esy.osm.shape
>>> shape = esy.osm.shape.Shape('andorra.osm.pbf')
>>> highways = [
...     obj for obj in shape(lambda e: e.tags.get('highway') is not None)
...     if type(obj) is shapely.geometry.LineString
... ]

Using shapely objects it is also easy to compute geometric properties, like for example the length of the highways (note that the unit of this length is in longitude and latitude):

>>> sum(linestring.length for linestring in highways)

For slightly more details, jump to the documentation.

Project details

Download files

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

Files for esy-osm-shape, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size esy_osm_shape-0.0.3-py3-none-any.whl (6.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size esy-osm-shape-0.0.3.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page