Parse specific restriction:* tags based on profile exceptions
This commit is contained in:
parent
a1e273e983
commit
5ac024788e
@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/regex.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
@ -51,8 +52,7 @@ int lua_error_callback(lua_State *lua_state)
|
||||
}
|
||||
}
|
||||
|
||||
RestrictionParser::RestrictionParser(lua_State *lua_state)
|
||||
: use_turn_restrictions(true)
|
||||
RestrictionParser::RestrictionParser(lua_State *lua_state) : use_turn_restrictions(true)
|
||||
{
|
||||
ReadUseRestrictionsSetting(lua_state);
|
||||
|
||||
@ -141,17 +141,31 @@ RestrictionParser::TryParse(const osmium::Relation &relation) const
|
||||
|
||||
bool is_only_restriction = false;
|
||||
|
||||
for (auto iter = fi_begin; iter != fi_end; ++iter)
|
||||
for (; fi_begin != fi_end; ++fi_begin)
|
||||
{
|
||||
if (std::string("restriction") == iter->key() ||
|
||||
std::string("restriction::hgv") == iter->key())
|
||||
{
|
||||
const std::string restriction_value(iter->value());
|
||||
const std::string key(fi_begin->key());
|
||||
const std::string value(fi_begin->value());
|
||||
|
||||
if (restriction_value.find("only_") == 0)
|
||||
if (value.find("only_") == 0)
|
||||
{
|
||||
is_only_restriction = true;
|
||||
}
|
||||
|
||||
// if the "restriction*" key is longer than 11 chars, it is a conditional exception (i.e.
|
||||
// "restriction:<transportation_type>")
|
||||
if (key.size() > 11)
|
||||
{
|
||||
const auto ex_suffix = [&](const std::string &exception)
|
||||
{
|
||||
return boost::algorithm::ends_with(key, exception);
|
||||
};
|
||||
bool is_actually_restricted =
|
||||
std::any_of(begin(restriction_exceptions), end(restriction_exceptions), ex_suffix);
|
||||
|
||||
if (!is_actually_restricted)
|
||||
{
|
||||
return mapbox::util::optional<InputRestrictionContainer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,6 +226,54 @@ Feature: Car - Turn restrictions
|
||||
| s | n | sj,nj |
|
||||
| s | e | |
|
||||
|
||||
@specific
|
||||
Scenario: Car - :hgv-qualified on a standard turn restriction
|
||||
Given the node map
|
||||
| | n | |
|
||||
| w | j | e |
|
||||
| | s | |
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| sj | yes |
|
||||
| nj | -1 |
|
||||
| wj | -1 |
|
||||
| ej | -1 |
|
||||
|
||||
And the relations
|
||||
| type | way:from | way:to | node:via | restriction:hgv |
|
||||
| restriction | sj | nj | j | no_straight_on |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route |
|
||||
| s | w | sj,wj |
|
||||
| s | n | sj,nj |
|
||||
| s | e | sj,ej |
|
||||
|
||||
@specific
|
||||
Scenario: Car - :motorcar-qualified on a standard turn restriction
|
||||
Given the node map
|
||||
| | n | |
|
||||
| w | j | e |
|
||||
| | s | |
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| sj | yes |
|
||||
| nj | -1 |
|
||||
| wj | -1 |
|
||||
| ej | -1 |
|
||||
|
||||
And the relations
|
||||
| type | way:from | way:to | node:via | restriction:motorcar |
|
||||
| restriction | sj | nj | j | no_straight_on |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route |
|
||||
| s | w | sj,wj |
|
||||
| s | n | |
|
||||
| s | e | sj,ej |
|
||||
|
||||
@except
|
||||
Scenario: Car - Except tag and on no_ restrictions
|
||||
Given the node map
|
||||
|
@ -115,8 +115,8 @@ Given /^the relations$/ do |table|
|
||||
raise "*** unknown relation way member '#{way_name}'" unless way
|
||||
relation << OSM::Member.new( 'way', way.id, $1 )
|
||||
end
|
||||
elsif key =~ /^(.*):(.*)/
|
||||
raise "*** unknown relation member type '#{$1}', must be either 'node' or 'way'"
|
||||
elsif key =~ /^(.*):(.*)/ && "#{$1}" != 'restriction'
|
||||
raise "*** unknown relation member type '#{$1}:#{$2}', must be either 'node' or 'way'"
|
||||
else
|
||||
relation << { key => value }
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user