Allow multiple GeoJSON files with locations data
This commit is contained in:
parent
095b345713
commit
476bc347b4
@ -72,6 +72,7 @@ Feature: osrm-extract lua ways:get_nodes()
|
|||||||
|
|
||||||
function way_function(profile, way, result, relations)
|
function way_function(profile, way, result, relations)
|
||||||
print('ISO3166-1 ' .. (way:get_location_tag('ISO3166-1') or 'none'))
|
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_mode = mode.driving
|
||||||
result.forward_speed = 1
|
result.forward_speed = 1
|
||||||
end
|
end
|
||||||
@ -85,18 +86,22 @@ Feature: osrm-extract lua ways:get_nodes()
|
|||||||
| b | 22.4901701 | 113.9455899 | 2 |
|
| b | 22.4901701 | 113.9455899 | 2 |
|
||||||
| c | 22.4901852 | 113.9458608 | 3 |
|
| c | 22.4901852 | 113.9458608 | 3 |
|
||||||
| d | 22.4904033 | 113.9456999 | 4 |
|
| d | 22.4904033 | 113.9456999 | 4 |
|
||||||
|
| e | 1.1 | 1 | 5 |
|
||||||
|
| f | 1.2 | 1 | 6 |
|
||||||
And the ways with locations
|
And the ways with locations
|
||||||
| nodes | # |
|
| nodes | # |
|
||||||
| ab | Hong Kong |
|
| ab | Hong Kong |
|
||||||
| cd | China Mainland |
|
| cd | China Mainland |
|
||||||
|
| ef | Null Island |
|
||||||
And the data has been saved to disk
|
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"
|
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
|
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 "2 GeoJSON polygons"
|
||||||
And stdout should contain "ISO3166-1 HK"
|
And stdout should contain "ISO3166-1 HK"
|
||||||
And stdout should contain "ISO3166-1 none"
|
And stdout should contain "ISO3166-1 none"
|
||||||
|
And stdout should contain "answer 42"
|
||||||
|
|
||||||
Scenario: osrm-extract location-dependent data via locations cache
|
Scenario: osrm-extract location-dependent data via locations cache
|
||||||
Given the profile file
|
Given the profile file
|
||||||
|
@ -32,8 +32,6 @@ struct LocationDependentData
|
|||||||
using property_t = boost::variant<boost::blank, double, std::string, bool>;
|
using property_t = boost::variant<boost::blank, double, std::string, bool>;
|
||||||
using properties_t = std::unordered_map<std::string, property_t>;
|
using properties_t = std::unordered_map<std::string, property_t>;
|
||||||
|
|
||||||
LocationDependentData(const boost::filesystem::path &path);
|
|
||||||
|
|
||||||
LocationDependentData(const std::vector<boost::filesystem::path> &file_paths);
|
LocationDependentData(const std::vector<boost::filesystem::path> &file_paths);
|
||||||
|
|
||||||
bool empty() const { return rtree.empty(); }
|
bool empty() const { return rtree.empty(); }
|
||||||
@ -41,7 +39,8 @@ struct LocationDependentData
|
|||||||
property_t operator()(const point_t &point, const char *key) const;
|
property_t operator()(const point_t &point, const char *key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadLocationDependentData(const boost::filesystem::path &file_path);
|
void loadLocationDependentData(const boost::filesystem::path &file_path,
|
||||||
|
std::vector<rtree_t::value_type> &bounding_boxes);
|
||||||
|
|
||||||
rtree_t rtree;
|
rtree_t rtree;
|
||||||
std::vector<std::pair<polygon_bands_t, std::size_t>> polygons;
|
std::vector<std::pair<polygon_bands_t, std::size_t>> polygons;
|
||||||
|
@ -19,20 +19,22 @@ namespace osrm
|
|||||||
namespace extractor
|
namespace extractor
|
||||||
{
|
{
|
||||||
|
|
||||||
LocationDependentData::LocationDependentData(const boost::filesystem::path &path)
|
|
||||||
{
|
|
||||||
loadLocationDependentData(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationDependentData::LocationDependentData(const std::vector<boost::filesystem::path> &file_paths)
|
LocationDependentData::LocationDependentData(const std::vector<boost::filesystem::path> &file_paths)
|
||||||
{
|
{
|
||||||
|
std::vector<rtree_t::value_type> bounding_boxes;
|
||||||
for (const auto &path : file_paths)
|
for (const auto &path : file_paths)
|
||||||
{
|
{
|
||||||
loadLocationDependentData(path);
|
loadLocationDependentData(path, bounding_boxes);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationDependentData::loadLocationDependentData(const boost::filesystem::path &file_path)
|
// 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, std::vector<rtree_t::value_type> &bounding_boxes)
|
||||||
{
|
{
|
||||||
if (file_path.empty())
|
if (file_path.empty())
|
||||||
return;
|
return;
|
||||||
@ -64,7 +66,6 @@ void LocationDependentData::loadLocationDependentData(const boost::filesystem::p
|
|||||||
BOOST_ASSERT(geojson["features"].IsArray());
|
BOOST_ASSERT(geojson["features"].IsArray());
|
||||||
|
|
||||||
const auto &features_array = geojson["features"].GetArray();
|
const auto &features_array = geojson["features"].GetArray();
|
||||||
std::vector<rtree_t::value_type> bounding_boxes;
|
|
||||||
|
|
||||||
auto convert_value = [](const auto &property) -> property_t {
|
auto convert_value = [](const auto &property) -> property_t {
|
||||||
if (property.IsString())
|
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,
|
LocationDependentData::property_t LocationDependentData::operator()(const point_t &point,
|
||||||
|
@ -49,7 +49,8 @@ BOOST_AUTO_TEST_CASE(polygon_tests)
|
|||||||
}
|
}
|
||||||
]})json");
|
]})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(data(point_t(0, 0), "answer").which(), 0);
|
||||||
BOOST_CHECK_EQUAL(boost::get<double>(data(point_t(1, 1), "answer")), 42);
|
BOOST_CHECK_EQUAL(boost::get<double>(data(point_t(1, 1), "answer")), 42);
|
||||||
BOOST_CHECK_EQUAL(boost::get<double>(data(point_t(0, 1), "answer")), 42);
|
BOOST_CHECK_EQUAL(boost::get<double>(data(point_t(0, 1), "answer")), 42);
|
||||||
@ -79,7 +80,8 @@ BOOST_AUTO_TEST_CASE(multy_polygon_tests)
|
|||||||
}
|
}
|
||||||
]})json");
|
]})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, 2), "answer").which(), 0);
|
||||||
BOOST_CHECK_EQUAL(data(point_t(0, -3), "answer").which(), 0);
|
BOOST_CHECK_EQUAL(data(point_t(0, -3), "answer").which(), 0);
|
||||||
BOOST_CHECK_EQUAL(boost::get<double>(data(point_t(0, 0), "answer")), 42.);
|
BOOST_CHECK_EQUAL(boost::get<double>(data(point_t(0, 0), "answer")), 42.);
|
||||||
@ -109,7 +111,8 @@ BOOST_AUTO_TEST_CASE(polygon_merging_tests)
|
|||||||
}
|
}
|
||||||
]})json");
|
]})json");
|
||||||
|
|
||||||
LocationDependentData data(fixture.temporary_file);
|
LocationDependentData data({fixture.temporary_file});
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(boost::get<std::string>(data(point_t(-3, 3), "answer")), "a");
|
BOOST_CHECK_EQUAL(boost::get<std::string>(data(point_t(-3, 3), "answer")), "a");
|
||||||
BOOST_CHECK_EQUAL(boost::get<std::string>(data(point_t(-3, 1), "answer")), "a");
|
BOOST_CHECK_EQUAL(boost::get<std::string>(data(point_t(-3, 1), "answer")), "a");
|
||||||
BOOST_CHECK_EQUAL(boost::get<std::string>(data(point_t(-3, -3), "answer")), "a");
|
BOOST_CHECK_EQUAL(boost::get<std::string>(data(point_t(-3, -3), "answer")), "a");
|
||||||
@ -137,7 +140,7 @@ BOOST_AUTO_TEST_CASE(staircase_polygon)
|
|||||||
}
|
}
|
||||||
]})json");
|
]})json");
|
||||||
|
|
||||||
LocationDependentData data(fixture.temporary_file);
|
LocationDependentData data({fixture.temporary_file});
|
||||||
|
|
||||||
// all corners
|
// all corners
|
||||||
BOOST_CHECK_NE(data(point_t(0, 0), "answer").which(), 0);
|
BOOST_CHECK_NE(data(point_t(0, 0), "answer").which(), 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user