From 66c23b58431972de72a63711959d583da89165ee Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 18 Aug 2012 23:31:32 +0200 Subject: [PATCH 1/2] extended access handling This adds a few more configuration options for a more flexible access tag handling: accessTags - replaces accessTag and is an ordered list of access tags to take into account. The first tag in the list found will determine the access. This allows to model OSM's access hierarchy where a more specific access tag might override a more general one. accessForbiddenKeys - unordered list of values that disallow access (similar to accessRestrictionKeys). Replaces hardcoded values in extractor. accessForbiddenDefault - unordered list of highway types where access is forbidden unless an explicit positiv access tag is given. Replaces the current track hack. --- DataStructures/ExtractorCallBacks.h | 31 ++++++++++++++++++++++------- DataStructures/ExtractorStructs.h | 6 ++++-- extractor.cpp | 24 ++++++++++++++++++++-- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 8f274e319..885b938fd 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -148,12 +148,9 @@ public: std::string junction( w.keyVals.Find("junction") ); std::string route( w.keyVals.Find("route") ); int maxspeed( parseMaxspeed(w.keyVals.Find("maxspeed")) ); - std::string access( w.keyVals.Find("access") ); - std::string accessTag( w.keyVals.Find(settings.accessTag) ); std::string man_made( w.keyVals.Find("man_made") ); std::string barrier( w.keyVals.Find("barrier") ); std::string oneway( w.keyVals.Find("oneway")); - std::string onewayClass( w.keyVals.Find("oneway:"+settings.accessTag)); std::string cycleway( w.keyVals.Find("cycleway")); std::string duration ( w.keyVals.Find("duration")); std::string service (w.keyVals.Find("service")); @@ -191,8 +188,28 @@ public: } } + //determine the access value + std::string access; + std::string onewayClass; + std::string accessTag; + BOOST_FOREACH(std::string & s, settings.accessTags) { + access = std::string(w.keyVals.Find(s)); + if(0 < access.size()) { + accessTag = s; + onewayClass = std::string(w.keyVals.Find("oneway:"+access)); + break; + } + } + + if(0 < access.size()) { + // handle ways with default access = no + if(settings.accessForbiddenDefault.find(access) != settings.accessForbiddenDefault.end()) { + access = std::string("no"); + } + } + //Is the highway tag listed as usable way? - if(("track" == highway && ("yes" == access || "yes" == accessTag)) || ("track" != highway && (0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) )) { + if(0 < settings[highway] || "yes" == access || "designated" == access) { if(!w.isDurationSet) { if(0 < settings[highway]) { if(0 < maxspeed) @@ -217,7 +234,7 @@ public: //Okay, do we have access to that way? if(0 < access.size()) { //fastest way to check for non-empty string //If access is forbidden, we don't want to route there. - if(access == "no" || access == "agricultural" || access == "forestry" || access == "delivery") { //Todo: this is still hard coded + if(settings.accessForbiddenKeys.find(access) != settings.accessForbiddenKeys.end()) { w.access = false; } if(settings.accessRestrictionKeys.find(access) != settings.accessRestrictionKeys.end()) { @@ -231,7 +248,7 @@ public: } } - if("no" == accessTag) { + if("no" == access) { return true; } @@ -244,7 +261,7 @@ public: w.direction = _Way::opposite; } else if( oneway == "no" || oneway == "0" || oneway == "false" ) { w.direction = _Way::bidirectional; - } else if( settings.accessTag == "bicycle" && (cycleway == "opposite" || cycleway == "opposite_track" || cycleway == "opposite_lane") ) { + } else if( accessTag == "bicycle" && (cycleway == "opposite" || cycleway == "opposite_track" || cycleway == "opposite_lane") ) { w.direction = _Way::bidirectional; } else if( oneway == "-1") { w.direction = _Way::opposite; diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index d93c96a41..f6665d2de 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -270,7 +270,7 @@ struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDSta }; struct Settings { - Settings() : obeyBollards(true), obeyOneways(true), useRestrictions(true), ignoreAreas(false), accessTag("motorcar"), defaultSpeed(30), takeMinimumOfSpeeds(false), excludeFromGrid("ferry") {} + Settings() : obeyBollards(true), obeyOneways(true), useRestrictions(true), ignoreAreas(false), defaultSpeed(30), takeMinimumOfSpeeds(false), excludeFromGrid("ferry") {} StringToIntPairMap speedProfile; int operator[](const std::string & param) const { if(speedProfile.find(param) == speedProfile.end()) @@ -294,12 +294,14 @@ struct Settings { bool obeyOneways; bool useRestrictions; bool ignoreAreas; - std::string accessTag; + std::vector accessTags; int defaultSpeed; bool takeMinimumOfSpeeds; std::string excludeFromGrid; boost::unordered_map accessRestrictedService; boost::unordered_map accessRestrictionKeys; + boost::unordered_map accessForbiddenKeys; + boost::unordered_map accessForbiddenDefault; }; struct Cmp : public std::binary_function { diff --git a/extractor.cpp b/extractor.cpp index 04a869927..7160b80c9 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -137,8 +137,10 @@ int main (int argc, char *argv[]) { } else if(name == "useRestrictions") { if(value == "no") settings.useRestrictions = false; - } else if(name == "accessTag") { - settings.accessTag = value; + } else if(name == "accessTags") { + std::vector tokens; + stringSplit(value, ',', tokens); + settings.accessTags = tokens; } else if(name == "excludeFromGrid") { settings.excludeFromGrid = value; } else if(name == "defaultSpeed") { @@ -166,6 +168,24 @@ int main (int argc, char *argv[]) { INFO("adding " << s << " to accessRestrictionKeys"); settings.accessRestrictionKeys.insert(std::make_pair(s, true)); } + } else if( name == "accessForbiddenKeys") { + //split value at commas + std::vector tokens; + stringSplit(value, ',', tokens); + //put each value into map + BOOST_FOREACH(std::string & s, tokens) { + INFO("adding " << s << " to accessForbiddenKeys"); + settings.accessForbiddenKeys.insert(std::make_pair(s, true)); + } + } else if( name == "accessForbiddenDefault") { + //split value at commas + std::vector tokens; + stringSplit(value, ',', tokens); + //put each value into map + BOOST_FOREACH(std::string & s, tokens) { + INFO("adding " << s << " to accessForbiddenDefault"); + settings.accessForbiddenDefault.insert(std::make_pair(s, true)); + } } settings.speedProfile[name] = std::make_pair(std::atoi(value.c_str()), settings.speedProfile.size() ); } From 58dfd29a3a33170d1a533ed5efd8afb4f3155128 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Mon, 20 Aug 2012 20:57:22 +0200 Subject: [PATCH 2/2] adapt speed profiles to extended access control --- speedprofile.ini | 8 ++++++-- speedprofiles/bicycle.ini | 7 +++++-- speedprofiles/car.ini | 5 ++++- speedprofiles/ebiki.ini | 5 ++++- speedprofiles/foot.ini | 5 ++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/speedprofile.ini b/speedprofile.ini index 3577a73b4..b4d543491 100644 --- a/speedprofile.ini +++ b/speedprofile.ini @@ -20,7 +20,7 @@ obeyOneways = yes useRestrictions = yes ignoreAreas = yes - accessTag = motorcar + accessTags = motorcar,motor_vehicle,vehicle,access excludeFromGrid = ferry defaultSpeed = 50 trafficSignalPenalty = 5 @@ -28,6 +28,8 @@ uturnPenalty = 20 accessRestrictedService = parking_aisle accessRestrictionKeys = destination,private,delivery + accessForbiddenKeys = no,private,agricultural,forestery + accessForbiddenDefault = track [bike] trunk = 16 trunk_link = 16 @@ -48,10 +50,12 @@ pier = 5 obeyOneways = yes useRestrictions = no - accessTag = bicycle + accessTags = bicycle,vehicle,access excludeFromGrid = ferry defaultSpeed = 5 trafficSignalPenalty = 5 obeyBollards = no takeMinimumOfSpeeds = yes uturnPenalty = 20 + accessRestrictionKeys = destination,private,delivery + accessForbiddenKeys = no,private,agricultural,forestery diff --git a/speedprofiles/bicycle.ini b/speedprofiles/bicycle.ini index 1664beb88..e9e0f4a8f 100644 --- a/speedprofiles/bicycle.ini +++ b/speedprofiles/bicycle.ini @@ -1,5 +1,5 @@ [bicycle] - accessTag = bicycle + accessTags = bicycle,vehicle,access defaultSpeed = 17 obeyOneways = yes useRestrictions = yes @@ -25,4 +25,7 @@ ferry = 5 excludeFromGrid = ferry - trafficSignalPenalty = 10 \ No newline at end of file + trafficSignalPenalty = 10 + + accessRestrictionKeys = destination,private,delivery + accessForbiddenKeys = no,private,agricultural,forestery diff --git a/speedprofiles/car.ini b/speedprofiles/car.ini index b2ce3c4c0..cfb86114b 100644 --- a/speedprofiles/car.ini +++ b/speedprofiles/car.ini @@ -1,5 +1,5 @@ [car] - accessTag = motorcar + accessTag = motorcar,motor_vehicle,vehicle,access defaultSpeed = 50 obeyOneways = yes useRestrictions = yes @@ -21,3 +21,6 @@ service = 20 living_street = 10 + accessRestrictionKeys = destination,private,delivery + accessForbiddenKeys = no,private,agricultural,forestery + accessForbiddenDefault = track diff --git a/speedprofiles/ebiki.ini b/speedprofiles/ebiki.ini index d3b9fa54b..cd9e55dcf 100644 --- a/speedprofiles/ebiki.ini +++ b/speedprofiles/ebiki.ini @@ -1,5 +1,5 @@ [ebike] -accessTag = bicycle +accessTags = bicycle,vehicle,access obeyOneways = yes defaultSpeed = 25 useRestrictions = no @@ -24,3 +24,6 @@ footway = 5 ferry = 5 excludeFromGrid = ferry + +accessRestrictionKeys = destination,private,delivery +accessForbiddenKeys = no,private,agricultural,forestery diff --git a/speedprofiles/foot.ini b/speedprofiles/foot.ini index 656c82ad5..f65dd10d8 100644 --- a/speedprofiles/foot.ini +++ b/speedprofiles/foot.ini @@ -1,5 +1,5 @@ [foot] - accessTag = foot + accessTags = foot,access defaultSpeed = 5 obeyOneways = no useRestrictions = no @@ -26,3 +26,6 @@ ferry = 5 excludeFromGrid = ferry + + accessRestrictionKeys = destination,private,delivery + accessForbiddenKeys = no,private,agricultural,forestery