Package: pyrosm
PyrosmPyrosmis a Python library for reading OpenStreetMap data from Protocolbuffer Binary Format -files (*.osm.pbf) into Geopandas GeoDataFrames.
Pyrosm makes it easy to extract various datasets from OpenStreetMap pbf-dumps including e.g. road networks, buildings,
Points of Interest (POI), landuse and natural elements. Also fully customized queries are supported which makes it possible
to parse the data from OSM with more specific filters.Pyrosmis easy to use and it provides a somewhat similar user interface asOSMnx.
The main difference between pyrosm and OSMnx is that OSMnx reads the data over internet using OverPass API, whereas pyrosm reads the data from local OSM data dumps
that can be downloaded e.g. fromGeoFabrik's website. This makes it possible to read data faster thus
allowing e.g. parsing street networks for the whole country fairly efficiently (however, seecaveats).The library has been developed by keeping performance in mind, hence, it is mainly written in Cython (Python with C-like performance)
which makes it fast to parse OpenStreetMap data from PBF files.
Pyrosm is built on top of another Cython library calledPyrobufwhich is a faster Cython alternative
to Google's Protobuf library: It provides 2-4x boost in performance for deserializing the protocol buffer messages compared to
Google's version with C++ backend. Google's Protocol Buffers is a commonly used and efficient method to serialize and compress structured data
which is also used by OpenStreetMap contributors to distribute the OSM data in PBF format (Protocolbuffer Binary Format).Documentationis available athttps://pyrosm.readthedocs.io.Current featuresdownload PBF data easily from hundreds of locations across the worldread street networks (separately for driving, cycling, walking and all-combined)read buildings from PBFread Points of Interest (POI) from PBFread landuse from PBFread "natural" from PBFread boundaries from PBF (+ allow searching by name)read any other data from PBF by using a custom user-defined filterfilter data based on bounding boxexport networks as a directed graph toigraph,networkxandpandanaInstallPyrosm is distributed via PyPi and conda-forge.The recommended way to install pyrosm is usingcondapackage manager:$ conda install -c conda-forge pyrosmYou can also install the package with pip:$ pip install pyrosmTroubleshootingNotice thatpyrosmrequires geopandas to work.
On Linux and Mac installing geopandas withpipshould work without a problem, which is handled automatically when installing pyrosm.However, on Windows installing geopandas with pip is likely to cause issues, hence, it is recommended to install Geopandas before installingpyrosm. See instructions fromGeopandas website.When should I use Pyrosm?Pyrosm can of course be used whenever you need to parse data from OSM into geopandas GeoDataFrames.
However,pyrosmis better suited for situations where you want to fetch data for whole city or larger regions (even whole country).If you are interested to fetch OSM data for smaller areas such as neighborhoods, or search data around a specific location/address,
we recommend usingOSMnxwhich is more flexible in terms of specifying the area of interest.
That being said, it is also possible to extract neighborhood level information with pyrosm and filter data based on a bounding box
(seedocs).How to use?Usingpyrosmis straightforward. Seedocsfor instructions how to use the library.Get in touch + contributionsIf you find a bug from the tool, have question, or would like to suggest a new feature to it, you canmake a new issue here.We warmly welcome contributions topyrosmto make it better. If you are interested in contributing to the library,
please check thecontribution guidelines.DevelopmentYou can install a local development version of the tool by 1) installing necessary packages with conda and 2) building pyrosm from source:install conda-environment for Python 3.12 by:Python 3.12 (you might want to modify the env-name which istestby default):$ conda env create -f ci/312-conda.yamlbuild pyrosm development version from master (activate the environment first):pip install -e .You can run tests withpytestby executing:$ pytest . -vLicense and copyrightPyrosm is licensed under MIT (seelicense).The OSM data is downloaded from two sources:Data ©Geofabrik GmbH,BBBikeandOpenStreetMap ContributorsAll data from theOpenStreetMapis licensed under theOpenStreetMap License.CaveatsFiltering large files by bounding boxAlthoughpyrosmprovides possibility to filter even larger data files based on bounding box,
this process can slow down the reading process significantly (1.5-3x longer) due to necessary lookups when parsing the data.
This might not be an issue with smaller files (up to ~100MB) but with larger data dumps this can take longer than necessary.Hence, a recommended approach with large data files is tofirstfilter the protobuf file based on bounding box into a
smaller subset by using a dedicated open source Java tool calledOsmosiswhich is available for all operating systems. Detailed installation instructions arehere,
and instructions how to filter data based on bounding box arehere.