2017-05-18 08:27:28 -04:00
|
|
|
-- Rasterbot with interpolation profile
|
2015-05-29 20:28:29 -04:00
|
|
|
|
2017-05-18 08:27:28 -04:00
|
|
|
functions = require('rasterbot')
|
2017-06-12 17:46:29 -04:00
|
|
|
|
2017-05-18 08:27:28 -04:00
|
|
|
functions.process_segment = function(profile, segment)
|
|
|
|
local sourceData = raster:interpolate(profile.raster_source, segment.source.lon, segment.source.lat)
|
|
|
|
local targetData = raster:interpolate(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
|
2016-05-12 12:50:10 -04:00
|
|
|
local slope = math.abs(sourceData.datum - targetData.datum) / segment.distance
|
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(" was speed: " .. segment.duration .. "\n")
|
2015-05-29 20:28:29 -04:00
|
|
|
|
2016-05-12 12:50:10 -04:00
|
|
|
scaled_weight = scaled_weight / (1 - (slope * 5))
|
|
|
|
io.write(" new weight: " .. scaled_weight .. "\n")
|
|
|
|
scaled_duration = scaled_duration / (1 - (slope * 5))
|
|
|
|
io.write(" new speed: " .. 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 functions
|