diff --git a/profiles/car.lua b/profiles/car.lua index 7a6999d3e..ff7c37971 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -11,10 +11,10 @@ service_tag_restricted = { ["parking_aisle"] = true } ignore_in_grid = { ["ferry"] = true } restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" } -speed_profile = { - ["motorway"] = 90, - ["motorway_link"] = 75, - ["trunk"] = 85, +speed_profile = { + ["motorway"] = 90, + ["motorway_link"] = 75, + ["trunk"] = 85, ["trunk_link"] = 70, ["primary"] = 65, ["primary_link"] = 60, @@ -43,7 +43,7 @@ u_turn_penalty = 20 -- End of globals function get_exceptions(vector) - for i,v in ipairs(restriction_exception_tags) do + for i,v in ipairs(restriction_exception_tags) do vector:Add(v) end end @@ -66,13 +66,13 @@ function node_function (node) local barrier = node.tags:Find ("barrier") local access = Access.find_access_tag(node, access_tags_hierachy) local traffic_signal = node.tags:Find("highway") - + --flag node if it carries a traffic light - + if traffic_signal == "traffic_signals" then - node.traffic_light = true; + node.traffic_light = true; end - + -- parse access and barrier tags if access and access ~= "" then if access_tag_blacklist[access] then @@ -90,35 +90,40 @@ end function way_function (way) - -- First, get the properties of each way that we come across - 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 oneway = way.tags:Find("oneway") - local cycleway = way.tags:Find("cycleway") - local duration = way.tags:Find("duration") - local service = way.tags:Find("service") - local area = way.tags:Find("area") - local access = Access.find_access_tag(way, access_tags_hierachy) + -- we dont route over areas + local area = way.tags:Find("area") + if ignore_areas and ("yes" == area) then + return 0 + end + + -- check if oneway tag is unsupported + local oneway = way.tags:Find("oneway") + if "reversible" == oneway then + return 0 + end + + -- 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 + return 0 + end -- 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") - if ignore_areas and ("yes" == area) then - return 0 - end - - -- Check if we are allowed to access the way - if access_tag_blacklist[access] then - return 0 - end - -- Set the name that will be used for instructions + -- Set the name that will be used for instructions if "" ~= ref then way.name = ref elseif "" ~= name then @@ -126,87 +131,82 @@ function way_function (way) -- else -- way.name = highway -- if no name exists, use way type end - + if "roundabout" == junction then way.roundabout = true; end -- Handling ferries and piers if (speed_profile[route] ~= nil and speed_profile[route] > 0) then - 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 + 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 end - + -- Set the avg speed on the way if it is accessible by road class if (speed_profile[highway] ~= nil and way.speed == -1 ) then - 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) + 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) end end -- Set the avg speed on ways that are marked accessible - if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then - if 0 == maxspeed then - maxspeed = math.huge - end - way.speed = math.min(speed_profile["default"], maxspeed) + if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then + if 0 == maxspeed then + maxspeed = math.huge end + way.speed = math.min(speed_profile["default"], maxspeed) + end -- Set access restriction flag if access is allowed under certain restrictions only - if access ~= "" and access_tag_restricted[access] then - way.is_access_restricted = true - end + if access ~= "" and access_tag_restricted[access] then + way.is_access_restricted = true + end -- Set access restriction flag if service is allowed under certain restrictions only - if service ~= "" and service_tag_restricted[service] then + if service ~= "" and service_tag_restricted[service] then way.is_access_restricted = true - end - + end + -- Set direction according to tags on way - if obey_oneway then - if oneway == "no" or oneway == "0" or oneway == "false" then - way.direction = Way.bidirectional - elseif oneway == "-1" then + way.direction = Way.bidirectional + if obey_oneway then + if oneway == "-1" then way.direction = Way.opposite - elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then - way.direction = Way.oneway - else - way.direction = Way.bidirectional - end - else - way.direction = Way.bidirectional + elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then + way.direction = Way.oneway end + end -- Override speed settings if explicit forward/backward maxspeeds are given - if maxspeed_forward ~= nil and maxspeed_forward > 0 then - if Way.bidirectional == way.direction then - way.backward_speed = way.speed - end - way.speed = maxspeed_forward - end - if maxspeed_backward ~= nil and maxspeed_backward > 0 then - way.backward_speed = maxspeed_backward + if maxspeed_forward ~= nil and maxspeed_forward > 0 then + if Way.bidirectional == way.direction then + way.backward_speed = way.speed end + way.speed = maxspeed_forward + end + if maxspeed_backward ~= nil and maxspeed_backward > 0 then + way.backward_speed = maxspeed_backward + end -- Override general direction settings of there is a specific one for our mode of travel - - if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then + if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then way.ignore_in_grid = true - end - way.type = 1 + end + + way.type = 1 return 1 end diff --git a/profiles/lib/access.lua b/profiles/lib/access.lua index a1e2fcf4d..af9570bd6 100644 --- a/profiles/lib/access.lua +++ b/profiles/lib/access.lua @@ -3,9 +3,8 @@ local ipairs = ipairs module "Access" function find_access_tag(source,access_tags_hierachy) - for i,v in ipairs(access_tags_hierachy) do - local tag = source.tags:Find(v) - if tag ~= '' then + for i,v in ipairs(access_tags_hierachy) do + if source.tags:Find(v) ~= '' then return tag end end