Thank you both for the very fast answers!
@SimonPoole Yes, given the coordinates of the polygon nodes would make it easy to calculate a bounding box. But osmium tags-filter just filters and extracts the nodes into a file, so I don't have direct access to the coordinates, only afterwards. I was hoping that there is a functionality that handles that for me.
@Jochen Topf If I filter the country map for the city relation, then the bounding box of the resulting OSM file still contains the values of the whole country and not that of the extracted relation.
So probably I can solve it that way:
- use libosmium to filter the data for the relation of the city
- extract all nodes of that relation
- determine min and max longitude and latitude coordinates to determine city bounding box
- use osmium-tool to extract the data within this bounding box
But unfortunately, I'm struggling to collect access the nodes of a relation in libosmium. I hope you can give me a hint.
I'm trying to use the following handler for that, but I'm stuck here:
class NamesHandler : public osmium::handler::Handler {
public:
static void relation(const osmium::Relation& relation)
{
osmium::TagsFilter filter { false };
filter.add_rule(true, "name", "Friedrichshafen");
if (!osmium::tags::match_any_of(relation.tags(), filter))
return;
for (const auto& member : relation.members()) {
const auto& object = member.get_object();
if (!object.is_compatible_to(osmium::item_type::node))
continue;
// TODO: convert osmium::OSMObject to osmium::Node to access the location function
}
}
};
int main()
{
NamesHandler names_handler;
osmium::io::Reader reader { "input.pbf", osmium::osm_entity_bits::relation };
osmium::apply(reader, names_handler);
}