Skip to main content

Convert OpenStreetMap objects to shapely objects.

Project description

esy-osm-shape

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

Usage

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(
...     'https://download.geofabrik.de/europe/andorra-190101.osm.pbf',
...     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)
16.952160743015657

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.

Source Distribution

esy-osm-shape-0.0.3.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

esy_osm_shape-0.0.3-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page