'How to create a graph from German OSM data with OSMnx efficiently?
I am currently working on a dataset with German postal codes. I aim to calculate "real" distances between the centers of each postal code area. To do so, I first downloaded the germany-latest.osm.bz2 file from geofabrik. Next I would like to create a graph from the downloaded file for the network_type = "driving".
However, I noticed that using the osmnx.graph.graph_from_xml() method is very time consuming for a large OMS file such as for Germany.
My questions are:
- How can I create the graph more efficiently?
- Once the graph has been created: how can I compute the "real" distances for a large set of origin-destination-pairs?
Thank you!
I am attaching my current code for reference:
import os
from pyrosm import OSM, get_data
import osmnx as ox
import networkx as nx
os.chdir(r"myPath")
xml = "germany-latest.osm.bz2"
graph = ox.graph.graph_from_xml(xml) #how to restrict to network_type = "driving"?
Solution 1:[1]
My suggestion is to download each country separately with https://download.geofabrik.de/europe/germany.html and save them to a PostGIS Database with osm2psgl (https://osm2pgsql.org/).
Setting up a PostGIS DB is done fast and working with osm2psgl is easier than it looks as well.
You can upload a bz2 File to your PostGIS DB from geofabrik with:
osm2pgsql bayern.osm.bz2 -d geodb -U USERNAME -W -H localhost -P 5432 -S default.style --output-pgsql-schema=osm --prefix bayern
When it's uploaded to PostGIS you can use all the PostGIS SQL magic you need.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Phil |
