diff --git a/features/raster/weights.feature b/features/raster/weights.feature index 829407101..1339bd249 100644 --- a/features/raster/weights.feature +++ b/features/raster/weights.feature @@ -61,7 +61,7 @@ Feature: Raster - weights | d | b | de,eb | 10 km/h | Scenario: Weighting based on raster sources - Given the profile "rasterbot-interp" + Given the profile "rasterbotinterp" When I run "osrm-extract {osm_base}.osm -p {profile}" Then stdout should contain "evaluating segment" And I run "osrm-contract {osm_base}.osm" diff --git a/include/extractor/raster_source.hpp b/include/extractor/raster_source.hpp index c5d276f87..4cc7e0202 100644 --- a/include/extractor/raster_source.hpp +++ b/include/extractor/raster_source.hpp @@ -2,6 +2,7 @@ #define RASTER_SOURCE_HPP #include "util/exception.hpp" +#include "util/coordinate.hpp" #include #include @@ -141,9 +142,9 @@ class SourceContainer std::size_t nrows, std::size_t ncols); - RasterDatum getRasterDataFromSource(unsigned int source_id, int lon, int lat); + RasterDatum getRasterDataFromSource(unsigned int source_id, double lon, double lat); - RasterDatum getRasterInterpolateFromSource(unsigned int source_id, int lon, int lat); + RasterDatum getRasterInterpolateFromSource(unsigned int source_id, double lon, double lat); private: std::vector LoadedSources; diff --git a/profiles/rasterbot.lua b/profiles/rasterbot.lua index f9fd527b9..fd9dcda64 100644 --- a/profiles/rasterbot.lua +++ b/profiles/rasterbot.lua @@ -13,6 +13,9 @@ function way_function (way, result) result.name = name end + result.forward_mode = mode.cycling + result.backward_mode = mode.cycling + result.forward_speed = 15 result.backward_speed = 15 end @@ -30,6 +33,7 @@ function source_function () end function segment_function (source, target, distance, weight) + io.write("lookup for " .. source.lon .. "," .. source.lat .. " " .. target.lon .. "," .. target.lat .. "\n") local sourceData = sources:query(raster_source, source.lon, source.lat) local targetData = sources:query(raster_source, target.lon, target.lat) io.write("evaluating segment: " .. sourceData.datum .. " " .. targetData.datum .. "\n") diff --git a/profiles/rasterbot-interp.lua b/profiles/rasterbotinterp.lua similarity index 94% rename from profiles/rasterbot-interp.lua rename to profiles/rasterbotinterp.lua index 1b2969ea6..8266b07c4 100644 --- a/profiles/rasterbot-interp.lua +++ b/profiles/rasterbotinterp.lua @@ -13,6 +13,9 @@ function way_function (way, result) result.name = name end + result.forward_mode = mode.cycling + result.backward_mode = mode.cycling + result.forward_speed = 15 result.backward_speed = 15 end diff --git a/src/extractor/raster_source.cpp b/src/extractor/raster_source.cpp index 2d369cb44..16e41f987 100644 --- a/src/extractor/raster_source.cpp +++ b/src/extractor/raster_source.cpp @@ -3,8 +3,6 @@ #include "util/simple_logger.hpp" #include "util/timing_util.hpp" -#include "osrm/coordinate.hpp" - #include namespace osrm @@ -84,10 +82,10 @@ int SourceContainer::loadRasterSource(const std::string &path_string, std::size_t nrows, std::size_t ncols) { - const auto _xmin = static_cast(xmin * COORDINATE_PRECISION); - const auto _xmax = static_cast(xmax * COORDINATE_PRECISION); - const auto _ymin = static_cast(ymin * COORDINATE_PRECISION); - const auto _ymax = static_cast(ymax * COORDINATE_PRECISION); + const auto _xmin = static_cast(util::toFixed(util::FloatLongitude(xmin))); + const auto _xmax = static_cast(util::toFixed(util::FloatLongitude(xmax))); + const auto _ymin = static_cast(util::toFixed(util::FloatLatitude(ymin))); + const auto _ymax = static_cast(util::toFixed(util::FloatLatitude(ymax))); const auto itr = LoadedSourcePaths.find(path_string); if (itr != LoadedSourcePaths.end()) @@ -122,38 +120,40 @@ int SourceContainer::loadRasterSource(const std::string &path_string, } // External function for looking up nearest data point from a specified source -RasterDatum SourceContainer::getRasterDataFromSource(unsigned int source_id, int lon, int lat) +RasterDatum SourceContainer::getRasterDataFromSource(unsigned int source_id, double lon, double lat) { if (LoadedSources.size() < source_id + 1) { throw util::exception("error reading: no such loaded source"); } - BOOST_ASSERT(lat < (90 * COORDINATE_PRECISION)); - BOOST_ASSERT(lat > (-90 * COORDINATE_PRECISION)); - BOOST_ASSERT(lon < (180 * COORDINATE_PRECISION)); - BOOST_ASSERT(lon > (-180 * COORDINATE_PRECISION)); + BOOST_ASSERT(lat < 90); + BOOST_ASSERT(lat > -90); + BOOST_ASSERT(lon < 180); + BOOST_ASSERT(lon > -180); const auto &found = LoadedSources[source_id]; - return found.getRasterData(lon, lat); + return found.getRasterData(static_cast(util::toFixed(util::FloatLongitude(lon))), + static_cast(util::toFixed(util::FloatLatitude(lat)))); } // External function for looking up interpolated data from a specified source RasterDatum -SourceContainer::getRasterInterpolateFromSource(unsigned int source_id, int lon, int lat) +SourceContainer::getRasterInterpolateFromSource(unsigned int source_id, double lon, double lat) { if (LoadedSources.size() < source_id + 1) { throw util::exception("error reading: no such loaded source"); } - BOOST_ASSERT(lat < (90 * COORDINATE_PRECISION)); - BOOST_ASSERT(lat > (-90 * COORDINATE_PRECISION)); - BOOST_ASSERT(lon < (180 * COORDINATE_PRECISION)); - BOOST_ASSERT(lon > (-180 * COORDINATE_PRECISION)); + BOOST_ASSERT(lat < 90); + BOOST_ASSERT(lat > -90); + BOOST_ASSERT(lon < 180); + BOOST_ASSERT(lon > -180); const auto &found = LoadedSources[source_id]; - return found.getRasterInterpolate(lon, lat); + return found.getRasterInterpolate(static_cast(util::toFixed(util::FloatLongitude(lon))), + static_cast(util::toFixed(util::FloatLatitude(lat)))); } } } diff --git a/unit_tests/extractor/raster_source.cpp b/unit_tests/extractor/raster_source.cpp index 5ce93514e..1c66f12d3 100644 --- a/unit_tests/extractor/raster_source.cpp +++ b/unit_tests/extractor/raster_source.cpp @@ -16,12 +16,12 @@ int normalize(double coord) { return static_cast(coord * COORDINATE_PRECISI #define CHECK_QUERY(source_id, lon, lat, expected) \ BOOST_CHECK_EQUAL( \ - sources.getRasterDataFromSource(source_id, normalize(lon), normalize(lat)).datum, \ + sources.getRasterDataFromSource(source_id, lon, lat).datum, \ expected) #define CHECK_INTERPOLATE(source_id, lon, lat, expected) \ BOOST_CHECK_EQUAL( \ - sources.getRasterInterpolateFromSource(source_id, normalize(lon), normalize(lat)).datum, \ + sources.getRasterInterpolateFromSource(source_id, lon, lat).datum, \ expected) BOOST_AUTO_TEST_CASE(raster_test)