diff --git a/docs/profiles.md b/docs/profiles.md index b2c8a3d4d..c539d5121 100644 --- a/docs/profiles.md +++ b/docs/profiles.md @@ -208,33 +208,35 @@ The `process_turn` function is called for every possible turn in the network. Ba The following attributes can be read and set on the result in `process_turn`: -Attribute | Read/write? | Type | Notes ---------------------- | ------------- | --------- | ------------------------------------------------------ -angle | Read | Float | Angle of turn in degrees (`[-179, 180]`: `0`=straight, `180`=u turn, `+x`=x degrees to the right, `-x`= x degrees to the left) -number_of_roads | Read | Integer | Number of ways at the intersection of the turn -is_u_turn | Read | Boolean | Is the turn a u-turn? -has_traffic_light | Read | Boolean | Is a traffic light present at this turn? -is_left_hand_driving | Read | Boolean | Is left-hand traffic? -source_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`) -source_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp` -source_is_motorway | Read | Boolean | Is the source road a motorway? -source_is_link | Read | Boolean | Is the source road a link? -source_number_of_lanes | Read | Integer | How many lanes does the source road have? (default when not tagged: 0) -source_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) -source_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) -source_speed | Read | Integer | Speed on this source road in km/h -target_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`) -target_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp` -target_is_motorway | Read | Boolean | Is the target road a motorway? -target_is_link | Read | Boolean | Is the target road a link? -target_number_of_lanes | Read | Integer | How many lanes does the target road have? (default when not tagged: 0) -target_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) -target_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) -target_speed | Read | Integer | Speed on this target road in km/h -roads_on_the_right | Read | Vector | Vector with information about other roads on the right of the turn that are also connected at the intersection -roads_on_the_left | Read | Vector | Vector with information about other roads on the left of the turn that are also connected at the intersection. If turn is a u turn, this is empty. -weight | Read/write | Float | Penalty to be applied for this turn (routing weight) -duration | Read/write | Float | Penalty to be applied for this turn (duration in deciseconds) +Attribute | Read/write? | Type | Notes +--------------------- | ------------- | --------- | ------------------------------------------------------ +angle | Read | Float | Angle of turn in degrees (`[-179, 180]`: `0`=straight, `180`=u turn, `+x`=x degrees to the right, `-x`= x degrees to the left) +number_of_roads | Read | Integer | Number of ways at the intersection of the turn +is_u_turn | Read | Boolean | Is the turn a u-turn? +has_traffic_light | Read | Boolean | Is a traffic light present at this turn? +is_left_hand_driving | Read | Boolean | Is left-hand traffic? +source_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`) +source_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp` +source_is_motorway | Read | Boolean | Is the source road a motorway? +source_is_link | Read | Boolean | Is the source road a link? +source_number_of_lanes | Read | Integer | How many lanes does the source road have? (default when not tagged: 0) +source_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) +source_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) +source_speed | Read | Integer | Speed on this source road in km/h +source_priority_class | Read | Enum | The type of road priority class of the source. Defined in `include/extractor/guidance/road_classification.hpp` +target_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`) +target_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp` +target_is_motorway | Read | Boolean | Is the target road a motorway? +target_is_link | Read | Boolean | Is the target road a link? +target_number_of_lanes | Read | Integer | How many lanes does the target road have? (default when not tagged: 0) +target_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) +target_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) +target_speed | Read | Integer | Speed on this target road in km/h +target_priority_class | Read | Enum | The type of road priority class of the target. Defined in `include/extractor/guidance/road_classification.hpp` +roads_on_the_right | Read | Vector | Vector with information about other roads on the right of the turn that are also connected at the intersection +roads_on_the_left | Read | Vector | Vector with information about other roads on the left of the turn that are also connected at the intersection. If turn is a u turn, this is empty. +weight | Read/write | Float | Penalty to be applied for this turn (routing weight) +duration | Read/write | Float | Penalty to be applied for this turn (duration in deciseconds) #### `roads_on_the_right` and `roads_on_the_left` @@ -250,6 +252,7 @@ number_of_lanes | Read | Integer | How many lanes does th highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15) access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15) speed | Read | Integer | Speed on this road in km/h +priority_class | Read | Enum | The type of road priority class of the leg. Defined in `include/extractor/guidance/road_classification.hpp` is_incoming | Read | Boolean | Is the road an incoming road of the intersection is_outgoing | Read | Boolean | Is the road an outgoing road of the intersection diff --git a/features/options/extract/turn_function.feature b/features/options/extract/turn_function.feature index 897c1187c..adf412ccf 100644 --- a/features/options/extract/turn_function.feature +++ b/features/options/extract/turn_function.feature @@ -40,6 +40,7 @@ Feature: Turn Function Information .. ', is_outgoing: ' .. tostring(leg.is_outgoing) .. ', highway_turn_classification: ' .. tostring(leg.highway_turn_classification) .. ', access_turn_classification: ' .. tostring(leg.access_turn_classification) + .. ', priority_class: ' .. tostring(leg.priority_class) end function print_turn (profile, turn) @@ -50,6 +51,8 @@ Feature: Turn Function Information print ('source_highway_turn_classification ' .. string.format("%s", tostring(turn.source_highway_turn_classification))) print ('source_access_turn_classification ' .. string.format("%s", tostring(turn.source_access_turn_classification))) print ('source_speed ' .. string.format("%s", tostring(turn.source_speed))) + print ('source_priority_class ' .. string.format("%s", tostring(turn.source_priority_class))) + print ('source_mode ' .. string.format("%s", tostring(turn.source_mode))) print ('target_restricted ' .. string.format("%s", tostring(turn.target_restricted))) print ('target_is_motorway ' .. string.format("%s", tostring(turn.target_is_motorway))) @@ -58,6 +61,8 @@ Feature: Turn Function Information print ('target_highway_turn_classification ' .. string.format("%s", tostring(turn.target_highway_turn_classification))) print ('target_access_turn_classification ' .. string.format("%s", tostring(turn.target_access_turn_classification))) print ('target_speed ' .. string.format("%s", tostring(turn.target_speed))) + print ('target_priority_class ' .. string.format("%s", tostring(turn.target_priority_class))) + print ('target_mode ' .. string.format("%s", tostring(turn.target_mode))) print ('number_of_roads ' .. string.format("%s", tostring(turn.number_of_roads))) if not turn.is_u_turn then @@ -97,8 +102,10 @@ Feature: Turn Function Information And stdout should contain "source_is_motorway true" And stdout should contain "target_is_motorway true" And stdout should contain "source_is_link false" + And stdout should contain "source_priority_class 0" And stdout should contain "target_is_motorway true" And stdout should contain "target_is_link false" + And stdout should contain "target_priority_class 0" Scenario: Turns should detect when turn is leaving highway @@ -143,6 +150,9 @@ Feature: Turn Function Information When I run "osrm-extract --profile {profile_file} {osm_file}" Then it should exit successfully And stdout should contain "number_of_roads 3" + And stdout should contain "source_priority_class 4" + And stdout should contain "target_priority_class 0" + And stdout should contain "target_priority_class 11" # turning abd, give information about bc And stdout should contain /roads_on_the_right \[1\] speed: [0-9]+, is_incoming: false, is_outgoing: true, highway_turn_classification: 4, access_turn_classification: 0/ # turning abc, give information about bd diff --git a/include/extractor/extraction_turn.hpp b/include/extractor/extraction_turn.hpp index 6256e15ae..0480d7073 100644 --- a/include/extractor/extraction_turn.hpp +++ b/include/extractor/extraction_turn.hpp @@ -1,7 +1,8 @@ #ifndef OSRM_EXTRACTION_TURN_HPP #define OSRM_EXTRACTION_TURN_HPP -#include +#include "extractor/road_classification.hpp" +#include "extractor/travel_mode.hpp" #include @@ -21,13 +22,14 @@ struct ExtractionTurnLeg int highway_turn_classification, int access_turn_classification, int speed, + RoadPriorityClass::Enum priority_class, bool is_incoming, bool is_outgoing) : is_restricted(is_restricted), is_motorway(is_motorway), is_link(is_link), number_of_lanes(number_of_lanes), highway_turn_classification(highway_turn_classification), access_turn_classification(access_turn_classification), speed(speed), - is_incoming(is_incoming), is_outgoing(is_outgoing) + priority_class(priority_class), is_incoming(is_incoming), is_outgoing(is_outgoing) { } @@ -38,6 +40,7 @@ struct ExtractionTurnLeg const int highway_turn_classification; const int access_turn_classification; const int speed; + const RoadPriorityClass::Enum priority_class; const bool is_incoming; const bool is_outgoing; }; @@ -53,11 +56,12 @@ struct ExtractionTurn TravelMode source_mode, bool source_is_motorway, bool source_is_link, - int source_number_of_lanes, int source_highway_turn_classification, int source_access_turn_classification, int source_speed, + RoadPriorityClass::Enum source_priority_class, + bool target_restricted, TravelMode target_mode, bool target_is_motorway, @@ -66,6 +70,8 @@ struct ExtractionTurn int target_highway_turn_classification, int target_access_turn_classification, int target_speed, + RoadPriorityClass::Enum target_priority_class, + const std::vector &roads_on_the_right, const std::vector &roads_on_the_left) : angle(180. - angle), number_of_roads(number_of_roads), is_u_turn(is_u_turn), @@ -76,14 +82,14 @@ struct ExtractionTurn source_number_of_lanes(source_number_of_lanes), source_highway_turn_classification(source_highway_turn_classification), source_access_turn_classification(source_access_turn_classification), - source_speed(source_speed), + source_speed(source_speed), source_priority_class(source_priority_class), target_restricted(target_restricted), target_mode(target_mode), target_is_motorway(target_is_motorway), target_is_link(target_is_link), target_number_of_lanes(target_number_of_lanes), target_highway_turn_classification(target_highway_turn_classification), target_access_turn_classification(target_access_turn_classification), - target_speed(target_speed), + target_speed(target_speed), target_priority_class(target_priority_class), roads_on_the_right(roads_on_the_right), roads_on_the_left(roads_on_the_left), weight(0.), duration(0.) @@ -105,6 +111,7 @@ struct ExtractionTurn const int source_highway_turn_classification; const int source_access_turn_classification; const int source_speed; + const RoadPriorityClass::Enum source_priority_class; // target info const bool target_restricted; @@ -115,6 +122,7 @@ struct ExtractionTurn const int target_highway_turn_classification; const int target_access_turn_classification; const int target_speed; + const RoadPriorityClass::Enum target_priority_class; const std::vector roads_on_the_right; const std::vector roads_on_the_left; diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 6b1722260..a6812718a 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -585,6 +585,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( ((double)intersection::findEdgeLength(edge_geometries, node_based_edge_from) / edge_data1.duration) * 36, + edge_data1.flags.road_classification.GetPriority(), // target info edge_data2.flags.restricted, m_edge_based_node_container.GetAnnotation(edge_data2.annotation_data).travel_mode, @@ -596,6 +597,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( ((double)intersection::findEdgeLength(edge_geometries, node_based_edge_to) / edge_data2.duration) * 36, + edge_data2.flags.road_classification.GetPriority(), // connected roads road_legs_on_the_right, road_legs_on_the_left); @@ -763,6 +765,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( connected_edge.eid) / edge_data.duration) * 36, + edge_data.flags.road_classification.GetPriority(), !connected_edge.entry_allowed || (edge_data.flags.forward && edge_data.flags.backward), // is incoming diff --git a/src/extractor/graph_compressor.cpp b/src/extractor/graph_compressor.cpp index 27c428d8d..1af0617b5 100644 --- a/src/extractor/graph_compressor.cpp +++ b/src/extractor/graph_compressor.cpp @@ -235,6 +235,7 @@ void GraphCompressor::Compress( 0, 0, 0, + 0, false, TRAVEL_MODE_DRIVING, false, @@ -243,6 +244,7 @@ void GraphCompressor::Compress( 0, 0, 0, + 0, roads_on_the_right, roads_on_the_left); scripting_environment.ProcessTurn(extraction_turn); diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index 70cef802e..9b802b0a0 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -692,6 +692,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) &ExtractionTurnLeg::access_turn_classification, "speed", &ExtractionTurnLeg::speed, + "priority_class", + &ExtractionTurnLeg::priority_class, "is_incoming", &ExtractionTurnLeg::is_incoming, "is_outgoing", @@ -726,6 +728,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) &ExtractionTurn::source_access_turn_classification, "source_speed", &ExtractionTurn::source_speed, + "source_priority_class", + &ExtractionTurn::source_priority_class, "target_restricted", &ExtractionTurn::target_restricted, @@ -743,6 +747,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) &ExtractionTurn::target_access_turn_classification, "target_speed", &ExtractionTurn::target_speed, + "target_priority_class", + &ExtractionTurn::target_priority_class, "roads_on_the_right", &ExtractionTurn::roads_on_the_right,