From 7ad52de2b1b2e2c0ec89fb20ecfb7eaf27347fde Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 15 May 2015 14:45:50 +0200 Subject: [PATCH 1/7] Cleanup the profiles --- profiles/bicycle.lua | 99 ++++++++++++++++++++++---------------------- profiles/car.lua | 10 +---- 2 files changed, 52 insertions(+), 57 deletions(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index dc290e11a..1e8e97928 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -12,10 +12,10 @@ access_tags_hierachy = { "bicycle", "vehicle", "access" } cycleway_tags = {["track"]=true,["lane"]=true,["opposite"]=true,["opposite_lane"]=true,["opposite_track"]=true,["share_busway"]=true,["sharrow"]=true,["shared"]=true } service_tag_restricted = { ["parking_aisle"] = true } restriction_exception_tags = { "bicycle", "vehicle", "access" } +unsafe_highway_list = { ["primary"] = true, ["secondary"] = true, ["tertiary"] = true, ["primary_link"] = true, ["secondary_link"] = true, ["tertiary_link"] = true} -default_speed = 15 - -walking_speed = 6 +local default_speed = 15 +local walking_speed = 6 bicycle_speeds = { ["cycleway"] = default_speed, @@ -91,24 +91,22 @@ surface_speeds = { ["sand"] = 3 } -take_minimum_of_speeds = true -obey_oneway = true -obey_bollards = false -use_restrictions = true -ignore_areas = true -- future feature -traffic_signal_penalty = 5 -u_turn_penalty = 20 -use_turn_restrictions = false -turn_penalty = 60 -turn_bias = 1.4 - +local obey_oneway = true +local obey_bollards = false +local ignore_areas = true +local u_turn_penalty = 20 +local turn_penalty = 60 +local turn_bias = 1.4 +-- reduce the driving speed by 30% for unsafe roads +local safety_penalty = 0.7 +local use_public_transport = false --modes -mode_normal = 1 -mode_pushing = 2 -mode_ferry = 3 -mode_train = 4 -mode_movable_bridge = 5 +local mode_normal = 1 +local mode_pushing = 2 +local mode_ferry = 3 +local mode_train = 4 +local mode_movable_bridge = 5 local function parse_maxspeed(source) if not source then @@ -131,29 +129,26 @@ function get_exceptions(vector) end function node_function (node, result) - local barrier = node:get_value_by_key("barrier") + -- parse access and barrier tags local access = find_access_tag(node, access_tags_hierachy) - local traffic_signal = node:get_value_by_key("highway") + if access ~= "" then + if access_tag_blacklist[access] then + result.barrier = true + end + else + local barrier = node:get_value_by_key("barrier") + if barrier and "" ~= barrier then + if not barrier_whitelist[barrier] then + result.barrier = true + end + end + end - -- flag node if it carries a traffic light - if traffic_signal and traffic_signal == "traffic_signals" then - result.traffic_lights = true - end - - -- parse access and barrier tags - if access and access ~= "" then - if access_tag_blacklist[access] then - result.barrier = true - else - result.barrier = false - end - elseif barrier and barrier ~= "" then - if barrier_whitelist[barrier] then - result.barrier = false - else - result.barrier = true - end - end + -- check if node is a traffic light + local tag = node:get_value_by_key("highway") + if tag and "traffic_signals" == tag then + result.traffic_lights = true; + end end function way_function (way, result) @@ -166,8 +161,8 @@ function way_function (way, result) local public_transport = way:get_value_by_key("public_transport") local bridge = way:get_value_by_key("bridge") if (not highway or highway == '') and - (not route or route == '') and - (not railway or railway=='') and + (not use_public_transport or not route or route == '') and + (not use_public_transport or not railway or railway=='') and (not amenity or amenity=='') and (not man_made or man_made=='') and (not public_transport or public_transport=='') and @@ -214,10 +209,11 @@ function way_function (way, result) result.name = ref elseif name and "" ~= name then result.name = name - elseif highway then - -- if no name exists, use way type - -- this encoding scheme is excepted to be a temporary solution - result.name = "{highway:"..highway.."}" +-- TODO find a better solution for encoding way type +-- elseif highway then +-- -- if no name exists, use way type +-- -- this encoding scheme is excepted to be a temporary solution +-- result.name = "{highway:"..highway.."}" end -- roundabout handling @@ -247,15 +243,16 @@ function way_function (way, result) result.forward_speed = route_speeds[route] result.backward_speed = route_speeds[route] end - elseif railway and platform_speeds[railway] then + -- public transport + if use_public_transport and railway and platform_speeds[railway] then -- railway platforms (old tagging scheme) result.forward_speed = platform_speeds[railway] result.backward_speed = platform_speeds[railway] - elseif platform_speeds[public_transport] then + elseif use_public_transport and platform_speeds[public_transport] then -- public_transport platforms (new tagging platform) result.forward_speed = platform_speeds[public_transport] result.backward_speed = platform_speeds[public_transport] - elseif railway and railway_speeds[railway] then + elseif use_public_transport and railway and railway_speeds[railway] then result.forward_mode = mode_train result.backward_mode = mode_train -- railways @@ -271,6 +268,10 @@ function way_function (way, result) -- regular ways result.forward_speed = bicycle_speeds[highway] result.backward_speed = bicycle_speeds[highway] + if unsafe_highway_list[highway] then + result.forward_speed *= safety_penalty + result.backward_speed *= safety_penalty + end elseif access and access_tag_whitelist[access] then -- unknown way, but valid access tag result.forward_speed = default_speed diff --git a/profiles/car.lua b/profiles/car.lua index 6b77575ed..4f4e081d9 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -132,10 +132,9 @@ maxspeed_table = { traffic_signal_penalty = 2 use_turn_restrictions = true -local take_minimum_of_speeds = false local obey_oneway = true local obey_bollards = true -local ignore_areas = true -- future feature +local ignore_areas = true local u_turn_penalty = 20 local abs = math.abs @@ -179,6 +178,7 @@ local function parse_maxspeed(source) return n end +-- FIXME Why was this commented out? -- function turn_function (angle) -- -- print ("called at angle " .. angle ) -- local index = math.abs(math.floor(angle/10+0.5))+1 -- +1 'coz LUA starts as idx 1 @@ -420,9 +420,3 @@ function way_function (way, result) end end --- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT -function node_vector_function(vector) - for v in vector.nodes do - node_function(v) - end -end From f04a3e3d2e34dbfba15b30090c330118a55befa4 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 15 May 2015 15:35:48 +0200 Subject: [PATCH 2/7] Fix bicycle profile syntax --- profiles/bicycle.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 1e8e97928..9efcf7070 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -269,8 +269,8 @@ function way_function (way, result) result.forward_speed = bicycle_speeds[highway] result.backward_speed = bicycle_speeds[highway] if unsafe_highway_list[highway] then - result.forward_speed *= safety_penalty - result.backward_speed *= safety_penalty + result.forward_speed = result.forward_speed * safety_penalty + result.backward_speed = result.backward_speed * safety_penalty end elseif access and access_tag_whitelist[access] then -- unknown way, but valid access tag From aad846b968098f00ee70ab996db84b65a8a9658f Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 15 May 2015 16:35:35 +0200 Subject: [PATCH 3/7] Fix call to function and transportation if clause --- profiles/bicycle.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 9efcf7070..7b7e54177 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -130,7 +130,7 @@ end function node_function (node, result) -- parse access and barrier tags - local access = find_access_tag(node, access_tags_hierachy) + local access = Access.find_access_tag(node, access_tags_hierachy) if access ~= "" then if access_tag_blacklist[access] then result.barrier = true @@ -244,7 +244,7 @@ function way_function (way, result) result.backward_speed = route_speeds[route] end -- public transport - if use_public_transport and railway and platform_speeds[railway] then + elseif use_public_transport and railway and platform_speeds[railway] then -- railway platforms (old tagging scheme) result.forward_speed = platform_speeds[railway] result.backward_speed = platform_speeds[railway] From c778ab96226ba72e779ec55e9ec2f06c2d904f1d Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 15 May 2015 17:01:03 +0200 Subject: [PATCH 4/7] Make bicycle profile backwards compatible --- profiles/bicycle.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 7b7e54177..aa688f12e 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -98,8 +98,9 @@ local u_turn_penalty = 20 local turn_penalty = 60 local turn_bias = 1.4 -- reduce the driving speed by 30% for unsafe roads -local safety_penalty = 0.7 -local use_public_transport = false +-- local safety_penalty = 0.7 +local safety_penalty = 1.0 +local use_public_transport = true --modes local mode_normal = 1 @@ -268,7 +269,7 @@ function way_function (way, result) -- regular ways result.forward_speed = bicycle_speeds[highway] result.backward_speed = bicycle_speeds[highway] - if unsafe_highway_list[highway] then + if safety_penalty < 1 and unsafe_highway_list[highway] then result.forward_speed = result.forward_speed * safety_penalty result.backward_speed = result.backward_speed * safety_penalty end From 6166d946f7c89915d63a41cec37a2c5068654998 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 15 May 2015 17:01:21 +0200 Subject: [PATCH 5/7] Fix access tag check --- profiles/bicycle.lua | 2 +- profiles/car.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index aa688f12e..2781cc404 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -132,7 +132,7 @@ end function node_function (node, result) -- parse access and barrier tags local access = Access.find_access_tag(node, access_tags_hierachy) - if access ~= "" then + if access and access ~= "" then if access_tag_blacklist[access] then result.barrier = true end diff --git a/profiles/car.lua b/profiles/car.lua index 4f4e081d9..3e22afe04 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -190,7 +190,7 @@ end function node_function (node, result) -- parse access and barrier tags local access = find_access_tag(node, access_tags_hierachy) - if access ~= "" then + if access and access ~= "" then if access_tag_blacklist[access] then result.barrier = true end From de2f06970d291536a2a9b779a4c4db8bc1fb715f Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Sat, 16 May 2015 14:36:32 +0200 Subject: [PATCH 6/7] Fix missing values and activate fallback names by default --- profiles/bicycle.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 2781cc404..aaf29d28c 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -91,6 +91,9 @@ surface_speeds = { ["sand"] = 3 } +traffic_signal_penalty = 2 +use_turn_restrictions = false + local obey_oneway = true local obey_bollards = false local ignore_areas = true @@ -101,6 +104,7 @@ local turn_bias = 1.4 -- local safety_penalty = 0.7 local safety_penalty = 1.0 local use_public_transport = true +local fallback_names = true --modes local mode_normal = 1 @@ -210,11 +214,11 @@ function way_function (way, result) result.name = ref elseif name and "" ~= name then result.name = name --- TODO find a better solution for encoding way type --- elseif highway then --- -- if no name exists, use way type --- -- this encoding scheme is excepted to be a temporary solution --- result.name = "{highway:"..highway.."}" + -- TODO find a better solution for encoding way type + elseif fallback_names and highway then + -- if no name exists, use way type + -- this encoding scheme is excepted to be a temporary solution + result.name = "{highway:"..highway.."}" end -- roundabout handling From 074c7a9c403e22a655c9ef0d05eb928aeb3d9fda Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Sun, 17 May 2015 17:26:10 +0200 Subject: [PATCH 7/7] Fix access module --- profiles/bicycle.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index aaf29d28c..9630a6e4c 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -135,7 +135,7 @@ end function node_function (node, result) -- parse access and barrier tags - local access = Access.find_access_tag(node, access_tags_hierachy) + local access = find_access_tag(node, access_tags_hierachy) if access and access ~= "" then if access_tag_blacklist[access] then result.barrier = true