From fcdee8f5d5f230c436922d5c7e266bbd20de6375 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sat, 27 Apr 2013 17:00:25 +0200 Subject: [PATCH 1/6] handle surfaces in bike profile --- profiles/bicycle.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index c87baad33..12c4a9484 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -65,6 +65,24 @@ route_speeds = { ["ferry"] = 5 } +surface_speeds = { + ["cobblestone:flattened"] = 10, + ["paving_stones"] = 10, + ["compacted"] = 10, + ["cobblestone"] = 6, + ["unpaved"] = 6, + ["fine_gravel"] = 6, + ["gravel"] = 6, + ["fine_gravel"] = 6, + ["pebbelstone"] = 6, + ["ground"] = 6, + ["dirt"] = 6, + ["earth"] = 6, + ["grass"] = 6, + ["mud"] = 3, + ["sand"] = 3 +} + take_minimum_of_speeds = true obey_oneway = true obey_bollards = false @@ -158,6 +176,7 @@ function way_function (way) local service = way.tags:Find("service") local area = way.tags:Find("area") local foot = way.tags:Find("foot") + local surface = way.tags:Find("surface") -- name if "" ~= ref then @@ -286,6 +305,15 @@ function way_function (way) elseif cycleway_right and 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 + end -- maxspeed -- TODO: maxspeed of backward direction From 7ac901cb08bd8cd814951c8c851b0acb7769221c Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sat, 27 Apr 2013 17:01:43 +0200 Subject: [PATCH 2/6] update rake task to work with bins in /build --- Rakefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index e465d636b..91eaf063e 100644 --- a/Rakefile +++ b/Rakefile @@ -120,9 +120,9 @@ end desc "Reprocess OSM data." task :process => :setup do Dir.chdir DATA_FOLDER do - raise "Error while extracting data." unless system "../osrm-extract #{osm_data_area_name}.osm.pbf #{PROFILES_FOLDER}/#{PROFILE}.lua" + raise "Error while extracting data." unless system "../#{BUILD_FOLDER}/osrm-extract #{osm_data_area_name}.osm.pbf #{PROFILES_FOLDER}/#{PROFILE}.lua" puts - raise "Error while preparing data." unless system "../osrm-prepare #{osm_data_area_name}.osrm #{osm_data_area_name}.osrm.restrictions #{PROFILES_FOLDER}/#{PROFILE}.lua" + raise "Error while preparing data." unless system "../#{BUILD_FOLDER}/osrm-prepare #{osm_data_area_name}.osrm #{osm_data_area_name}.osrm.restrictions #{PROFILES_FOLDER}/#{PROFILE}.lua" puts end end @@ -130,14 +130,14 @@ end desc "Extract OSM data." task :extract => :setup do Dir.chdir DATA_FOLDER do - raise "Error while extracting data." unless system "../osrm-extract #{osm_data_area_name}.osm.pbf ../profiles/#{PROFILE}.lua" + raise "Error while extracting data." unless system "../#{BUILD_FOLDER}/osrm-extract #{osm_data_area_name}.osm.pbf ../profiles/#{PROFILE}.lua" end end desc "Prepare OSM data." task :prepare => :setup do Dir.chdir DATA_FOLDER do - raise "Error while preparing data." unless system "../osrm-prepare #{osm_data_area_name}.osrm #{osm_data_area_name}.osrm.restrictions ../profiles/#{PROFILE}.lua" + raise "Error while preparing data." unless system "../#{BUILD_FOLDER}/osrm-prepare #{osm_data_area_name}.osrm #{osm_data_area_name}.osrm.restrictions ../profiles/#{PROFILE}.lua" end end @@ -157,7 +157,7 @@ desc "Run the routing server in the terminal. Press Ctrl-C to stop." task :run => :setup do Dir.chdir DATA_FOLDER do write_server_ini osm_data_area_name - system "../osrm-routed" + system "../#{BUILD_FOLDER}/osrm-routed" end end @@ -166,7 +166,7 @@ task :up => :setup do Dir.chdir DATA_FOLDER do abort("Already up.") if up? write_server_ini osm_data_area_name - pipe = IO.popen('../osrm-routed 1>>osrm-routed.log 2>>osrm-routed.log') + pipe = IO.popen("../#{BUILD_FOLDER}/osrm-routed 1>>osrm-routed.log 2>>osrm-routed.log") timeout = 5 (timeout*10).times do begin From 3afcd31f61b4370a72db18fb3b2577b99f19b907 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sun, 28 Apr 2013 11:42:21 +0200 Subject: [PATCH 3/6] bike: use both ref&name when available --- features/bicycle/ref.feature | 41 ++++++++++++++++++++++++++++++++++++ profiles/bicycle.lua | 6 ++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 features/bicycle/ref.feature diff --git a/features/bicycle/ref.feature b/features/bicycle/ref.feature new file mode 100644 index 000000000..da1585902 --- /dev/null +++ b/features/bicycle/ref.feature @@ -0,0 +1,41 @@ +@routing @bicycle @ref @name +Feature: Bike - Way ref + + Background: + Given the profile "bicycle" + + Scenario: Bike - Way with both name and ref + Given the node map + | a | b | + + And the ways + | nodes | name | ref | + | ab | Utopia Drive | E7 | + + When I route I should get + | from | to | route | + | a | b | Utopia Drive / E7 | + + Scenario: Bike - Way with only ref + Given the node map + | a | b | + + And the ways + | nodes | name | ref | + | ab | | E7 | + + When I route I should get + | from | to | route | + | a | b | E7 | + + Scenario: Bike - Way with only name + Given the node map + | a | b | + + And the ways + | nodes | name | + | ab | Utopia Drive | + + When I route I should get + | from | to | route | + | a | b | Utopia Drive | diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 12c4a9484..98d03c83d 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -179,8 +179,10 @@ function way_function (way) local surface = way.tags:Find("surface") -- name - if "" ~= ref then - way.name = ref + if "" ~= ref and "" ~= name then + way.name = name .. ' / ' .. ref + elseif "" ~= ref then + way.name = ref elseif "" ~= name then way.name = name else From 67addfdb373700b34da0945af0e4d5f8ada01d7d Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sun, 5 May 2013 11:14:09 +0200 Subject: [PATCH 4/6] test via points --- features/step_definitions/routability.rb | 8 +++- features/step_definitions/routing.rb | 31 ++++++++++---- features/support/route.rb | 17 ++++---- features/testbot/via.feature | 52 ++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 features/testbot/via.feature diff --git a/features/step_definitions/routability.rb b/features/step_definitions/routability.rb index 0af027a98..565c7445b 100644 --- a/features/step_definitions/routability.rb +++ b/features/step_definitions/routability.rb @@ -12,9 +12,13 @@ Then /^routability should be$/ do |table| ['forw','backw','bothw'].each do |direction| if table.headers.include? direction if direction == 'forw' || direction == 'bothw' - response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}") + a = Location.new ORIGIN[0]+(1+WAY_SPACING*i)*@zoom, ORIGIN[1] + b = Location.new ORIGIN[0]+(3+WAY_SPACING*i)*@zoom, ORIGIN[1] + response = request_route [a,b] elsif direction == 'backw' || direction == 'bothw' - response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}") + a = Location.new ORIGIN[0]+(3+WAY_SPACING*i)*@zoom, ORIGIN[1] + b = Location.new ORIGIN[0]+(1+WAY_SPACING*i)*@zoom, ORIGIN[1] + response = request_route [a,b] end want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts got[direction] = route_status response diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index 4c4584379..13c8b6a04 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -3,13 +3,28 @@ When /^I route I should get$/ do |table| actual = [] OSRMLauncher.new do table.hashes.each_with_index do |row,ri| - from_node = find_node_by_name row['from'] - raise "*** unknown from-node '#{row['from']}" unless from_node - to_node = find_node_by_name row['to'] - raise "*** unknown to-node '#{row['to']}" unless to_node - - got = {'from' => row['from'], 'to' => row['to'] } - + waypoints = [] + if row['from'] and row['to'] + node = find_node_by_name(row['from']) + raise "*** unknown from-node '#{row['from']}" unless node + waypoints << node + + node = find_node_by_name(row['to']) + raise "*** unknown to-node '#{row['to']}" unless node + waypoints << node + + got = {'from' => row['from'], 'to' => row['to'] } + elsif row['waypoints'] + row['waypoints'].split(',').each do |n| + node = find_node_by_name(n.strip) + raise "*** unknown waypoint node '#{n.strip}" unless node + waypoints << node + end + got = {'waypoints' => row['waypoints'] } + else + raise "*** no waypoints" + end + params = {} row.each_pair do |k,v| if k =~ /param:(.*)/ @@ -22,7 +37,7 @@ When /^I route I should get$/ do |table| end end - response = request_route("#{from_node.lat},#{from_node.lon}", "#{to_node.lat},#{to_node.lon}", params) + response = request_route(waypoints, params) if response.code == "200" && response.body.empty? == false json = JSON.parse response.body if json['status'] == 0 diff --git a/features/support/route.rb b/features/support/route.rb index 0d67bc076..86ea263fd 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -8,16 +8,15 @@ class Hash def to_param(namespace = nil) collect do |key, value| "#{key}=#{value}" - end.sort * '&' + end.sort end end -def request_path path, params={} - if params.any? - uri = URI.parse ["#{HOST}/#{path}",params.to_param].join('&') - else - uri = URI.parse "#{HOST}/#{path}" - end +def request_path path, waypoints=[], options={} + locs = waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" } + params = (locs + options.to_param).join('&') + params = nil if params=="" + uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?') Timeout.timeout(REQUEST_TIMEOUT) do Net::HTTP.get_response uri end @@ -27,9 +26,9 @@ rescue Timeout::Error raise "*** osrm-routed did not respond." end -def request_route a,b, params={} +def request_route waypoints, params={} defaults = { 'output' => 'json', 'instructions' => true, 'alt' => true } - request_path "viaroute?loc=#{a}&loc=#{b}", defaults.merge(params) + request_path "viaroute", waypoints, defaults.merge(params) end def parse_response response diff --git a/features/testbot/via.feature b/features/testbot/via.feature new file mode 100644 index 000000000..0ec365daf --- /dev/null +++ b/features/testbot/via.feature @@ -0,0 +1,52 @@ +@routing @testbot @via +Feature: Via points + + Background: + Given the profile "testbot" + + Scenario: Simple via point + Given the node map + | a | b | c | + + And the ways + | nodes | + | abc | + + When I route I should get + | waypoints | route | + | a,b,c | abc | + | c,b,a | abc | + + Scenario: Via point at a dead end + Given the node map + | a | b | c | + | | d | | + + And the ways + | nodes | + | abc | + | bd | + + When I route I should get + | waypoints | route | + | a,d,c | abc,bd,bd,abc | + | c,d,a | abc,bd,bd,abc | + + Scenario: Multiple via points + Given the node map + | a | | c | | e | | + | | b | | d | | f | + + And the ways + | nodes | + | ace | + | bdf | + | ab | + | bc | + | cd | + | de | + | ef | + + When I route I should get + | waypoints | route | + | a,b,c,d,e,f | ab,bc,cd,de,ef | From 411603ea0346d307e365104aa2a4839e319eaad1 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Tue, 7 May 2013 14:12:27 +0200 Subject: [PATCH 5/6] new geofabrik download url --- Rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 91eaf063e..ccbb0cb9a 100644 --- a/Rakefile +++ b/Rakefile @@ -102,8 +102,8 @@ desc "Download OSM data." task :download => :setup do Dir.mkdir "#{DATA_FOLDER}" unless File.exist? "#{DATA_FOLDER}" puts "Downloading..." - puts "curl http://download.geofabrik.de/openstreetmap/europe/#{osm_data_country}.osm.pbf -o #{DATA_FOLDER}/#{osm_data_country}.osm.pbf" - raise "Error while downloading data." unless system "curl http://download.geofabrik.de/openstreetmap/europe/#{osm_data_country}.osm.pbf -o #{DATA_FOLDER}/#{osm_data_country}.osm.pbf" + puts "curl http://download.geofabrik.de/europe/#{osm_data_country}-latest.osm.pbf -o #{DATA_FOLDER}/#{osm_data_country}.osm.pbf" + raise "Error while downloading data." unless system "curl http://download.geofabrik.de/europe/#{osm_data_country}-latest.osm.pbf -o #{DATA_FOLDER}/#{osm_data_country}.osm.pbf" if osm_data_area_bbox puts "Cropping and converting to protobuffer..." raise "Error while cropping data." unless system "osmosis --read-pbf file=#{DATA_FOLDER}/#{osm_data_country}.osm.pbf --bounding-box #{osm_data_area_bbox} --write-pbf file=#{DATA_FOLDER}/#{osm_data_area_name}.osm.pbf omitmetadata=true" From 9588ef00a55519b6b75250ee782743fb00038761 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Fri, 10 May 2013 17:17:24 +0200 Subject: [PATCH 6/6] use alt=false during cucumber testing --- features/bicycle/area.feature | 16 ++++++++-------- features/support/route.rb | 2 +- features/testbot/bad.feature | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/features/bicycle/area.feature b/features/bicycle/area.feature index 5f23e182d..541f02631 100644 --- a/features/bicycle/area.feature +++ b/features/bicycle/area.feature @@ -41,14 +41,14 @@ Feature: Bike - Squares and other areas When I route I should get | from | to | route | - | a | b | | - | a | d | | - | b | c | | - | c | b | | - | c | d | | - | d | c | | - | d | a | | - | a | d | | + | a | b | xa | + | a | d | xa | + | b | c | xa | + | c | b | xa | + | c | d | xa | + | d | c | xa | + | d | a | xa | + | a | d | xa | @parking Scenario: Bike - parking areas diff --git a/features/support/route.rb b/features/support/route.rb index 86ea263fd..9cfbbfa14 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -27,7 +27,7 @@ rescue Timeout::Error end def request_route waypoints, params={} - defaults = { 'output' => 'json', 'instructions' => true, 'alt' => true } + defaults = { 'output' => 'json', 'instructions' => true, 'alt' => false } request_path "viaroute", waypoints, defaults.merge(params) end diff --git a/features/testbot/bad.feature b/features/testbot/bad.feature index 77a660776..f57e4dd17 100644 --- a/features/testbot/bad.feature +++ b/features/testbot/bad.feature @@ -26,7 +26,8 @@ Feature: Handle bad data in a graceful manner When I route I should get | from | to | route | | a | b | ab | - + + @todo Scenario: Start/end point at the same location Given the node map | a | b |