[OSRM-talk] further simplifying profiles
Jens Thiele
karme at karme.de
Tue Jun 18 07:57:05 UTC 2013
is there really a need to discriminate between "no tag" and "tag with
empty string" value in the profiles?
are there any osm tags where key presence and empty value has a meaning?
if not one could change the HashTable Find to return an empty string (or
add a Find variant doing this)
how this could look like
(this version just does it in lua, untested):
diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua
index 98d03c8..d80f197 100644
--- a/profiles/bicycle.lua
+++ b/profiles/bicycle.lua
@@ -131,18 +131,20 @@ end
function way_function (way)
-- initial routability check, filters out buildings, boundaries, etc
- local highway = way.tags:Find("highway")
- local route = way.tags:Find("route")
- local man_made = way.tags:Find("man_made")
- local railway = way.tags:Find("railway")
- local amenity = way.tags:Find("amenity")
- local public_transport = way.tags:Find("public_transport")
- if (not highway or highway == '') and
- (not route or route == '') and
- (not railway or railway=='') and
- (not amenity or amenity=='') and
- (not man_made or man_made=='') and
- (not public_transport or public_transport=='')
+ local tag = function(x) return way.tags:Find(x) or "" end
+ local highway = tag("highway")
+ local route = tag("route")
+ local man_made = tag("man_made")
+ local railway = tag("railway")
+ local amenity = tag("amenity")
+ local public_transport = tag("public_transport")
+
+ if (highway == '') and
+ (route == '') and
+ (railway=='') and
+ (amenity=='') and
+ (man_made=='') and
+ (public_transport=='')
then
return 0
end
@@ -160,23 +162,23 @@ function way_function (way)
-- other tags
- local name = way.tags:Find("name")
- local ref = way.tags:Find("ref")
- local junction = way.tags:Find("junction")
- local maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") )
- local maxspeed_forward = parseMaxspeed(way.tags:Find( "maxspeed:forward"))
- local maxspeed_backward = parseMaxspeed(way.tags:Find( "maxspeed:backward"))
- local barrier = way.tags:Find("barrier")
- local oneway = way.tags:Find("oneway")
- local onewayClass = way.tags:Find("oneway:bicycle")
- local cycleway = way.tags:Find("cycleway")
- local cycleway_left = way.tags:Find("cycleway:left")
- local cycleway_right = way.tags:Find("cycleway:right")
- local duration = way.tags:Find("duration")
- local service = way.tags:Find("service")
- local area = way.tags:Find("area")
- local foot = way.tags:Find("foot")
- local surface = way.tags:Find("surface")
+ local name = tag("name")
+ local ref = tag("ref")
+ local junction = tag("junction")
+ local maxspeed = parseMaxspeed(tag ( "maxspeed") )
+ local maxspeed_forward = parseMaxspeed(tag( "maxspeed:forward"))
+ local maxspeed_backward = parseMaxspeed(tag( "maxspeed:backward"))
+ local barrier = tag("barrier")
+ local oneway = tag("oneway")
+ local onewayClass = tag("oneway:bicycle")
+ local cycleway = tag("cycleway")
+ local cycleway_left = tag("cycleway:left")
+ local cycleway_right = tag("cycleway:right")
+ local duration = tag("duration")
+ local service = tag("service")
+ local area = tag("area")
+ local foot = tag("foot")
+ local surface = tag("surface")
-- name
if "" ~= ref and "" ~= name then
@@ -200,25 +202,25 @@ function way_function (way)
else
way.speed = route_speeds[route]
end
- elseif railway and platform_speeds[railway] then
+ elseif platform_speeds[railway] then
-- railway platforms (old tagging scheme)
way.speed = platform_speeds[railway]
elseif platform_speeds[public_transport] then
-- public_transport platforms (new tagging platform)
way.speed = platform_speeds[public_transport]
- elseif railway and railway_speeds[railway] then
+ elseif railway_speeds[railway] then
-- railways
- if access and access_tag_whitelist[access] then
+ if access_tag_whitelist[access] then
way.speed = railway_speeds[railway]
way.direction = Way.bidirectional
end
- elseif amenity and amenity_speeds[amenity] then
+ elseif amenity_speeds[amenity] then
-- parking areas
way.speed = amenity_speeds[amenity]
elseif bicycle_speeds[highway] then
-- regular ways
way.speed = bicycle_speeds[highway]
- elseif access and access_tag_whitelist[access] then
+ elseif access_tag_whitelist[access] then
-- unknown way, but valid access tag
way.speed = default_speed
else
@@ -229,7 +231,7 @@ function way_function (way)
if pedestrian_speeds[highway] then
-- pedestrian-only ways and areas
way.speed = pedestrian_speeds[highway]
- elseif man_made and man_made_speeds[man_made] then
+ elseif man_made_speeds[man_made] then
-- man made structures
way.speed = man_made_speeds[man_made]
elseif foot == 'yes' then
@@ -254,7 +256,7 @@ function way_function (way)
way.direction = Way.opposite
elseif oneway == "no" or oneway == "0" or oneway == "false" then
way.direction = Way.bidirectional
- elseif cycleway and string.find(cycleway, "opposite") == 1 then
+ elseif string.find(cycleway, "opposite") == 1 then
if impliedOneway then
way.direction = Way.opposite
else
@@ -262,13 +264,13 @@ function way_function (way)
end
elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then
way.direction = Way.bidirectional
- elseif cycleway_left and cycleway_tags[cycleway_left] then
+ elseif cycleway_tags[cycleway_left] then
if impliedOneway then
way.direction = Way.opposite
else
way.direction = Way.bidirectional
end
- elseif cycleway_right and cycleway_tags[cycleway_right] then
+ elseif cycleway_tags[cycleway_right] then
if impliedOneway then
way.direction = Way.oneway
else
@@ -300,21 +302,19 @@ function way_function (way)
-- cycleways
- if cycleway and cycleway_tags[cycleway] then
+ if cycleway_tags[cycleway] then
way.speed = bicycle_speeds["cycleway"]
- elseif cycleway_left and cycleway_tags[cycleway_left] then
+ elseif cycleway_tags[cycleway_left] then
way.speed = bicycle_speeds["cycleway"]
- elseif cycleway_right and cycleway_tags[cycleway_right] then
+ elseif cycleway_tags[cycleway_right] then
way.speed = bicycle_speeds["cycleway"]
end
-- surfaces
- if surface then
- surface_speed = surface_speeds[surface]
- if surface_speed then
- way.speed = math.min(way.speed, surface_speed)
- way.backward_speed = math.min(way.backward_speed, surface_speed)
- end
+ local surface_speed=surface_speeds[surface]
+ if surface_speeds then
+ way.speed = math.min(way.speed, surface_speed)
+ way.backward_speed = math.min(way.backward_speed, surface_speed)
end
-- maxspeed
More information about the OSRM-talk
mailing list