Include datasources for each segment in route annotation.

This commit is contained in:
Daniel Patterson
2016-07-20 14:59:16 +02:00
parent fb4834458e
commit 280b000f07
11 changed files with 71 additions and 20 deletions
+5 -1
View File
@@ -207,18 +207,21 @@ class RouteAPI : public BaseAPI
util::json::Array durations;
util::json::Array distances;
util::json::Array nodes;
util::json::Array datasources;
auto &leg_geometry = leg_geometries[idx];
durations.values.reserve(leg_geometry.annotations.size());
distances.values.reserve(leg_geometry.annotations.size());
nodes.values.reserve(leg_geometry.osm_node_ids.size());
datasources.values.reserve(leg_geometry.annotations.size());
std::for_each(
leg_geometry.annotations.begin(),
leg_geometry.annotations.end(),
[this, &durations, &distances](const guidance::LegGeometry::Annotation &step) {
[this, &durations, &distances, &datasources](const guidance::LegGeometry::Annotation &step) {
durations.values.push_back(step.duration);
distances.values.push_back(step.distance);
datasources.values.push_back(step.datasource);
});
std::for_each(leg_geometry.osm_node_ids.begin(),
leg_geometry.osm_node_ids.end(),
@@ -229,6 +232,7 @@ class RouteAPI : public BaseAPI
annotation.values["distance"] = std::move(distances);
annotation.values["duration"] = std::move(durations);
annotation.values["nodes"] = std::move(nodes);
annotation.values["datasources"] = std::move(datasources);
annotations.push_back(std::move(annotation));
}
}
+11 -2
View File
@@ -50,6 +50,10 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
geometry.osm_node_ids.push_back(facade.GetOSMNodeIDOfNode(
reverse_geometry[reverse_geometry.size() - source_node.fwd_segment_position - 1]));
std::vector<uint8_t> forward_datasource_vector;
facade.GetUncompressedDatasources(source_node.forward_packed_geometry_id, forward_datasource_vector);
auto cumulative_distance = 0.;
auto current_distance = 0.;
auto prev_coordinate = geometry.locations.front();
@@ -70,7 +74,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
prev_coordinate = coordinate;
geometry.annotations.emplace_back(
LegGeometry::Annotation{current_distance, path_point.duration_until_turn / 10.});
LegGeometry::Annotation{current_distance, path_point.duration_until_turn / 10., path_point.datasource_id});
geometry.locations.push_back(std::move(coordinate));
geometry.osm_node_ids.push_back(facade.GetOSMNodeIDOfNode(path_point.turn_via_node));
}
@@ -79,8 +83,12 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
cumulative_distance += current_distance;
// segment leading to the target node
geometry.segment_distances.push_back(cumulative_distance);
std::vector<DatasourceID> forward_datasources;
facade.GetUncompressedDatasources(target_node.forward_packed_geometry_id, forward_datasources);
geometry.annotations.emplace_back(
LegGeometry::Annotation{current_distance, target_node.forward_weight / 10.});
LegGeometry::Annotation{current_distance, target_node.forward_weight / 10., forward_datasources[target_node.fwd_segment_position]});
geometry.segment_offsets.push_back(geometry.locations.size());
geometry.locations.push_back(target_node.location);
@@ -91,6 +99,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
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);
+1
View File
@@ -39,6 +39,7 @@ struct LegGeometry
{
double distance;
double duration;
DatasourceID datasource;
};
std::vector<Annotation> annotations;
+3
View File
@@ -33,6 +33,9 @@ struct PathData
extractor::TravelMode travel_mode : 4;
// entry class of the turn, indicating possibility of turns
EntryClassID entry_classid;
// Source of the speed value on this road segment
DatasourceID datasource_id;
};
struct InternalRouteResult
@@ -294,16 +294,18 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
? phantom_node_pair.source_phantom.backward_travel_mode
: facade->GetTravelModeForEdgeID(ed.id);
const auto geometry_index = facade->GetGeometryIndexForEdgeID(ed.id);
std::vector<NodeID> id_vector;
facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id),
id_vector);
facade->GetUncompressedGeometry(geometry_index, id_vector);
BOOST_ASSERT(id_vector.size() > 0);
std::vector<EdgeWeight> weight_vector;
facade->GetUncompressedWeights(facade->GetGeometryIndexForEdgeID(ed.id),
weight_vector);
facade->GetUncompressedWeights(geometry_index, weight_vector);
BOOST_ASSERT(weight_vector.size() > 0);
std::vector<DatasourceID> datasource_vector;
facade->GetUncompressedDatasources(geometry_index, datasource_vector);
auto total_weight = std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
BOOST_ASSERT(weight_vector.size() == id_vector.size());
@@ -329,7 +331,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
extractor::guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
travel_mode,
INVALID_ENTRY_CLASSID});
INVALID_ENTRY_CLASSID,
datasource_vector[i]});
}
BOOST_ASSERT(unpacked_path.size() > 0);
if (facade->hasLaneData(ed.id))
@@ -343,6 +346,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
std::size_t start_index = 0, end_index = 0;
std::vector<unsigned> id_vector;
std::vector<EdgeWeight> weight_vector;
std::vector<DatasourceID> datasource_vector;
const bool is_local_path = (phantom_node_pair.source_phantom.forward_packed_geometry_id ==
phantom_node_pair.target_phantom.forward_packed_geometry_id) &&
unpacked_path.empty();
@@ -355,6 +359,9 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
facade->GetUncompressedWeights(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, weight_vector);
facade->GetUncompressedDatasources(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, datasource_vector);
if (is_local_path)
{
start_index =
@@ -375,6 +382,9 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
facade->GetUncompressedWeights(
phantom_node_pair.target_phantom.forward_packed_geometry_id, weight_vector);
facade->GetUncompressedDatasources(
phantom_node_pair.target_phantom.forward_packed_geometry_id, datasource_vector);
}
// Given the following compressed geometry:
@@ -396,7 +406,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
target_traversed_in_reverse ? phantom_node_pair.target_phantom.backward_travel_mode
: phantom_node_pair.target_phantom.forward_travel_mode,
INVALID_ENTRY_CLASSID});
INVALID_ENTRY_CLASSID,
datasource_vector[i]});
}
if (unpacked_path.size() > 0)
+2
View File
@@ -83,6 +83,8 @@ static const NameID EMPTY_NAMEID = 0;
static const unsigned INVALID_COMPONENTID = 0;
static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max();
using DatasourceID = std::uint8_t;
struct SegmentID
{
SegmentID(const NodeID id_, const bool enabled_) : id{id_}, enabled{enabled_}