diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 96e0cf4c0..d30225a70 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -21,6 +21,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef EXTRACTORCALLBACKS_H_ #define EXTRACTORCALLBACKS_H_ +#include +#include + #include #include #include "ExtractorStructs.h" @@ -64,6 +67,24 @@ private: StringMap * stringMap; STXXLContainers * externalMemory; + struct DurationContainer { + int hours; + int minutes; + }; + + bool checkForValidTiming(const std::string &s, DurationContainer & duration) const { + boost::regex e ("((\\d|\\d\\d):)*(\\d|\\d\\d)",boost::regex_constants::icase|boost::regex_constants::perl); + + std::vector< std::string > result; + boost::algorithm::split_regex( result, s, boost::regex( ":" ) ) ; + bool matched = regex_match(s, e); + if(matched) { + duration.hours = (result.size()== 2) ? atoi(result[0].c_str()) : 0; + duration.minutes = (result.size()== 2) ? atoi(result[1].c_str()) : atoi(result[0].c_str()); + } + return matched; + } + public: ExtractorCallbacks(STXXLContainers * ext, Settings set, StringMap * strMap) { externalMemory = ext; @@ -122,6 +143,7 @@ public: 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")); //Save the name of the way if it has one, ref has precedence over name tag. if ( 0 < ref.length() ) @@ -137,7 +159,13 @@ public: //Is the route tag listed as usable way in the profile? if(settings[route] > 0 || settings[man_made] > 0) { w.useful = true; - w.speed = settings[route]; + DurationContainer dc; + if(checkForValidTiming(duration, dc)){ + w.speed = (600*(dc.hours*60+dc.minutes))/std::max((unsigned)(w.path.size()-1),1u); + w.isDurationSet = true; + } else { + w.speed = settings[route]; + } w.direction = _Way::bidirectional; if(0 < settings[route]) highway = route; @@ -148,15 +176,16 @@ public: //Is the highway tag listed as usable way? if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) { - - if(0 < settings[highway]) { - if(0 < maxspeed) - w.speed = std::min(maxspeed, settings[highway]); - else - w.speed = settings[highway]; - } else { - w.speed = settings.defaultSpeed; - highway = "default"; + if(!w.isDurationSet) { + if(0 < settings[highway]) { + if(0 < maxspeed) + w.speed = std::min(maxspeed, settings[highway]); + else + w.speed = settings[highway]; + } else { + w.speed = settings.defaultSpeed; + highway = "default"; + } } w.useful = true; @@ -225,7 +254,7 @@ public: } for(vector< NodeID >::size_type n = 0; n < w.path.size()-1; ++n) { - externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout, highway == settings.excludeFromGrid)); + externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout, highway == settings.excludeFromGrid, w.isDurationSet)); externalMemory->usedNodeIDs.push_back(w.path[n]); } externalMemory->usedNodeIDs.push_back(w.path[w.path.size()-1]); diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index a267216e5..ed14200a0 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -91,6 +91,7 @@ struct _Way { useful = false; access = true; roundabout = false; + isDurationSet = false; } enum { @@ -104,6 +105,7 @@ struct _Way { bool useful; bool access; bool roundabout; + bool isDurationSet; std::vector< NodeID > path; HashTable keyVals; }; @@ -137,10 +139,10 @@ struct _Relation { }; struct _Edge { - _Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) {}; + _Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false), isDurationSet(false) {}; _Edge(NodeID s, NodeID t) : start(s), target(t), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) { } - _Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false), ignoreInGrid(false) { } - _Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra, bool iing): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing) { + _Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false), ignoreInGrid(false), isDurationSet(false) { } + _Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra, bool iing, bool ids): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing), isDurationSet(ids) { assert(0 <= type); } NodeID start; @@ -151,6 +153,7 @@ struct _Edge { unsigned nameID; bool isRoundabout; bool ignoreInGrid; + bool isDurationSet; _Coordinate startCoord; _Coordinate targetCoord; diff --git a/extractor.cpp b/extractor.cpp index 3dfe7698b..3c456b4f7 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -408,8 +408,8 @@ int main (int argc, char *argv[]) { double distance = ApproximateDistance(edgeIT->startCoord.lat, edgeIT->startCoord.lon, nodesIT->lat, nodesIT->lon); assert(edgeIT->speed != -1); double weight = ( distance * 10. ) / (edgeIT->speed / 3.6); - int intWeight = max(1, (int) weight); - int intDist = max(1, (int)distance); + int intWeight = std::max(1, (int)(edgeIT->isDurationSet ? edgeIT->speed : weight) ); + int intDist = std::max(1, (int)distance); short zero = 0; short one = 1;