2012-09-19 12:35:45 -04:00
|
|
|
-- Begin of globals
|
2013-01-05 11:32:39 -05:00
|
|
|
require("lib/access")
|
2012-09-19 12:35:45 -04:00
|
|
|
|
2013-07-09 08:08:24 -04:00
|
|
|
barrier_whitelist = { ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true, ["entrance"] = true}
|
2012-09-19 12:35:45 -04:00
|
|
|
access_tag_whitelist = { ["yes"] = true, ["motorcar"] = true, ["motor_vehicle"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true }
|
2012-12-18 05:12:17 -05:00
|
|
|
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestry"] = true }
|
2012-09-19 12:35:45 -04:00
|
|
|
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
|
|
|
|
access_tags = { "motorcar", "motor_vehicle", "vehicle" }
|
2012-10-04 08:18:39 -04:00
|
|
|
access_tags_hierachy = { "motorcar", "motor_vehicle", "vehicle", "access" }
|
2012-09-19 12:35:45 -04:00
|
|
|
service_tag_restricted = { ["parking_aisle"] = true }
|
2012-10-11 10:35:14 -04:00
|
|
|
ignore_in_grid = { ["ferry"] = true }
|
2013-01-05 11:32:39 -05:00
|
|
|
restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" }
|
2012-09-19 12:35:45 -04:00
|
|
|
|
2013-06-26 13:40:25 -04:00
|
|
|
speed_profile = {
|
|
|
|
["motorway"] = 90,
|
|
|
|
["motorway_link"] = 75,
|
|
|
|
["trunk"] = 85,
|
2012-09-27 05:35:56 -04:00
|
|
|
["trunk_link"] = 70,
|
|
|
|
["primary"] = 65,
|
2012-09-19 12:35:45 -04:00
|
|
|
["primary_link"] = 60,
|
2012-09-27 05:35:56 -04:00
|
|
|
["secondary"] = 55,
|
2012-09-19 12:35:45 -04:00
|
|
|
["secondary_link"] = 50,
|
2012-09-27 05:35:56 -04:00
|
|
|
["tertiary"] = 40,
|
|
|
|
["tertiary_link"] = 30,
|
|
|
|
["unclassified"] = 25,
|
|
|
|
["residential"] = 25,
|
2012-09-19 12:35:45 -04:00
|
|
|
["living_street"] = 10,
|
|
|
|
["service"] = 15,
|
|
|
|
-- ["track"] = 5,
|
|
|
|
["ferry"] = 5,
|
2013-02-04 12:38:15 -05:00
|
|
|
["shuttle_train"] = 10,
|
2013-08-19 11:36:15 -04:00
|
|
|
["default"] = 10
|
2012-09-19 12:35:45 -04:00
|
|
|
}
|
|
|
|
|
2013-07-17 10:23:57 -04:00
|
|
|
take_minimum_of_speeds = false
|
|
|
|
obey_oneway = true
|
|
|
|
obey_bollards = true
|
|
|
|
use_restrictions = true
|
|
|
|
ignore_areas = true -- future feature
|
|
|
|
traffic_signal_penalty = 2
|
|
|
|
u_turn_penalty = 20
|
2012-09-19 12:35:45 -04:00
|
|
|
|
|
|
|
-- End of globals
|
|
|
|
|
2013-01-05 11:32:39 -05:00
|
|
|
function get_exceptions(vector)
|
2013-06-26 13:40:25 -04:00
|
|
|
for i,v in ipairs(restriction_exception_tags) do
|
2013-01-05 11:32:39 -05:00
|
|
|
vector:Add(v)
|
2012-11-12 11:00:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-03 03:19:01 -04:00
|
|
|
local function parse_maxspeed(source)
|
|
|
|
if source == nil then
|
|
|
|
return 0
|
|
|
|
end
|
2013-01-04 06:31:43 -05:00
|
|
|
local n = tonumber(source:match("%d*"))
|
2012-11-03 03:19:01 -04:00
|
|
|
if n == nil then
|
|
|
|
n = 0
|
|
|
|
end
|
|
|
|
if string.match(source, "mph") or string.match(source, "mp/h") then
|
|
|
|
n = (n*1609)/1000;
|
|
|
|
end
|
2012-11-12 11:00:36 -05:00
|
|
|
return math.abs(n)
|
2012-11-03 03:19:01 -04:00
|
|
|
end
|
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
function node_function (node)
|
2013-08-19 07:56:57 -04:00
|
|
|
local barrier = node.tags:Find("barrier")
|
2013-01-05 11:32:39 -05:00
|
|
|
local access = Access.find_access_tag(node, access_tags_hierachy)
|
2012-09-19 12:35:45 -04:00
|
|
|
local traffic_signal = node.tags:Find("highway")
|
2013-06-26 13:40:25 -04:00
|
|
|
|
2012-10-04 02:33:52 -04:00
|
|
|
--flag node if it carries a traffic light
|
2013-06-26 13:40:25 -04:00
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
if traffic_signal == "traffic_signals" then
|
2013-06-26 13:40:25 -04:00
|
|
|
node.traffic_light = true;
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
2013-06-26 13:40:25 -04:00
|
|
|
|
2012-10-04 08:18:39 -04:00
|
|
|
-- parse access and barrier tags
|
|
|
|
if access and access ~= "" then
|
|
|
|
if access_tag_blacklist[access] then
|
|
|
|
node.bollard = true
|
|
|
|
end
|
|
|
|
elseif barrier and barrier ~= "" then
|
|
|
|
if barrier_whitelist[barrier] then
|
|
|
|
return
|
|
|
|
else
|
|
|
|
node.bollard = true
|
|
|
|
end
|
2012-09-27 05:35:56 -04:00
|
|
|
end
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
|
|
|
|
2012-10-04 08:18:39 -04:00
|
|
|
|
2013-02-27 11:36:44 -05:00
|
|
|
function way_function (way)
|
2013-06-26 13:40:25 -04:00
|
|
|
-- we dont route over areas
|
|
|
|
local area = way.tags:Find("area")
|
|
|
|
if ignore_areas and ("yes" == area) then
|
2013-08-16 11:10:02 -04:00
|
|
|
return
|
2013-06-26 13:40:25 -04:00
|
|
|
end
|
2012-09-19 12:35:45 -04:00
|
|
|
|
2013-06-26 13:40:25 -04:00
|
|
|
-- check if oneway tag is unsupported
|
|
|
|
local oneway = way.tags:Find("oneway")
|
|
|
|
if "reversible" == oneway then
|
2013-08-16 11:10:02 -04:00
|
|
|
return
|
2013-06-26 13:40:25 -04:00
|
|
|
end
|
2012-09-19 12:35:45 -04:00
|
|
|
|
2013-06-26 13:40:25 -04:00
|
|
|
-- Check if we are allowed to access the way
|
|
|
|
local access = Access.find_access_tag(way, access_tags_hierachy)
|
|
|
|
if access_tag_blacklist[access] then
|
2013-08-16 11:10:02 -04:00
|
|
|
return
|
2013-06-26 13:40:25 -04:00
|
|
|
end
|
2012-10-04 08:18:39 -04:00
|
|
|
|
2013-06-26 13:40:25 -04:00
|
|
|
-- Second, parse the way according to these properties
|
|
|
|
local highway = way.tags:Find("highway")
|
|
|
|
local name = way.tags:Find("name")
|
|
|
|
local ref = way.tags:Find("ref")
|
|
|
|
local junction = way.tags:Find("junction")
|
|
|
|
local route = way.tags:Find("route")
|
|
|
|
local maxspeed = parse_maxspeed(way.tags:Find ( "maxspeed") )
|
|
|
|
local maxspeed_forward = parse_maxspeed(way.tags:Find( "maxspeed:forward"))
|
|
|
|
local maxspeed_backward = parse_maxspeed(way.tags:Find( "maxspeed:backward"))
|
|
|
|
local barrier = way.tags:Find("barrier")
|
|
|
|
local cycleway = way.tags:Find("cycleway")
|
|
|
|
local duration = way.tags:Find("duration")
|
|
|
|
local service = way.tags:Find("service")
|
|
|
|
|
|
|
|
|
|
|
|
-- Set the name that will be used for instructions
|
2012-09-19 12:35:45 -04:00
|
|
|
if "" ~= ref then
|
|
|
|
way.name = ref
|
|
|
|
elseif "" ~= name then
|
|
|
|
way.name = name
|
2012-10-06 09:01:26 -04:00
|
|
|
-- else
|
|
|
|
-- way.name = highway -- if no name exists, use way type
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
2013-06-26 13:40:25 -04:00
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
if "roundabout" == junction then
|
|
|
|
way.roundabout = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Handling ferries and piers
|
2013-02-04 06:13:30 -05:00
|
|
|
if (speed_profile[route] ~= nil and speed_profile[route] > 0) then
|
2013-06-26 13:40:25 -04:00
|
|
|
if durationIsValid(duration) then
|
|
|
|
way.duration = math.max( parseDuration(duration), 1 );
|
|
|
|
end
|
|
|
|
way.direction = Way.bidirectional
|
|
|
|
if speed_profile[route] ~= nil then
|
|
|
|
highway = route;
|
|
|
|
end
|
|
|
|
if tonumber(way.duration) < 0 then
|
|
|
|
way.speed = speed_profile[highway]
|
|
|
|
end
|
2013-02-04 06:13:30 -05:00
|
|
|
end
|
2013-06-26 13:40:25 -04:00
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
-- Set the avg speed on the way if it is accessible by road class
|
2013-02-04 12:38:15 -05:00
|
|
|
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
|
2013-06-26 13:40:25 -04:00
|
|
|
if maxspeed > speed_profile[highway] then
|
|
|
|
way.speed = maxspeed
|
|
|
|
else
|
|
|
|
if 0 == maxspeed then
|
|
|
|
maxspeed = math.huge
|
|
|
|
end
|
|
|
|
way.speed = math.min(speed_profile[highway], maxspeed)
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
2013-02-04 06:13:30 -05:00
|
|
|
end
|
2012-09-19 12:35:45 -04:00
|
|
|
|
|
|
|
-- Set the avg speed on ways that are marked accessible
|
2013-06-26 13:40:25 -04:00
|
|
|
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
|
|
|
|
if 0 == maxspeed then
|
|
|
|
maxspeed = math.huge
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
2013-06-26 13:40:25 -04:00
|
|
|
way.speed = math.min(speed_profile["default"], maxspeed)
|
|
|
|
end
|
2013-02-04 06:13:30 -05:00
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
-- Set access restriction flag if access is allowed under certain restrictions only
|
2013-06-26 13:40:25 -04:00
|
|
|
if access ~= "" and access_tag_restricted[access] then
|
|
|
|
way.is_access_restricted = true
|
|
|
|
end
|
2012-09-19 12:35:45 -04:00
|
|
|
|
|
|
|
-- Set access restriction flag if service is allowed under certain restrictions only
|
2013-06-26 13:40:25 -04:00
|
|
|
if service ~= "" and service_tag_restricted[service] then
|
2012-09-19 12:35:45 -04:00
|
|
|
way.is_access_restricted = true
|
2013-06-26 13:40:25 -04:00
|
|
|
end
|
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
-- Set direction according to tags on way
|
2013-06-26 13:40:25 -04:00
|
|
|
way.direction = Way.bidirectional
|
2013-07-17 10:23:57 -04:00
|
|
|
if obey_oneway then
|
2013-06-26 13:40:25 -04:00
|
|
|
if oneway == "-1" then
|
2012-09-19 12:35:45 -04:00
|
|
|
way.direction = Way.opposite
|
2013-07-17 10:23:57 -04:00
|
|
|
elseif oneway == "yes" or
|
|
|
|
oneway == "1" or
|
|
|
|
oneway == "true" or
|
|
|
|
junction == "roundabout" or
|
|
|
|
(highway == "motorway_link" and oneway ~="no") or
|
|
|
|
(highway == "motorway" and oneway ~= "no")
|
|
|
|
then
|
|
|
|
way.direction = Way.oneway
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
2013-06-26 13:40:25 -04:00
|
|
|
end
|
2013-02-04 09:58:35 -05:00
|
|
|
|
|
|
|
-- Override speed settings if explicit forward/backward maxspeeds are given
|
2013-08-12 07:19:07 -04:00
|
|
|
if way.speed > 0 and maxspeed_forward ~= nil and maxspeed_forward > 0 then
|
2013-06-26 13:40:25 -04:00
|
|
|
if Way.bidirectional == way.direction then
|
|
|
|
way.backward_speed = way.speed
|
2013-02-04 09:58:35 -05:00
|
|
|
end
|
2013-06-26 13:40:25 -04:00
|
|
|
way.speed = maxspeed_forward
|
|
|
|
end
|
|
|
|
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
|
|
|
|
way.backward_speed = maxspeed_backward
|
|
|
|
end
|
2013-02-04 09:58:35 -05:00
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
-- Override general direction settings of there is a specific one for our mode of travel
|
2013-06-26 13:40:25 -04:00
|
|
|
if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then
|
2012-09-19 12:35:45 -04:00
|
|
|
way.ignore_in_grid = true
|
2013-06-26 13:40:25 -04:00
|
|
|
end
|
|
|
|
way.type = 1
|
2013-08-16 11:10:02 -04:00
|
|
|
return
|
2012-09-27 05:35:56 -04:00
|
|
|
end
|
2012-11-03 03:19:01 -04:00
|
|
|
|
|
|
|
-- 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
|