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.1.tar.gz
(7.1 kB
view hashes)
Built Distribution
Close
Hashes for esy_osm_shape-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0001b9f0c0966dc77beec800e55d9f588986931bd00d88c1f2fcb505533c154 |
|
MD5 | ca874c6ebb7a27904c71ce902cc2fb5b |
|
BLAKE2b-256 | e77cb507138cf19b7c2fe4daf4db7fe3fe852d77091f51bc87bcc81de13e7cc1 |