diff --git a/extractor/restriction_parser.cpp b/extractor/restriction_parser.cpp index 9b209b719..86174d410 100644 --- a/extractor/restriction_parser.cpp +++ b/extractor/restriction_parser.cpp @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include @@ -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,16 +141,30 @@ 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:") + if (key.size() > 11) + { + const auto ex_suffix = [&](const std::string &exception) { - is_only_restriction = true; + 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(); } } } diff --git a/features/car/restrictions.feature b/features/car/restrictions.feature index f381f2f8c..89fffff75 100644 --- a/features/car/restrictions.feature +++ b/features/car/restrictions.feature @@ -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 diff --git a/features/step_definitions/data.rb b/features/step_definitions/data.rb index ff074d24f..0f3384323 100644 --- a/features/step_definitions/data.rb +++ b/features/step_definitions/data.rb @@ -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