1

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:

  1. How can I create the graph more efficiently?
  2. 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"?
SpoJa92
  • 11
  • 1

1 Answers1

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.

Phil
  • 624
  • 7
  • 19
  • I am new to postGIS and have had a look around in its documentation, but could you explain or point me to an explanation on how I could use the PostGIS sql to reduce the original osm file to the driving network only? I'm face with the same issue as the OP but with the UK – Saleem Khan May 03 '22 at 00:30
  • 1
    yea sure! SELECT * FROM uk_line WHERE highway = "path" AND WHERE highway = "residential" ... and so on you d have to add all tags relevant to you here. uk_line is the table name of the line geometries of roads, paths and footwalks when you use osm2pgsql – Phil May 03 '22 at 05:56
  • 1
    thankyou very much. this points me in the right direction for the same use case as the OP – Saleem Khan May 03 '22 at 13:43