0

I have been using the Overpass API to extract data and this only provided the data back for the bounding box I requested, which was then fed into a chain of libosmium handlers.

I would like to replace the Overpass querying with a local country-scale PBF file and am trying to wrap my head around how best to do this. It seems that just checking if each node is within the bbox would be inefficient, but I am not familiar enough with osmium to come up with a better strategy.

My current snippet is:

osmium::area::AssemblerConfig assemblerConfig;
assemblerConfig.ignore_invalid_locations = true;
assemblerConfig.create_way_polygons = false; // These are handled as normal ways in the handler
assemblerConfig.create_empty_areas = true;
osmium::area::MultipolygonManager<osmium::area::Assembler> multipolygonManager{
        assemblerConfig
};

osm::DefaultNodeLocationsForWaysHandler n2wHandler;
n2wHandler.ignore_errors();

// SWNE bounding box
std::array<double,4> bounds{50.9065510, -1.4500237, 50.9517765, -1.3419628};

osmium::io::File f;

// Check if local file exists, if not then do an overpass api call and save to file
if (!std::filesystem::exists(std::string("/britain-and-ireland-latest.osm.pbf"))) {
    f = osmium::io::File{rawResponse(bounds)};
} else {
    f = osmium::io::File{std::string("/britain-and-ireland-latest.osm.pbf")};
    //TODO: Apply some logic here to only give results within a bounding box
}

read_relations(f, multipolygonManager);

// handlers is a parameter pack of osmium handlers passed in
osmium::io::Reader reader{f, osmium::osm_entity_bits::all};
osmium::apply(reader, n2wHandler, multipolygonManager.handler(),
              std::forward<THandlers>(handlers)...);
osmium::apply(multipolygonManager.buffer(), std::forward<THandlers>(handlers)...);

I've had a look at the source for osmium-tool extract command, but it doesn't look like it uses osmium handlers and again I am not familiar enough with osmium to understand the strategy pattern it applies.

Thanks in advance!

aliaksei
  • 714
  • 1
  • 9
  • 23

0 Answers0