From 493a9a1cb2f56eac08f4949ec952613751cd51a6 Mon Sep 17 00:00:00 2001 From: David Audrain Date: Wed, 23 Aug 2017 14:20:06 -0400 Subject: [PATCH] Add 'to' and 'from' OSM Node Ids in the result of nearest webservice. #2548 --- include/engine/api/nearest_api.hpp | 43 +++++++++++++++++++++++++++++- unit_tests/library/nearest.cpp | 7 +++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/include/engine/api/nearest_api.hpp b/include/engine/api/nearest_api.hpp index c0c2c8077..841a3bf02 100644 --- a/include/engine/api/nearest_api.hpp +++ b/include/engine/api/nearest_api.hpp @@ -38,8 +38,49 @@ class NearestAPI final : public BaseAPI phantom_nodes.front().end(), waypoints.values.begin(), [this](const PhantomNodeWithDistance &phantom_with_distance) { - auto waypoint = MakeWaypoint(phantom_with_distance.phantom_node); + auto &phantom_node = phantom_with_distance.phantom_node; + auto waypoint = MakeWaypoint(phantom_node); waypoint.values["distance"] = phantom_with_distance.distance; + + util::json::Array nodes; + + std::uint64_t from_node = static_cast(SPECIAL_OSM_NODEID); + std::uint64_t to_node = static_cast(SPECIAL_OSM_NODEID); + + std::vector forward_geometry; + if (phantom_node.forward_segment_id.enabled ) + { + auto segment_id = phantom_node.forward_segment_id.id; + const auto geometry_id = facade.GetGeometryIndex(segment_id).id; + forward_geometry = + facade.GetUncompressedForwardGeometry(geometry_id); + + auto osm_node_id = facade.GetOSMNodeIDOfNode( + forward_geometry[phantom_node.fwd_segment_position]); + to_node = static_cast(osm_node_id); + } + + if (phantom_node.reverse_segment_id.enabled) + { + auto segment_id = phantom_node.reverse_segment_id.id; + const auto geometry_id = facade.GetGeometryIndex(segment_id).id; + std::vector geometry = + facade.GetUncompressedForwardGeometry(geometry_id); + auto osm_node_id = facade.GetOSMNodeIDOfNode( + geometry[phantom_node.fwd_segment_position + 1]); + from_node = static_cast(osm_node_id); + } + else if (phantom_node.forward_segment_id.enabled && phantom_node.fwd_segment_position > 0) + { + // In the case of one way, rely on forward segment only + auto osm_node_id = facade.GetOSMNodeIDOfNode( + forward_geometry[phantom_node.fwd_segment_position - 1]); + from_node = static_cast(osm_node_id); + } + nodes.values.push_back(from_node); + nodes.values.push_back(to_node); + waypoint.values["nodes"] = std::move(nodes); + return waypoint; }); diff --git a/unit_tests/library/nearest.cpp b/unit_tests/library/nearest.cpp index 7e3b89f47..a1b6f669d 100644 --- a/unit_tests/library/nearest.cpp +++ b/unit_tests/library/nearest.cpp @@ -105,6 +105,13 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component) // Nearest service should snap to road network without considering components. const auto distance = waypoint_object.values.at("distance").get().value; BOOST_CHECK_LT(distance, 20); + + const auto &nodes = waypoint_object.values.at("nodes").get().values; + BOOST_CHECK(nodes.size() == 2); + BOOST_CHECK(nodes[0].get().value != + static_cast(SPECIAL_OSM_NODEID)); + BOOST_CHECK(nodes[1].get().value != + static_cast(SPECIAL_OSM_NODEID)); } }