Parse specific restriction:* tags based on profile exceptions

This commit is contained in:
Lauren Budorick 2015-09-09 21:53:41 -07:00
parent a1e273e983
commit 5ac024788e
3 changed files with 73 additions and 11 deletions

View File

@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp> #include <boost/algorithm/string/regex.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <boost/regex.hpp> #include <boost/regex.hpp>
@ -51,8 +52,7 @@ int lua_error_callback(lua_State *lua_state)
} }
} }
RestrictionParser::RestrictionParser(lua_State *lua_state) RestrictionParser::RestrictionParser(lua_State *lua_state) : use_turn_restrictions(true)
: use_turn_restrictions(true)
{ {
ReadUseRestrictionsSetting(lua_state); ReadUseRestrictionsSetting(lua_state);
@ -141,16 +141,30 @@ RestrictionParser::TryParse(const osmium::Relation &relation) const
bool is_only_restriction = false; 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() || const std::string key(fi_begin->key());
std::string("restriction::hgv") == iter->key()) const std::string value(fi_begin->value());
{
const std::string restriction_value(iter->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)
{ {
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<InputRestrictionContainer>();
} }
} }
} }

View File

@ -226,6 +226,54 @@ Feature: Car - Turn restrictions
| s | n | sj,nj | | s | n | sj,nj |
| s | e | | | 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 @except
Scenario: Car - Except tag and on no_ restrictions Scenario: Car - Except tag and on no_ restrictions
Given the node map Given the node map

View File

@ -115,8 +115,8 @@ Given /^the relations$/ do |table|
raise "*** unknown relation way member '#{way_name}'" unless way raise "*** unknown relation way member '#{way_name}'" unless way
relation << OSM::Member.new( 'way', way.id, $1 ) relation << OSM::Member.new( 'way', way.id, $1 )
end end
elsif key =~ /^(.*):(.*)/ elsif key =~ /^(.*):(.*)/ && "#{$1}" != 'restriction'
raise "*** unknown relation member type '#{$1}', must be either 'node' or 'way'" raise "*** unknown relation member type '#{$1}:#{$2}', must be either 'node' or 'way'"
else else
relation << { key => value } relation << { key => value }
end end