From 6b98b5f4c778caa6c15980cccd02a0d01e360539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Sat, 4 Oct 2014 14:12:14 +0200 Subject: [PATCH 1/2] Parse maxspeed value like FR:urban on car profile --- profiles/car.lua | 50 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) mode change 100755 => 100644 profiles/car.lua diff --git a/profiles/car.lua b/profiles/car.lua old mode 100755 new mode 100644 index 371740fe4..40a327b05 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -32,6 +32,36 @@ speed_profile = { ["default"] = 10 } +-- http://wiki.openstreetmap.org/wiki/Speed_limits +maxspeed_table_default = { + ["urban"] = 50, + ["rural"] = 90, + ["trunk"] = 110, + ["motorway"] = 130 +} + +-- List only exceptions +maxspeed_table = { + ["de:living_street"] = 7, + ["ru:living_street"] = 20, + ["ru:urban"] = 60, + ["ua:urban"] = 60, + ["at:rural"] = 100, + ["de:rural"] = 100, + ["at:trunk"] = 100, + ["cz:trunk"] = 0, + ["ro:trunk"] = 100, + ["cz:motorway"] = 0, + ["de:motorway"] = 0, + ["ru:motorway"] = 110, + ["gb:nsl_single"] = (60*1609)/1000, + ["gb:nsl_dual"] = (70*1609)/1000, + ["gb:motorway"] = (70*1609)/1000, + ["uk:nsl_single"] = (60*1609)/1000, + ["uk:nsl_dual"] = (70*1609)/1000, + ["uk:motorway"] = (70*1609)/1000 +} + traffic_signal_penalty = 2 -- End of globals @@ -74,11 +104,21 @@ local function parse_maxspeed(source) return 0 end local n = tonumber(source:match("%d*")) - if not n then - n = 0 - end - if string.match(source, "mph") or string.match(source, "mp/h") then - n = (n*1609)/1000; + if n then + if string.match(source, "mph") or string.match(source, "mp/h") then + n = (n*1609)/1000; + end + else + -- parse maxspeed like FR:urban + source = string.lower(source) + n = maxspeed_table[source] + if not n then + local highway_type = string.match(source, "%a%a:(%a+)") + n = maxspeed_table_default[highway_type] + if not n then + n = 0 + end + end end return n end From ec119a6d52dc7b60d67b07a07fb5c2411253edd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Sat, 4 Oct 2014 21:17:18 +0200 Subject: [PATCH 2/2] Add test for maxspeed like 'countrycode:zone type' for car profile --- features/car/maxspeed.feature | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/features/car/maxspeed.feature b/features/car/maxspeed.feature index 7bb45809d..4a548020c 100644 --- a/features/car/maxspeed.feature +++ b/features/car/maxspeed.feature @@ -8,31 +8,35 @@ OSRM will use 4/5 of the projected free-flow speed. Scenario: Car - Respect maxspeeds when lower that way type speed Given the node map - | a | b | c | + | a | b | c | d | And the ways | nodes | highway | maxspeed | | ab | trunk | | | bc | trunk | 60 | + | cd | trunk | FR:urban | When I route I should get | from | to | route | speed | | a | b | ab | 67 km/h | | b | c | bc | 48 km/h +- 1 | + | c | d | cd | 40 km/h | Scenario: Car - Do not ignore maxspeed when higher than way speed Given the node map - | a | b | c | + | a | b | c | d | And the ways - | nodes | highway | maxspeed | - | ab | residential | | - | bc | residential | 90 | + | nodes | highway | maxspeed | + | ab | residential | | + | bc | residential | 90 | + | cd | living_street | FR:urban | When I route I should get | from | to | route | speed | | a | b | ab | 20 km/h | | b | c | bc | 72 km/h +- 1 | + | c | d | cd | 40 km/h | Scenario: Car - Forward/backward maxspeed Given a grid size of 100 meters