Recreate feature/expose_node_ids

This commit is contained in:
Lauren Budorick
2016-05-18 16:09:14 -04:00
committed by Daniel J. Hofmann
parent 448f8377fb
commit a4ac07866a
10 changed files with 59 additions and 0 deletions
+8
View File
@@ -198,6 +198,7 @@ class RouteAPI : public BaseAPI
{
util::json::Array durations;
util::json::Array distances;
util::json::Array nodes;
auto &leg_geometry = leg_geometries[idx];
std::for_each(
leg_geometry.annotations.begin(),
@@ -206,9 +207,16 @@ class RouteAPI : public BaseAPI
durations.values.push_back(step.duration);
distances.values.push_back(step.distance);
});
std::for_each(
leg_geometry.osm_node_ids.begin(),
leg_geometry.osm_node_ids.end(),
[this, &nodes](const OSMNodeID &node_id) {
nodes.values.push_back(static_cast<std::uint64_t>(node_id));
});
util::json::Object annotation;
annotation.values["distance"] = std::move(distances);
annotation.values["duration"] = std::move(durations);
annotation.values["nodes"] = std::move(nodes);
annotations.push_back(std::move(annotation));
}
}
@@ -67,6 +67,7 @@ class BaseDataFacade
// node and edge information access
virtual util::Coordinate GetCoordinateOfNode(const unsigned id) const = 0;
virtual OSMNodeID GetOSMNodeIDOfNode(const unsigned id) const = 0;
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0;
@@ -73,6 +73,7 @@ class InternalDataFacade final : public BaseDataFacade
std::string m_timestamp;
util::ShM<util::Coordinate, false>::vector m_coordinate_list;
util::ShM<OSMNodeID, false>::vector m_osmnodeid_list;
util::ShM<NodeID, false>::vector m_via_node_list;
util::ShM<unsigned, false>::vector m_name_ID_list;
util::ShM<extractor::guidance::TurnInstruction, false>::vector m_turn_instruction_list;
@@ -156,10 +157,12 @@ class InternalDataFacade final : public BaseDataFacade
unsigned number_of_coordinates = 0;
nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned));
m_coordinate_list.resize(number_of_coordinates);
m_osmnodeid_list.resize(number_of_coordinates);
for (unsigned i = 0; i < number_of_coordinates; ++i)
{
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode));
m_coordinate_list[i] = util::Coordinate(current_node.lon, current_node.lat);
m_osmnodeid_list[i] = current_node.node_id;
BOOST_ASSERT(m_coordinate_list[i].IsValid());
}
@@ -438,6 +441,11 @@ class InternalDataFacade final : public BaseDataFacade
return m_coordinate_list[id];
}
OSMNodeID GetOSMNodeIDOfNode(const unsigned id) const override final
{
return m_osmnodeid_list[id];
}
extractor::guidance::TurnInstruction
GetTurnInstructionForEdgeID(const unsigned id) const override final
{
@@ -76,6 +76,7 @@ class SharedDataFacade final : public BaseDataFacade
extractor::ProfileProperties *m_profile_properties;
util::ShM<util::Coordinate, true>::vector m_coordinate_list;
util::ShM<OSMNodeID, true>::vector m_osmnodeid_list;
util::ShM<NodeID, true>::vector m_via_node_list;
util::ShM<unsigned, true>::vector m_name_ID_list;
util::ShM<extractor::guidance::TurnInstruction, true>::vector m_turn_instruction_list;
@@ -170,6 +171,11 @@ class SharedDataFacade final : public BaseDataFacade
coordinate_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
auto osmnodeid_list_ptr = data_layout->GetBlockPtr<OSMNodeID>(
shared_memory, storage::SharedDataLayout::OSM_NODE_ID_LIST);
m_osmnodeid_list.reset(osmnodeid_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::OSM_NODE_ID_LIST]);
auto travel_mode_list_ptr = data_layout->GetBlockPtr<extractor::TravelMode>(
shared_memory, storage::SharedDataLayout::TRAVEL_MODE);
util::ShM<extractor::TravelMode, true>::vector travel_mode_list(
@@ -471,6 +477,11 @@ class SharedDataFacade final : public BaseDataFacade
return m_coordinate_list[id];
}
OSMNodeID GetOSMNodeIDOfNode(const unsigned id) const override final
{
return m_osmnodeid_list[id];
}
virtual void GetUncompressedGeometry(const EdgeID id,
std::vector<NodeID> &result_nodes) const override final
{
@@ -43,6 +43,13 @@ LegGeometry assembleGeometry(const DataFacadeT &facade,
geometry.segment_offsets.push_back(0);
geometry.locations.push_back(source_node.location);
// Need to get the node ID preceding the source phantom node
// TODO: check if this was traversed in reverse?
std::vector<NodeID> reverse_geometry;
facade.GetUncompressedGeometry(source_node.reverse_packed_geometry_id, reverse_geometry);
geometry.osm_node_ids.push_back(facade.GetOSMNodeIDOfNode(
reverse_geometry[reverse_geometry.size() - source_node.fwd_segment_position - 1]));
auto cumulative_distance = 0.;
auto current_distance = 0.;
auto prev_coordinate = geometry.locations.front();
@@ -65,6 +72,7 @@ LegGeometry assembleGeometry(const DataFacadeT &facade,
geometry.annotations.emplace_back(
LegGeometry::Annotation{current_distance, path_point.duration_until_turn / 10.});
geometry.locations.push_back(std::move(coordinate));
geometry.osm_node_ids.push_back(facade.GetOSMNodeIDOfNode(path_point.turn_via_node));
}
current_distance =
util::coordinate_calculation::haversineDistance(prev_coordinate, target_node.location);
@@ -76,6 +84,13 @@ LegGeometry assembleGeometry(const DataFacadeT &facade,
geometry.segment_offsets.push_back(geometry.locations.size());
geometry.locations.push_back(target_node.location);
// Need to get the node ID following the destination phantom node
// TODO: check if this was traversed in reverse??
std::vector<NodeID> forward_geometry;
facade.GetUncompressedGeometry(target_node.forward_packed_geometry_id, forward_geometry);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(forward_geometry[target_node.fwd_segment_position]));
BOOST_ASSERT(geometry.segment_distances.size() == geometry.segment_offsets.size() - 1);
BOOST_ASSERT(geometry.locations.size() > geometry.segment_distances.size());
BOOST_ASSERT(geometry.annotations.size() == geometry.locations.size() - 1);
+3
View File
@@ -3,6 +3,7 @@
#include "util/coordinate.hpp"
#include "util/integer_range.hpp"
#include "util/typedefs.hpp"
#include <boost/assert.hpp>
@@ -30,6 +31,8 @@ struct LegGeometry
std::vector<std::size_t> segment_offsets;
// length of the segment in meters
std::vector<double> segment_distances;
// original OSM node IDs for each coordinate
std::vector<OSMNodeID> osm_node_ids;
// Per-coordinate metadata
struct Annotation
+1
View File
@@ -28,6 +28,7 @@ struct SharedDataLayout
GRAPH_NODE_LIST,
GRAPH_EDGE_LIST,
COORDINATE_LIST,
OSM_NODE_ID_LIST,
TURN_INSTRUCTION,
ENTRY_CLASSID,
TRAVEL_MODE,