Skip to content

Commit

Permalink
Fix: Attemp to retrieve traffic signal information of nodes through t…
Browse files Browse the repository at this point in the history
…race_attribute request (valhalla#5121)
  • Loading branch information
MohamedM216 authored Feb 26, 2025
1 parent 1725be1 commit e949fe7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* CHANGED: Speed up pbf parsing by using libosmium [#5070](https://github.com/valhalla/valhalla/pull/5070)
* ADDED: headings and correlated ll's in verbose matrix output [#5072](https://github.com/valhalla/valhalla/pull/5072)
* CHANGED: Faster Docker builds in CI [#5082](https://github.com/valhalla/valhalla/pull/5082)
* ADDED: Retrieve traffic signal information of nodes through trace_attribute request [#5121](https://github.com/valhalla/valhalla/pull/5121)
* CHANGED: Remove redundant callback-style pbf parsing [5119](https://github.com/valhalla/valhalla/pull/5119)

## Release Date: 2024-10-10 Valhalla 3.5.1
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/api/map-matching/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ node.intersecting_edge.lane_count
node.elapsed_time
node.admin_index
node.type
node.traffic_signal
node.fork
node.time_zone
Expand Down Expand Up @@ -246,6 +247,7 @@ Each `end_node` may include:
| `elapsed_time` | Elapsed time of the path to arrive at this node. |
| `admin_index` | Index value in the admin list. |
| `type` | Node type values: <ul><li>`street_intersection`</li><li>`gate`</li><li>`bollard`</li><li>`toll_booth`</li><li>`multi_use_transit_stop`</li><li>`bike_share`</li><li>`parking`</li><li>`motor_way_junction`</li><li>`border_control`</li></ul> |
| `traffic_signal` | A boolean value indicating whether the node is a traffic signal (`true` or `false`) |
| `fork` | True if this node is a fork. |
| `time_zone` | Time zone string for this node. |

Expand Down
1 change: 1 addition & 0 deletions src/baldr/attributes_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const std::unordered_map<std::string, bool> AttributesController::kDefaultAttrib
{kNodeElapsedTime, true},
{kNodeAdminIndex, true},
{kNodeType, true},
{kNodeTrafficSignal, true},
{kNodeFork, true},
{kNodeTransitPlatformInfoType, true},
{kNodeTransitPlatformInfoOnestopId, true},
Expand Down
3 changes: 3 additions & 0 deletions src/tyr/trace_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ void serialize_edges(const AttributesController& controller,
if (controller(kNodeType)) {
writer("type", to_string(static_cast<baldr::NodeType>(node.type())));
}
if (controller(kNodeTrafficSignal)) {
writer("traffic_signal", static_cast<bool>(node.traffic_signal()));
}
if (controller(kNodeFork)) {
writer("fork", static_cast<bool>(node.fork()));
}
Expand Down
34 changes: 34 additions & 0 deletions test/gurka/test_trace_attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,37 @@ TEST(Standalone, InterpolatedPoints) {
ASSERT_EQ(result_doc["matched_points"][4]["edge_index"].GetInt(), 1);
ASSERT_EQ(result_doc["matched_points"][5]["edge_index"].GetInt(), 1);
}

TEST(Standalone, RetrieveTrafficSignal) {
const std::string ascii_map = R"(
A---B---C
|
D
)";

const gurka::ways ways = {{"AB", {{"highway", "primary"}}},
{"BC", {{"highway", "primary"}}},
{"BD", {{"highway", "primary"}}}};

const gurka::nodes nodes = {{"B", {{"highway", "traffic_signals"}}}};

const double gridsize = 10;
const auto layout = gurka::detail::map_to_coordinates(ascii_map, gridsize);
auto map = gurka::buildtiles(layout, ways, nodes, {}, "test/data/traffic_signal_attributes");

std::string trace_json;
auto api = gurka::do_action(valhalla::Options::trace_attributes, map, {"A", "B", "C"}, "auto", {},
{}, &trace_json, "via");

rapidjson::Document result;
result.Parse(trace_json.c_str());

auto edges = result["edges"].GetArray();
ASSERT_EQ(edges.Size(), 2);

EXPECT_TRUE(edges[0]["end_node"].HasMember("traffic_signal"));
EXPECT_TRUE(edges[0]["end_node"]["traffic_signal"].GetBool());

EXPECT_TRUE(edges[1]["end_node"].HasMember("traffic_signal"));
EXPECT_FALSE(edges[1]["end_node"]["traffic_signal"].GetBool());
}
1 change: 1 addition & 0 deletions valhalla/baldr/attributes_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const std::string kNodeIntersectingEdgeSignInfo = "node.intersecting_edge.sign_i
const std::string kNodeElapsedTime = "node.elapsed_time";
const std::string kNodeAdminIndex = "node.admin_index";
const std::string kNodeType = "node.type";
const std::string kNodeTrafficSignal = "node.traffic_signal";
const std::string kNodeFork = "node.fork";
const std::string kNodeTransitPlatformInfoType = "node.transit_platform_info.type";
const std::string kNodeTransitPlatformInfoOnestopId = "node.transit_platform_info.onestop_id";
Expand Down

0 comments on commit e949fe7

Please sign in to comment.