2015-05-29 20:28:29 -04:00
|
|
|
-- Rasterbot profile
|
|
|
|
|
2017-05-18 08:27:28 -04:00
|
|
|
api_version = 2
|
2017-03-29 17:48:57 -04:00
|
|
|
|
2017-05-18 08:27:28 -04:00
|
|
|
function setup()
|
|
|
|
local raster_path = os.getenv('OSRM_RASTER_SOURCE') or "rastersource.asc"
|
2017-06-12 17:46:29 -04:00
|
|
|
|
2017-05-18 08:27:28 -04:00
|
|
|
return {
|
|
|
|
properties = {
|
|
|
|
force_split_edges = true,
|
|
|
|
process_call_tagless_node = false,
|
|
|
|
},
|
|
|
|
|
|
|
|
raster_source = raster:load(
|
|
|
|
raster_path,
|
|
|
|
0, -- lon_min
|
|
|
|
0.1, -- lon_max
|
|
|
|
0, -- lat_min
|
|
|
|
0.1, -- lat_max
|
|
|
|
5, -- nrows
|
|
|
|
4 -- ncols
|
|
|
|
)
|
|
|
|
}
|
2015-05-29 20:28:29 -04:00
|
|
|
end
|
|
|
|
|
2017-05-18 08:27:28 -04:00
|
|
|
-- Minimalist process_ways in order to test source_ and process_segments
|
|
|
|
function process_way (profile, way, result)
|
2015-05-29 20:28:29 -04:00
|
|
|
local highway = way:get_value_by_key("highway")
|
|
|
|
local name = way:get_value_by_key("name")
|
|
|
|
|
|
|
|
if name then
|
|
|
|
result.name = name
|
|
|
|
end
|
|
|
|
|
2016-03-30 18:29:47 -04:00
|
|
|
result.forward_mode = mode.cycling
|
|
|
|
result.backward_mode = mode.cycling
|
|
|
|
|
2015-05-29 20:28:29 -04:00
|
|
|
result.forward_speed = 15
|
|
|
|
result.backward_speed = 15
|
|
|
|
end
|
|
|
|
|
2017-05-18 08:27:28 -04:00
|
|
|
function process_segment (profile, segment)
|
|
|
|
local sourceData = raster:query(profile.raster_source, segment.source.lon, segment.source.lat)
|
|
|
|
local targetData = raster:query(profile.raster_source, segment.target.lon, segment.target.lat)
|
2016-03-23 10:40:11 -04:00
|
|
|
io.write("evaluating segment: " .. sourceData.datum .. " " .. targetData.datum .. "\n")
|
2015-05-29 20:28:29 -04:00
|
|
|
local invalid = sourceData.invalid_data()
|
2016-05-12 12:50:10 -04:00
|
|
|
local scaled_weight = segment.weight
|
|
|
|
local scaled_duration = segment.duration
|
2015-05-29 20:28:29 -04:00
|
|
|
|
|
|
|
if sourceData.datum ~= invalid and targetData.datum ~= invalid then
|
2017-03-29 07:43:47 -04:00
|
|
|
local slope = (targetData.datum - sourceData.datum) / segment.distance
|
2016-05-12 12:50:10 -04:00
|
|
|
scaled_weight = scaled_weight / (1.0 - (slope * 5.0))
|
|
|
|
scaled_duration = scaled_duration / (1.0 - (slope * 5.0))
|
2016-03-23 10:40:11 -04:00
|
|
|
io.write(" slope: " .. slope .. "\n")
|
2016-05-12 12:50:10 -04:00
|
|
|
io.write(" was weight: " .. segment.weight .. "\n")
|
|
|
|
io.write(" new weight: " .. scaled_weight .. "\n")
|
|
|
|
io.write(" was duration: " .. segment.duration .. "\n")
|
|
|
|
io.write(" new duration: " .. scaled_duration .. "\n")
|
2015-05-29 20:28:29 -04:00
|
|
|
end
|
2016-05-12 12:50:10 -04:00
|
|
|
|
|
|
|
segment.weight = scaled_weight
|
|
|
|
segment.duration = scaled_duration
|
2015-05-29 20:28:29 -04:00
|
|
|
end
|
2017-05-18 08:27:28 -04:00
|
|
|
|
|
|
|
return {
|
|
|
|
setup = setup,
|
|
|
|
process_way = process_way,
|
|
|
|
process_segment = process_segment
|
|
|
|
}
|