Repository navigation
[GSoC] Pedestrian area routing: Detect areas during parsing - #6127
Conversation
| if (kv["type"] == "multipolygon" and kv["highway"] == "pedestrian" and kv["area"] == "yes") then | ||
| return 0, kv | ||
| end | ||
|
|
There was a problem hiding this comment.
the function rels_proc only preserved a few relations and everything else was discarded. I have made pedestrian multipolygon and their tags survive the lua and reach for the pbfgraphparser
| tag_handlers_["pedestrian_area"] = [this]() { | ||
| way_.set_area(tag_.second == "true" ? true : false); | ||
| }; |
There was a problem hiding this comment.
This is the tag handler that marks, in the osmway.h the area_ bit, indicating we are dealing with a pedestrian area. Which only happens, as indicated in the review comment in graph.lua, for ways tagged with both highway=pedestrian and area=yes
There was a problem hiding this comment.
since pedestrian_area is a tag chosen by you, and you never set it to anything but "true" in graph.lua, you can just set it to true here to avoid confusion:
| tag_handlers_["pedestrian_area"] = [this]() { | |
| way_.set_area(tag_.second == "true" ? true : false); | |
| }; | |
| tag_handlers_["pedestrian_area"] = [this]() { | |
| if (pedestrian_areas_) { | |
| way_.set_area(true); | |
| } | |
| }; |
| uint64_t from_way_id = 0; | ||
| bool isRestriction = false, isTypeRestriction = false, hasRestriction = false; | ||
| bool isRoad = false, isRoute = false, isBicycle = false, isConnectivity = false; | ||
| bool isMultipolygon = false, isPedestrian = false, isArea = false; |
There was a problem hiding this comment.
Flags to identify pedestrian multipolygon areas, following a pretty similar pattern as the existing for bike relations
| } else if (tag.second == "multipolygon") { | ||
| isMultipolygon = true; |
There was a problem hiding this comment.
Extends the type tag handler to also catch mutipolygon
| } else if (tag.first == "highway") { | ||
| if (tag.second == "pedestrian") { | ||
| isPedestrian = true; | ||
| } | ||
| } else if (tag.first == "area") { | ||
| if (tag.second == "yes") { | ||
| isArea = true; | ||
| } |
There was a problem hiding this comment.
These tags weren't read anywhere, we need them to identify the areas
| } else if (isMultipolygon && isPedestrian && isArea) { | ||
| for (const auto& member : members) { | ||
| OSMArea area; | ||
| if (member.role == "outer" && member.member_type == osmium::item_type::way) { | ||
| area.is_outer = true; | ||
| area.way_id = member.member_id; | ||
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area)); | ||
| } else if (member.role == "inner" && member.member_type == osmium::item_type::way) { | ||
| area.is_outer = false; | ||
| area.way_id = member.member_id; | ||
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area)); | ||
| } | ||
| } |
There was a problem hiding this comment.
The relations we are looking for are none of the other types and they might be multipolygons, pedestrians and areas. This is where we iterate over the relation members to separate outer and inner ways and fill area_relations
| // OSM area data (stored within OSMData) | ||
| struct OSMArea { | ||
| uint64_t way_id; | ||
| bool is_outer; | ||
| }; | ||
|
|
There was a problem hiding this comment.
This struct represents a member way of a pedestrian multipolygon area, where we store its id and whether it is an outer or inner ring
| using ViaSet = std::unordered_set<uint64_t>; | ||
| using AccessRestrictionsMultiMap = std::unordered_multimap<uint64_t, OSMAccessRestriction>; | ||
| using BikeMultiMap = std::unordered_multimap<uint64_t, OSMBike>; | ||
| using AreaMultiMap = std::unordered_multimap<uint64_t, OSMArea>; |
There was a problem hiding this comment.
A multimap indexed by relation id, so all member ways of one area can be retrieved together
| /** | ||
| * Sets the area flag. | ||
| * @param area Is this an area? | ||
| */ | ||
| void set_area(const bool area) { | ||
| area_ = area; | ||
| } | ||
|
|
||
| /** | ||
| * Get the area flag. | ||
| * @return Returns area flag. | ||
| */ | ||
| bool area() const { | ||
| return area_; | ||
| } | ||
|
|
There was a problem hiding this comment.
Getter and setter for area_bit
| uint16_t area_ : 1; | ||
| uint16_t spare2_ : 1; |
There was a problem hiding this comment.
Save 1 bit to identify pedestrian areas
| // If the way is part of an area, make sure it does not generate edges | ||
| if (way.area()) { | ||
| current_way_node_index = last_way_node_index + 1; | ||
| continue; | ||
| } | ||
|
|
There was a problem hiding this comment.
Skip area ways so we don't generate edges, because we don't want to route along the perimeter of an area. We still store them but keep them out of the graph
There was a problem hiding this comment.
removed the config option flag check, is not necessary, because the area_bit works as the flag itself
There was a problem hiding this comment.
Gurka test file for area routing. The only test currently checks that
the perimeter of a pedestrian area does not generate edges (even though
we are collecting its ways), and that routing around the area works as
expected (currently is unimplemented so it goes around) .
There was a problem hiding this comment.
IMO it's fine to open a new test file for this.
don't forget that you can make use of #6136. you can test things for real on temp files, gurka graphs aren't very useful at this point.
There was a problem hiding this comment.
I didn't realise that #6136 was already merged. I'll make use of it then!
| } else if (isMultipolygon && isPedestrian && isArea && pedestrian_areas_) { | ||
| for (const auto& member : members) { | ||
| OSMAreaMember area_member; | ||
| if (member.role == "outer" && member.member_type == osmium::item_type::way) { | ||
| area_member.is_outer = true; | ||
| area_member.way_id = member.member_id; | ||
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area_member)); | ||
| } else if (member.role == "inner" && member.member_type == osmium::item_type::way) { | ||
| area_member.is_outer = false; | ||
| area_member.way_id = member.member_id; | ||
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area_member)); | ||
| } | ||
| } |
There was a problem hiding this comment.
The relations we are looking for are none of the other types and they might be multipolygons, pedestrians and areas. This is where we iterate over the relation members to separate outer and inner ways and fill area_relations. Disabled as default with pedestrian_areas_ config flag
There was a problem hiding this comment.
Added the new config option to valhalla_build_config with its default
value (false) and help text
| struct AreaRelation { | ||
| uint64_t relation_id; | ||
| OSMAreaMember area_member; | ||
| AreaRelation() : relation_id(0), area_member(OSMAreaMember()) { | ||
| } | ||
| AreaRelation(uint64_t r, const OSMAreaMember& m) : relation_id(r), area_member(m) { | ||
| } | ||
| }; | ||
|
|
There was a problem hiding this comment.
Helper struct to serialize/deserialize the area relations multimap, follows a similar pattern as the existing BikeRelation struct.
chrstnbwnkl
left a comment
There was a problem hiding this comment.
I think this is good so far! I've made some suggestions on simplifying parts of the code a little, but none of those change the logic in any way.
The next step will probably be parsing the ways to get the ones we care about. Think about the parsing order again: if it's possible to parse ways before relations without breaking anything, that could save us a second pass over the ways.
| tag_handlers_["pedestrian_area"] = [this]() { | ||
| way_.set_area(tag_.second == "true" ? true : false); | ||
| }; |
There was a problem hiding this comment.
since pedestrian_area is a tag chosen by you, and you never set it to anything but "true" in graph.lua, you can just set it to true here to avoid confusion:
| tag_handlers_["pedestrian_area"] = [this]() { | |
| way_.set_area(tag_.second == "true" ? true : false); | |
| }; | |
| tag_handlers_["pedestrian_area"] = [this]() { | |
| if (pedestrian_areas_) { | |
| way_.set_area(true); | |
| } | |
| }; |
| } else if (tag.first == "highway") { | ||
| if (tag.second == "pedestrian") { | ||
| isPedestrian = true; | ||
| } |
There was a problem hiding this comment.
| } else if (tag.first == "highway") { | |
| if (tag.second == "pedestrian") { | |
| isPedestrian = true; | |
| } | |
| } else if (tag.first == "highway" && tag.second == "pedestrian") { | |
| isPedestrian = true; |
We don't currently care about any other highway tag combo, so this can be simplified
| } else if (tag.first == "area") { | ||
| if (tag.second == "yes") { | ||
| isArea = true; | ||
| } |
There was a problem hiding this comment.
| } else if (tag.first == "area") { | |
| if (tag.second == "yes") { | |
| isArea = true; | |
| } | |
| } else if (tag.first == "area" && tag.second == "yes") { | |
| isArea = true; |
same here, can be simplified
| OSMAreaMember area_member; | ||
| if (member.role == "outer" && member.member_type == osmium::item_type::way) { | ||
| area_member.is_outer = true; | ||
| area_member.way_id = member.member_id; | ||
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area_member)); | ||
| } else if (member.role == "inner" && member.member_type == osmium::item_type::way) { | ||
| area_member.is_outer = false; | ||
| area_member.way_id = member.member_id; | ||
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area_member)); | ||
| } |
There was a problem hiding this comment.
This could also be simplified a little:
| OSMAreaMember area_member; | |
| if (member.role == "outer" && member.member_type == osmium::item_type::way) { | |
| area_member.is_outer = true; | |
| area_member.way_id = member.member_id; | |
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area_member)); | |
| } else if (member.role == "inner" && member.member_type == osmium::item_type::way) { | |
| area_member.is_outer = false; | |
| area_member.way_id = member.member_id; | |
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area_member)); | |
| } | |
| if ((member.role == "outer" || member.role == "inner") && | |
| member.member_type == osmium::item_type::way) { | |
| OSMAreaMember area_member{.way_id = member.member_id, .is_outer = member.role == "outer"}; | |
| osmdata_.area_relations.insert(AreaMultiMap::value_type(osmid, area_member)); | |
| } |
|
Oops looks like clang-tidy is complaining |
|
Some of the tests operating on real world tiles (Utrecht, Paris, etc.) are failing. I assume this PR includes area ways with |
chrstnbwnkl
left a comment
There was a problem hiding this comment.
Looks like there's one more test failing; in test/graphbuilder we construct an OSMData instance manually, so you need to brace initialize area_relations just like the other ones:
diff --git a/test/graphbuilder.cc b/test/graphbuilder.cc
index d8da9da17..8e0388b16 100644
--- a/test/graphbuilder.cc
+++ b/test/graphbuilder.cc
@@ -62,6 +62,7 @@ TEST(GraphBuilder, TestConstructEdges) {
{}, /* via_set */
{}, /* access_restrictions */
{}, /* bike_relations */
+ {}, /* area_relations */
{}, /* way_ref */
{}, /* way_ref_rev */
{}, /* node_names */
Background
First step toward area routing is to detect pedestrian areas (
highway=pedestrianandarea=yes) during tile building, both as ways and multipolygon relations.Changes I have made
Results
Tested on Murcia, Spain extract: