by wcedmisten · 2y ago · 0 comments
For example, it's simple to count the cafes in North America in under 30s:
SELECT COUNT(*) FROM st_readOSM('/home/wcedmisten/Downloads/north-america-latest.osm.pbf') WHERE tags['amenity'] = ['cafe'];
┌──────────────┐
│ count_star() │
│ int64 │
├──────────────┤
│ 57150 │
└──────────────┘
Run Time (s): real 24.643 user 379.067204 sys 3.696217
Unfortunately, I discovered there are still some bugs [2] that need to be ironed out, but it seems very promising for doing high performance queries with minimal effort.[1]: https://duckdb.org/docs/extensions/spatial.html#st_readosm--...
Can I ask where you get official OSM PBF data from? (I found these two links, but not sure what data these contain)
The first one is the official OpenStreetMap data, which contains the "planet file" - i.e. all the data for the entire world. But because OSM has so much stuff in it, the planet file is a whopping 76 GB, which can take a long time to process for most tasks. I also recommend using the torrent file for faster download speeds.
As a result of the planet's size, the German company Geofabrik provides unofficial "extracts" of the data, which are filtered down to a specific region. E.g. all the data in a particular continent, country, or U.S. state. If you click on the "Sub Region" link it will show countries, and if you click on those it will show states.
SELECT
tags['addr:city'][1] city,
tags['addr:state'][1] state,
tags['brand'][1] brand,
*,
FROM st_readosm('us-latest.osm.pbf')
WHERE 1=1
and city = 'Chicago'
and state = 'IL'
and brand = 'Whole Foods Market'
I'm sure there are ways to make this faster (partitioning, indexing, COPY TO native format, etc.) but querying a 9.8GB compressed raw format file with data (in key-value fields stored as strings) for the entire United States at this speed is pretty impressive to me.When I index the entire United States, admittedly with a subset of tags, I can search in milliseconds. I'll take it.
I appreciate your taking the time to share this tidbit! It's a game changer in what I do (geospatial).
You could certainly amortize this cost for repeated queries, but for one-off queries I haven't seen anything faster.
[1]: https://wiki.openstreetmap.org/wiki/Osm2pgsql/benchmarks