diff --git a/features/options/extract/lua.feature b/features/options/extract/lua.feature index e13dfc70d..91209a2a9 100644 --- a/features/options/extract/lua.feature +++ b/features/options/extract/lua.feature @@ -72,6 +72,7 @@ Feature: osrm-extract lua ways:get_nodes() function way_function(profile, way, result, relations) print('ISO3166-1 ' .. (way:get_location_tag('ISO3166-1') or 'none')) + print('answer ' .. (way:get_location_tag('answer') or 'none')) result.forward_mode = mode.driving result.forward_speed = 1 end @@ -85,18 +86,22 @@ Feature: osrm-extract lua ways:get_nodes() | b | 22.4901701 | 113.9455899 | 2 | | c | 22.4901852 | 113.9458608 | 3 | | d | 22.4904033 | 113.9456999 | 4 | + | e | 1.1 | 1 | 5 | + | f | 1.2 | 1 | 6 | And the ways with locations | nodes | # | | ab | Hong Kong | | cd | China Mainland | + | ef | Null Island | And the data has been saved to disk When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson --location-dependent-data test/data/regions/hong-kong.geojson" Then it should exit successfully - And stdout should contain "1 GeoJSON polygon" + And stdout should not contain "1 GeoJSON polygon" And stdout should contain "2 GeoJSON polygons" And stdout should contain "ISO3166-1 HK" And stdout should contain "ISO3166-1 none" + And stdout should contain "answer 42" Scenario: osrm-extract location-dependent data via locations cache Given the profile file diff --git a/include/extractor/location_dependent_data.hpp b/include/extractor/location_dependent_data.hpp index 8406b4fcb..8a942349d 100644 --- a/include/extractor/location_dependent_data.hpp +++ b/include/extractor/location_dependent_data.hpp @@ -32,8 +32,6 @@ struct LocationDependentData using property_t = boost::variant; using properties_t = std::unordered_map; - LocationDependentData(const boost::filesystem::path &path); - LocationDependentData(const std::vector &file_paths); bool empty() const { return rtree.empty(); } @@ -41,7 +39,8 @@ struct LocationDependentData property_t operator()(const point_t &point, const char *key) const; private: - void loadLocationDependentData(const boost::filesystem::path &file_path); + void loadLocationDependentData(const boost::filesystem::path &file_path, + std::vector &bounding_boxes); rtree_t rtree; std::vector> polygons; diff --git a/src/extractor/location_dependent_data.cpp b/src/extractor/location_dependent_data.cpp index c8e9578b0..9ae77a363 100644 --- a/src/extractor/location_dependent_data.cpp +++ b/src/extractor/location_dependent_data.cpp @@ -19,20 +19,22 @@ namespace osrm namespace extractor { -LocationDependentData::LocationDependentData(const boost::filesystem::path &path) -{ - loadLocationDependentData(path); -} - LocationDependentData::LocationDependentData(const std::vector &file_paths) { + std::vector bounding_boxes; for (const auto &path : file_paths) { - loadLocationDependentData(path); + loadLocationDependentData(path, bounding_boxes); } + + // Create R-tree for bounding boxes of collected polygons + rtree = rtree_t(bounding_boxes); + util::Log() << "Parsed " << properties.size() << " location-dependent features with " + << polygons.size() << " GeoJSON polygons"; } -void LocationDependentData::loadLocationDependentData(const boost::filesystem::path &file_path) +void LocationDependentData::loadLocationDependentData( + const boost::filesystem::path &file_path, std::vector &bounding_boxes) { if (file_path.empty()) return; @@ -64,7 +66,6 @@ void LocationDependentData::loadLocationDependentData(const boost::filesystem::p BOOST_ASSERT(geojson["features"].IsArray()); const auto &features_array = geojson["features"].GetArray(); - std::vector bounding_boxes; auto convert_value = [](const auto &property) -> property_t { if (property.IsString()) @@ -188,11 +189,6 @@ void LocationDependentData::loadLocationDependentData(const boost::filesystem::p } } } - - // Create R-tree for bounding boxes of collected polygons - rtree = rtree_t(bounding_boxes); - util::Log() << "Parsed " << properties.size() << " location-dependent features with " - << polygons.size() << " GeoJSON polygons"; } LocationDependentData::property_t LocationDependentData::operator()(const point_t &point, diff --git a/unit_tests/extractor/location_dependent_data_tests.cpp b/unit_tests/extractor/location_dependent_data_tests.cpp index 1749cb544..5d4d8f98d 100644 --- a/unit_tests/extractor/location_dependent_data_tests.cpp +++ b/unit_tests/extractor/location_dependent_data_tests.cpp @@ -49,7 +49,8 @@ BOOST_AUTO_TEST_CASE(polygon_tests) } ]})json"); - LocationDependentData data(fixture.temporary_file); + LocationDependentData data({fixture.temporary_file}); + BOOST_CHECK_EQUAL(data(point_t(0, 0), "answer").which(), 0); BOOST_CHECK_EQUAL(boost::get(data(point_t(1, 1), "answer")), 42); BOOST_CHECK_EQUAL(boost::get(data(point_t(0, 1), "answer")), 42); @@ -79,7 +80,8 @@ BOOST_AUTO_TEST_CASE(multy_polygon_tests) } ]})json"); - LocationDependentData data(fixture.temporary_file); + LocationDependentData data({fixture.temporary_file}); + BOOST_CHECK_EQUAL(data(point_t(0, 2), "answer").which(), 0); BOOST_CHECK_EQUAL(data(point_t(0, -3), "answer").which(), 0); BOOST_CHECK_EQUAL(boost::get(data(point_t(0, 0), "answer")), 42.); @@ -109,7 +111,8 @@ BOOST_AUTO_TEST_CASE(polygon_merging_tests) } ]})json"); - LocationDependentData data(fixture.temporary_file); + LocationDependentData data({fixture.temporary_file}); + BOOST_CHECK_EQUAL(boost::get(data(point_t(-3, 3), "answer")), "a"); BOOST_CHECK_EQUAL(boost::get(data(point_t(-3, 1), "answer")), "a"); BOOST_CHECK_EQUAL(boost::get(data(point_t(-3, -3), "answer")), "a"); @@ -137,7 +140,7 @@ BOOST_AUTO_TEST_CASE(staircase_polygon) } ]})json"); - LocationDependentData data(fixture.temporary_file); + LocationDependentData data({fixture.temporary_file}); // all corners BOOST_CHECK_NE(data(point_t(0, 0), "answer").which(), 0);