-
Notifications
You must be signed in to change notification settings - Fork 860
Add pbf module to load graphs from OSM PBF files #1338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 Sentry. 🚀 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! |
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.