Add 'to' and 'from' OSM Node Ids in the result of nearest webservice. #2548
This commit is contained in:
parent
e1149bd4b7
commit
493a9a1cb2
@ -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<std::uint64_t>(SPECIAL_OSM_NODEID);
|
||||
std::uint64_t to_node = static_cast<std::uint64_t>(SPECIAL_OSM_NODEID);
|
||||
|
||||
std::vector<NodeID> 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<std::uint64_t>(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<NodeID> geometry =
|
||||
facade.GetUncompressedForwardGeometry(geometry_id);
|
||||
auto osm_node_id = facade.GetOSMNodeIDOfNode(
|
||||
geometry[phantom_node.fwd_segment_position + 1]);
|
||||
from_node = static_cast<std::uint64_t>(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<std::uint64_t>(osm_node_id);
|
||||
}
|
||||
nodes.values.push_back(from_node);
|
||||
nodes.values.push_back(to_node);
|
||||
waypoint.values["nodes"] = std::move(nodes);
|
||||
|
||||
return waypoint;
|
||||
});
|
||||
|
||||
|
@ -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<json::Number>().value;
|
||||
BOOST_CHECK_LT(distance, 20);
|
||||
|
||||
const auto &nodes = waypoint_object.values.at("nodes").get<json::Array>().values;
|
||||
BOOST_CHECK(nodes.size() == 2);
|
||||
BOOST_CHECK(nodes[0].get<util::json::Number>().value !=
|
||||
static_cast<std::uint64_t>(SPECIAL_OSM_NODEID));
|
||||
BOOST_CHECK(nodes[1].get<util::json::Number>().value !=
|
||||
static_cast<std::uint64_t>(SPECIAL_OSM_NODEID));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user