Add OSM node barrier=height_restrictor handling

This commit is contained in:
Michael Krasnyk
2018-02-12 09:02:20 +01:00
parent 0da2029d2d
commit 5f598da76d
7 changed files with 64 additions and 32 deletions
+32 -24
View File
@@ -218,6 +218,22 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
"valid",
&osmium::Location::valid);
auto get_location_tag = [](auto &context, const auto &location, const char *key) {
if (context.location_dependent_data.empty())
return sol::object(sol::nil);
const LocationDependentData::point_t point{location.lon(), location.lat()};
if (!boost::geometry::equals(context.last_location_point, point))
{
context.last_location_point = point;
context.last_location_indexes =
context.location_dependent_data.GetPropertyIndexes(point);
}
auto value = context.location_dependent_data.FindByKey(context.last_location_indexes, key);
return boost::apply_visitor(to_lua_object(context.state), value);
};
context.state.new_usertype<osmium::Way>(
"Way",
"get_value_by_key",
@@ -229,37 +245,29 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
"get_nodes",
[](const osmium::Way &way) { return sol::as_table(way.nodes()); },
"get_location_tag",
[&context](const osmium::Way &way, const char *key) {
if (context.location_dependent_data.empty())
return sol::object(sol::nil);
[&context, &get_location_tag](const osmium::Way &way, const char *key) {
// HEURISTIC: use a single node (last) of the way to localize the way
// For more complicated scenarios a proper merging of multiple tags
// at one or many locations must be provided
const auto &nodes = way.nodes();
const auto &location = nodes.back().location();
const LocationDependentData::point_t point{location.lon(), location.lat()};
if (!boost::geometry::equals(context.last_location_point, point))
{
context.last_location_point = point;
context.last_location_indexes =
context.location_dependent_data.GetPropertyIndexes(point);
}
auto value =
context.location_dependent_data.FindByKey(context.last_location_indexes, key);
return boost::apply_visitor(to_lua_object(context.state), value);
return get_location_tag(context, location, key);
});
context.state.new_usertype<osmium::Node>("Node",
"location",
&osmium::Node::location,
"get_value_by_key",
&get_value_by_key<osmium::Node>,
"id",
&osmium::Node::id,
"version",
&osmium::Node::version);
context.state.new_usertype<osmium::Node>(
"Node",
"location",
&osmium::Node::location,
"get_value_by_key",
&get_value_by_key<osmium::Node>,
"id",
&osmium::Node::id,
"version",
&osmium::Node::version,
"get_location_tag",
[&context, &get_location_tag](const osmium::Node &node, const char *key) {
return get_location_tag(context, node.location(), key);
});
context.state.new_usertype<ExtractionNode>("ResultNode",
"traffic_lights",