topobyte / osm4j

Library and tools for working with OpenStreetMap data and APIs
https://jaryard.com/projects/osm4j/
47 stars 7 forks source link

Question: Get all nodes within a bounding box #14

Open betsch85 opened 1 year ago

betsch85 commented 1 year ago

While reading through the docs a few days ago I thought I saw a function to query all nodes within a bounding box, and now, for the life of me, I can't seem to find it. But maybe I misremembered, is there such a function?

i.e. instead of having a data file for city 1 through N I want a to load a PBF from a whole country and then query different bounding boxes for cities 1 through N

sebkur commented 1 year ago

Maybe you we're looking at https://jaryard.com/projects/osm4j/tutorial/cli-reference.html before.

There's the CLI utility OsmBboxFilter that you can install from the utils module using ./install.sh and that offers functionality for extracting bbox data from bigger data sets.

You can also run your data extraction in code and use a BboxFilter to filter your data.

Depending on what you do, it might also be more efficient to build an extraction data structure from you country data file and run bbox queries on that file-based extraction data structure. That is documented here: https://github.com/topobyte/osm4j/tree/master/extra

The run times given there are for the huge planet file. For country files that process is a lot faster (but it won't return data with 100% integrity because the country extracts from Geofabrik are already missing some ways and nodes). In addition to OsmExtraQueryRegion documented there, we also have OsmExtraQueryBbox for extracting rectangular areas.

sebkur commented 1 year ago

and of course if you're working with small cities where the Overpass API is an option, that's probably the quickest solution: https://jaryard.com/projects/osm4j/tutorial/rendering-a-map.html

betsch85 commented 1 year ago

Maybe you we're looking at https://jaryard.com/projects/osm4j/tutorial/cli-reference.html before.

There's the CLI utility OsmBboxFilter that you can install from the utils module using ./install.sh and that offers functionality for extracting bbox data from bigger data sets.

You can also run your data extraction in code and use a BboxFilter to filter your data.

Depending on what you do, it might also be more efficient to build an extraction data structure from you country data file and run bbox queries on that file-based extraction data structure. That is documented here: https://github.com/topobyte/osm4j/tree/master/extra

The run times given there are for the huge planet file. For country files that process is a lot faster (but it won't return data with 100% integrity because the country extracts from Geofabrik are already missing some ways and nodes). In addition to OsmExtraQueryRegion documented there, we also have OsmExtraQueryBbox for extracting rectangular areas.

Thanks!

and of course if you're working with small cities where the Overpass API is an option, that's probably the quickest solution: https://jaryard.com/projects/osm4j/tutorial/rendering-a-map.html

Yes I'm planning to do that for the initial data, but I don't want to query the API again for a subset of the data I already have in memory, that seems like a waste of time