Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1338 +/- ##
==========================================
- Coverage 98.57% 96.28% -2.29%
==========================================
Files 25 26 +1
Lines 2591 2666 +75
==========================================
+ Hits 2554 2567 +13
- Misses 37 99 +62 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This is an impressive progress, thanks for working on this feature! I ran the feature locally, loading a sample Chicago metro osm .pbf, which takes about ~2.8 min. I also test for projection and routing, also works as expected! import osmnx as ox
import time
ox.__version__
'2.1.0.dev0'
start_time = time.time()
filepath='inputdata/osm_Chicago.pbf'
G = ox.pbf.graph_from_pbf(filepath, simplify=True)
print(f"Total processing time: {time.time() - start_time:.2f} seconds")
Total processing time: 170.85 secondsQuick thoughts/questions on data filtering, the |
|
Thanks again for your work on this @gboeing --- I agree with @shiqin-liu that capacity to use a custom filter definition (or preset typology) would be really useful. In the code @shiqin-liu linked to, we actually use a custom filter (a couple of lines above the network type), that modifies the definition to remove the cycling restriction (defined here): So, basically, having options like currently exist for I installed this branch using UV, but it didn't seem to install the osmium module successfully by itself, I had to separately uv pip install this on my side. Not sure if that's relevant (it might be an issue on my side) but just mentioning in case there is something to be done flagging osmium as a dependency. I also had an issue when I tried using this with our example Las Palmas pbf from the I tried with on online Las Palmas excerpt from OpenStreetMap.fr. The example in our study (3.1MB) is a bespoke clipped version, but I would have expected a more or less official excerpt to work, but it had a similar failure: So using clipped pbfs might cause some issues, even when sourced from online re-publishers of OSM excerpts. Its good that it reports the issues, although, rather than failing, it could be convenient if there were a way this could work and just warn the user about potential for 'edge cases' where missing nodes on edges near the study region boundary could not be resolved, possibly due to data clipping issues. (and still return the graph object for use, with that caveat). I'll aim to look into this more tomorrow (eg if its possible to operationalise a custom pedestrian definition using the current functionality), but wanted to share this early feedback. Thanks again for exploring this possibility --- it will be a very useful functionality! |
|
I stumbled upon this while I was looking into availability of the public Overpass server instances and reading #1377. Is loading from PBF still a path that you are pursuing? If yes, I may be able to contribute to the filtering logic. I have worked with Overpass in Python a fair amount and am also the maintainer of https://codeberg.org/mvexel/overpass-api-python-wrapper. As a first step, supporting the existing |
|
@mvexel yes, this PR fell by the wayside a few months back, but it includes a simple working version of PBF loading functionality already. The filtering logic presents an interesting problem... osmium makes it a bit tricky to do normal OSMnx-style However, I think the normal |
|
I was thinking in the direction of abstracting the filter definitions from the PBF / Overpass readers. There would be a If this sounds like something you would consider, I can work on a minimal example to start. |
|
Sounds like a potentially good approach. Sure I'd be happy to review a PR. |
|
This is great! I've installed it in my conda environment by adding the following to the environment.yml: ...
- pip
- pip:
- osmnx @ git+https://github.com/gboeing/osmnx.git@pbf
- osmiumI could then load the .pbf file for the Netherlands from Geofabrik (~1 GB) and extract and plot highways: Loading took 88 seconds: tags = {"highway": ["motorway", "motorway_link", "trunk", "trunk_link", "primary", "secondary"]}
G = graph_from_pbf(filepath, tags)Reprojecting and plotting took 8 seconds: Gp = ox.projection.project_graph(G)
gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(Gp)
fig, ax = ox.plot.plot_graph(Gp, node_size=2)
I hope this can be merged soon, such that it's easier to install. If there is any specific functionality I can test, let me know, I'll do my best to help! |
|
Hi, just adding that I am also very much interested in this, as the overpass api is under heavy strain and fails too much, so this is really a good and needed approach.
Same! |
|
Thanks all for the feedback. Yes I'm happy to pick this back again in the coming days. The main issue is designing a good system for filtering. Overpass and PBF need very different filtering logic. Either they're used differently by users, or we need to do major work abstracting things. |

This PR proposes a new module to read data from PBF files. It uses the
osmiumlibrary to read PBF data and provides a familiargraph_from_pbffunction for users. This is much faster than using the Overpass API and allows users to download data extracts locally for loading.Initially I felt like we shouldn't provide any data filtering, and just load whatever data is in the user's desired PBF file. But we can maybe provide some simple built in filtering, with the expectation that the user who needs richer filtering should just pre-filter their PBF file as they wish.
Here's a simple usage example, using Geofabrik's DC extract:
Or you can load the state of Oregon's highway network in ~8 seconds:
Or you can load all of Australia's highway network in ~45 seconds:
More simple filtering examples:
I've tested projection, plotting, converting, etc and all seems to work fine with the graphs we've created from the PBF files.
You can also create a graph from Overpass with OSMnx, save to an OSM XML file, convert that to a PBF file, then load it back into OSMnx (as proof of concept only... this isn't a good workflow):
Any comments, feedback, or testing would be much appreciated.