How to extract street graph or network from OpenStreetMap ?
-
Have you looked at the osmium tool? https://osmcode.org/osmium-tool/ – ravenspoint Sep 14 '21 at 14:17
1 Answers
Solutions:
There are many solutions to achieve this goal, I listed some of them below.
- Overpass-api
Overpass-api & overpass-turbo let you use overpass query language to collect ways and nodes of type highway for a city :
[out:xml]; area[name = "Pantin"]; (way(area)[highway]; ); (._;>;); out;
- Geofabrik & Osmium
Geofabrik allows you to download various datasets from continents to cities.
Next, extract nodes and ways of type highway using Osmium tag-filters:
osmium tags-filter map.osm w/highway -o highways-ways.osm
NOTE: osmium tags-filter also works with .pbf files
- Ophois
Ophois is a CLI tool written in Rust, i created to:
- Download a map from overpass-api
- Process data from Overpass or Geofabrik to extract the street graph
- Simplify the extracted graph with detailed heuristics
- Discretize the extracted or simplified graph to a distance in meter
I also created a simple tool to display the generated graph on a Leaflet map to check the simplification process, cartographe.
Cartographe let you check the node id and the distance of links in meters using haversine formula.
Extracted
Simplified
Simplified and Discretized
NOTE: Simplified and discretized with 10 meters parameter
- OSMnx
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.
NOTE: Pantin using OSMnx

- 474
- 5
- 13
-
1AWESOME! I want to add other three options, 1. [osm2pgrouting](https://github.com/pgRouting/osm2pgrouting) 2. [osm2po](http://osm2po.de/) 3. [osm4routing2](https://github.com/Tristramg/osm4routing2) – kangkang Feb 27 '23 at 19:17
-
I am also wondering if you could use any of these tools for big graph extraction, eg, for the whole planet. – kangkang Feb 27 '23 at 19:23
-
@kangkang When I composed [ophois](https://github.com/ethicnology/ophois), I designed it to process streams of data so it can perform big graphs. You can download datasets of big regions [here](http://download.geofabrik.de/). For the whole earth you should concatenate and maybe pre-process these datasets – ethicnology Feb 28 '23 at 08:22