From 1628ebb871f6d81e8af8397ee78c362964564f79 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Tue, 31 Jan 2017 12:57:04 +0100 Subject: [PATCH] Fix assertions in car profile, resolves #3629 restrict direction if access tag is missing and can not be derived from highway tag http://www.openstreetmap.org/way/4282676 http://www.openstreetmap.org/way/4621857 http://www.openstreetmap.org/way/4898368 --- features/car/access.feature | 11 +++++++++++ features/foot/access.feature | 5 +++++ profiles/lib/handlers.lua | 34 ++++++++++++++++++++-------------- profiles/lib/tags.lua | 10 +++++----- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/features/car/access.feature b/features/car/access.feature index 5dc30cb08..959469be0 100644 --- a/features/car/access.feature +++ b/features/car/access.feature @@ -245,3 +245,14 @@ Feature: Car - Restricted access | gate | designated | x | | gate | private | | | gate | garbagetag | x | + + Scenario: Car - a way with conditional access + Then routability should be + | highway | vehicle:forward | vehicle:backward:conditional | forw | backw | + | pedestrian | yes | delivery @ (20:00-11:00) | x | | + + Scenario: Car - a way with a list of tags + Then routability should be + | highway | motor_vehicle | motor_vehicle:forward | motor_vehicle:backward | forw | backw | + | footway | | | destination | | x | + | track | destination;agricultural | destination | | x | x | diff --git a/features/foot/access.feature b/features/foot/access.feature index cdcfa3436..525fd03d2 100644 --- a/features/foot/access.feature +++ b/features/foot/access.feature @@ -103,3 +103,8 @@ Feature: Foot - Access tags on ways | bridleway | | yes | | | | bridleway | designated | | | | | bridleway | | | | | + + Scenario: Foot - a way with missing :forward tag + Then routability should be + | highway | bicycle:backward | foot:backward | forw | backw | + | cycleway | designated | designated | | x | diff --git a/profiles/lib/handlers.lua b/profiles/lib/handlers.lua index d8f3166e1..25d9ceefa 100644 --- a/profiles/lib/handlers.lua +++ b/profiles/lib/handlers.lua @@ -66,7 +66,7 @@ end -- determine if this way can be used as a start/end point for routing function Handlers.handle_startpoint(way,result,data,profile) -- only allow this road as start point if it not a ferry - result.is_startpoint = result.forward_mode == profile.default_mode or + result.is_startpoint = result.forward_mode == profile.default_mode or result.backward_mode == profile.default_mode end @@ -210,23 +210,29 @@ function Handlers.handle_speed(way,result,data,profile) if result.forward_speed ~= -1 then return -- abort if already set, eg. by a route end - + local key,value,speed = Tags.get_constant_by_key_value(way,profile.speeds) - + if speed then -- set speed by way type - result.forward_speed = highway_speed - result.backward_speed = highway_speed result.forward_speed = speed result.backward_speed = speed - else + else -- Set the avg speed on ways that are marked accessible if profile.access_tag_whitelist[data.forward_access] then result.forward_speed = profile.default_speed + elseif data.forward_access and not profile.access_tag_blacklist[data.forward_access] then + result.forward_speed = profile.default_speed -- fallback to the avg speed if access tag is not blacklisted + elseif not data.forward_access and data.backward_access then + result.forward_mode = mode.inaccessible end if profile.access_tag_whitelist[data.backward_access] then result.backward_speed = profile.default_speed + elseif data.backward_access and not profile.access_tag_blacklist[data.backward_access] then + result.backward_speed = profile.default_speed -- fallback to the avg speed if access tag is not blacklisted + elseif not data.backward_access and data.forward_access then + result.backward_mode = mode.inaccessible end end @@ -236,7 +242,7 @@ function Handlers.handle_speed(way,result,data,profile) end -- reduce speed on special side roads -function Handlers.handle_side_roads(way,result,data,profile) +function Handlers.handle_side_roads(way,result,data,profile) local sideway = way:get_value_by_key("side_road") if "yes" == sideway or "rotary" == sideway then @@ -281,7 +287,7 @@ function Handlers.handle_speed_scaling(way,result,data,profile) end end - local is_bidirectional = result.forward_mode ~= mode.inaccessible and + local is_bidirectional = result.forward_mode ~= mode.inaccessible and result.backward_mode ~= mode.inaccessible local service = way:get_value_by_key("service") @@ -367,7 +373,7 @@ function Handlers.handle_oneway(way,result,data,profile) if not profile.oneway_handling then return end - + local oneway if profile.oneway_handling == true then oneway = Tags.get_value_by_prefixed_sequence(way,profile.restrictions,'oneway') or way:get_value_by_key("oneway") @@ -388,7 +394,7 @@ function Handlers.handle_oneway(way,result,data,profile) elseif profile.oneway_handling == true then local junction = way:get_value_by_key("junction") if data.highway == "motorway" or - junction == "roundabout" or + junction == "roundabout" or junction == "circular" then if oneway ~= "no" then -- implied oneway @@ -402,12 +408,12 @@ end -- handle various that can block access function Handlers.handle_blocked_ways(way,result,data,profile) - + -- areas if profile.avoid.area and way:get_value_by_key("area") == "yes" then return false end - + -- toll roads if profile.avoid.toll and way:get_value_by_key("toll") == "yes" then return false @@ -419,7 +425,7 @@ function Handlers.handle_blocked_ways(way,result,data,profile) if profile.avoid.reversible and way:get_value_by_key("oneway") == "reversible" then return false end - + -- impassables if profile.avoid.impassable then if way:get_value_by_key("impassable") == "yes" then @@ -458,4 +464,4 @@ function Handlers.run(handlers,way,result,data,profile) end end -return Handlers \ No newline at end of file +return Handlers diff --git a/profiles/lib/tags.lua b/profiles/lib/tags.lua index 8ea55eac2..a1a8f0a9b 100644 --- a/profiles/lib/tags.lua +++ b/profiles/lib/tags.lua @@ -13,7 +13,7 @@ local Tags = {} function Tags.get_forward_backward_by_key(way,data,key) local forward = way:get_value_by_key(key .. ':forward') local backward = way:get_value_by_key(key .. ':backward') - + if forward and backward then return forward, backward end @@ -23,7 +23,7 @@ function Tags.get_forward_backward_by_key(way,data,key) backward or common end --- return [forward,backward] values, searching a +-- return [forward,backward] values, searching a -- prioritized sequence of tags -- e.g. for the sequence [maxspeed,advisory] search forward: -- maxspeed:forward @@ -90,7 +90,7 @@ function Tags.get_value_by_postfixed_sequence(way,seq,postfix) end end --- check if key-value pairs are set in a way and return a +-- check if key-value pairs are set in a way and return a -- corresponding constant if it is. e.g. for this input: -- -- local speeds = { @@ -105,7 +105,7 @@ end -- -- we would check whether the following key-value combinations -- are set, and return the corresponding constant: --- +-- -- highway = residential => 20 -- highway = primary => 40 -- amenity = parking => 10 @@ -121,4 +121,4 @@ function Tags.get_constant_by_key_value(way,lookup) end end -return Tags \ No newline at end of file +return Tags