duration tags on ferry ways get parsed now. Cheers to Mackerski!
This commit is contained in:
parent
64ab2da43b
commit
75353852fd
@ -21,6 +21,9 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef EXTRACTORCALLBACKS_H_
|
#ifndef EXTRACTORCALLBACKS_H_
|
||||||
#define EXTRACTORCALLBACKS_H_
|
#define EXTRACTORCALLBACKS_H_
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/regex.hpp>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
#include <stxxl.h>
|
#include <stxxl.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ExtractorStructs.h"
|
#include "ExtractorStructs.h"
|
||||||
@ -64,6 +67,24 @@ private:
|
|||||||
StringMap * stringMap;
|
StringMap * stringMap;
|
||||||
STXXLContainers * externalMemory;
|
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:
|
public:
|
||||||
ExtractorCallbacks(STXXLContainers * ext, Settings set, StringMap * strMap) {
|
ExtractorCallbacks(STXXLContainers * ext, Settings set, StringMap * strMap) {
|
||||||
externalMemory = ext;
|
externalMemory = ext;
|
||||||
@ -122,6 +143,7 @@ public:
|
|||||||
std::string oneway( w.keyVals.Find("oneway"));
|
std::string oneway( w.keyVals.Find("oneway"));
|
||||||
std::string onewayClass( w.keyVals.Find("oneway:"+settings.accessTag));
|
std::string onewayClass( w.keyVals.Find("oneway:"+settings.accessTag));
|
||||||
std::string cycleway( w.keyVals.Find("cycleway"));
|
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.
|
//Save the name of the way if it has one, ref has precedence over name tag.
|
||||||
if ( 0 < ref.length() )
|
if ( 0 < ref.length() )
|
||||||
@ -137,7 +159,13 @@ public:
|
|||||||
//Is the route tag listed as usable way in the profile?
|
//Is the route tag listed as usable way in the profile?
|
||||||
if(settings[route] > 0 || settings[man_made] > 0) {
|
if(settings[route] > 0 || settings[man_made] > 0) {
|
||||||
w.useful = true;
|
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;
|
w.direction = _Way::bidirectional;
|
||||||
if(0 < settings[route])
|
if(0 < settings[route])
|
||||||
highway = route;
|
highway = route;
|
||||||
@ -148,15 +176,16 @@ public:
|
|||||||
|
|
||||||
//Is the highway tag listed as usable way?
|
//Is the highway tag listed as usable way?
|
||||||
if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) {
|
if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) {
|
||||||
|
if(!w.isDurationSet) {
|
||||||
if(0 < settings[highway]) {
|
if(0 < settings[highway]) {
|
||||||
if(0 < maxspeed)
|
if(0 < maxspeed)
|
||||||
w.speed = std::min(maxspeed, settings[highway]);
|
w.speed = std::min(maxspeed, settings[highway]);
|
||||||
else
|
else
|
||||||
w.speed = settings[highway];
|
w.speed = settings[highway];
|
||||||
} else {
|
} else {
|
||||||
w.speed = settings.defaultSpeed;
|
w.speed = settings.defaultSpeed;
|
||||||
highway = "default";
|
highway = "default";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.useful = true;
|
w.useful = true;
|
||||||
|
|
||||||
@ -225,7 +254,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(vector< NodeID >::size_type n = 0; n < w.path.size()-1; ++n) {
|
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[n]);
|
||||||
}
|
}
|
||||||
externalMemory->usedNodeIDs.push_back(w.path[w.path.size()-1]);
|
externalMemory->usedNodeIDs.push_back(w.path[w.path.size()-1]);
|
||||||
|
@ -91,6 +91,7 @@ struct _Way {
|
|||||||
useful = false;
|
useful = false;
|
||||||
access = true;
|
access = true;
|
||||||
roundabout = false;
|
roundabout = false;
|
||||||
|
isDurationSet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -104,6 +105,7 @@ struct _Way {
|
|||||||
bool useful;
|
bool useful;
|
||||||
bool access;
|
bool access;
|
||||||
bool roundabout;
|
bool roundabout;
|
||||||
|
bool isDurationSet;
|
||||||
std::vector< NodeID > path;
|
std::vector< NodeID > path;
|
||||||
HashTable<std::string, std::string> keyVals;
|
HashTable<std::string, std::string> keyVals;
|
||||||
};
|
};
|
||||||
@ -137,10 +139,10 @@ struct _Relation {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _Edge {
|
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) : 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): 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): 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, 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);
|
assert(0 <= type);
|
||||||
}
|
}
|
||||||
NodeID start;
|
NodeID start;
|
||||||
@ -151,6 +153,7 @@ struct _Edge {
|
|||||||
unsigned nameID;
|
unsigned nameID;
|
||||||
bool isRoundabout;
|
bool isRoundabout;
|
||||||
bool ignoreInGrid;
|
bool ignoreInGrid;
|
||||||
|
bool isDurationSet;
|
||||||
|
|
||||||
_Coordinate startCoord;
|
_Coordinate startCoord;
|
||||||
_Coordinate targetCoord;
|
_Coordinate targetCoord;
|
||||||
|
@ -408,8 +408,8 @@ int main (int argc, char *argv[]) {
|
|||||||
double distance = ApproximateDistance(edgeIT->startCoord.lat, edgeIT->startCoord.lon, nodesIT->lat, nodesIT->lon);
|
double distance = ApproximateDistance(edgeIT->startCoord.lat, edgeIT->startCoord.lon, nodesIT->lat, nodesIT->lon);
|
||||||
assert(edgeIT->speed != -1);
|
assert(edgeIT->speed != -1);
|
||||||
double weight = ( distance * 10. ) / (edgeIT->speed / 3.6);
|
double weight = ( distance * 10. ) / (edgeIT->speed / 3.6);
|
||||||
int intWeight = max(1, (int) weight);
|
int intWeight = std::max(1, (int)(edgeIT->isDurationSet ? edgeIT->speed : weight) );
|
||||||
int intDist = max(1, (int)distance);
|
int intDist = std::max(1, (int)distance);
|
||||||
short zero = 0;
|
short zero = 0;
|
||||||
short one = 1;
|
short one = 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user