Low-level interface to OpenStreetMap protocol buffer files.
The OpenStreetMap PBF format defines three primary data types:
- Node: An annotated point on the earth.
- Way: An list of Node items forming a path or polygon.
- Relation: A set of related entries.
This library uses Google’s protobuf Python implementation to decode binary data into native Python objects and offers a convenient interface to iterate over all elements found in a .pbf data file.
What it provides:
- A pythonic way to work with .pbf data file entries.
- Conversion of lowlevel Protocol Buffer objects to Python objects like dictionaries and lists.
- An easy way to filter and process OpenStreetMap data with Python.
What it doesn’t provide:
- A mechanism to spatially query OpenStreetMap entries.
- Visualization of OpenStreetMap data.
esy.osm.pbf depends on a Python version of 3.5 or above as well as on the Google Protocol Buffers. Use pip to install esy.osm.pbf:
$ pip install esy-osm-pbf
The following example selects some entries from the Andorra .pbf provided by geofabrik. The entries contained in these files can be accessed using esy.osm.pbf.File objects.
Openstreetmap defines parks by a tag leisure with a value of park. Filter entries accordingly and store matching ones in a list parks:
>>> import esy.osm.pbf >>> osm = esy.osm.pbf.File('test/andorra.osm.pbf') >>> parks = [entry for entry in osm if entry.tags.get('leisure') == 'park'] >>> len(parks) 24
In this copy of the Andorra .pbf, there seem to be at least 24 parks. Lets select all with a name and show the first three of those:
>>> [entry.tags['name'] for entry in parks if 'name' in entry.tags][:3] ['Jardins de Juberri', 'Parc Central', 'Plaça Guillemó']
esy.osm.pbf is licensed under the GNU General Public License version 3.0.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for esy_osm_pbf-0.0.1-py3-none-any.whl