Skip to main content

Low-level interface to OpenStreetMap protocol buffer files.

Project description

esy.osm.pbf is a low-level Python library to interact with OpenStreetMap data files in the Protocol Buffers language.

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.

Features

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.

Installation

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

Example

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ó']

License

esy.osm.pbf is licensed under the GNU General Public License version 3.0.

The Team

esy.osm.pbf is developed at the DLR Institute of Networked Energy Systems in the departement for Energy Systems Analysis (ESY).

Project details


Release history Release notifications

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-pbf, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size esy_osm_pbf-0.0.1-py3-none-any.whl (10.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size esy-osm-pbf-0.0.1.tar.gz (11.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page