no direction flag, cleaner forw/back settings in lua
This commit is contained in:
parent
6cfe4f7ded
commit
00c0b9ce4d
@ -231,9 +231,6 @@ void ExtractionContainers::PrepareData(const std::string & outputFileName, const
|
||||
fout.write((char*)&edgeIT->target, sizeof(unsigned));
|
||||
fout.write((char*)&intDist, sizeof(int));
|
||||
switch(edgeIT->direction) {
|
||||
case ExtractionWay::notSure:
|
||||
fout.write((char*)&zero, sizeof(short));
|
||||
break;
|
||||
case ExtractionWay::oneway:
|
||||
fout.write((char*)&one, sizeof(short));
|
||||
break;
|
||||
|
||||
@ -64,7 +64,7 @@ bool ExtractorCallbacks::restrictionFunction(const _RawRestrictionContainer &r)
|
||||
|
||||
/** warning: caller needs to take care of synchronization! */
|
||||
void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) {
|
||||
if((0 < parsed_way.speed) || (0 < parsed_way.duration)) { //Only true if the way is specified by the speed profile
|
||||
if((0 < parsed_way.forward.speed) || (0 < parsed_way.backward.speed) || (0 < parsed_way.duration)) { //Only true if the way is specified by the speed profile
|
||||
if(UINT_MAX == parsed_way.id){
|
||||
DEBUG("found bogus way with id: " << parsed_way.id << " of size " << parsed_way.path.size());
|
||||
return;
|
||||
@ -72,10 +72,13 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) {
|
||||
|
||||
if(0 < parsed_way.duration) {
|
||||
//TODO: iterate all way segments and set duration corresponding to the length of each segment
|
||||
parsed_way.speed = parsed_way.duration/(parsed_way.path.size()-1);
|
||||
parsed_way.forward.speed = parsed_way.duration/(parsed_way.path.size()-1);
|
||||
parsed_way.backward.speed = parsed_way.duration/(parsed_way.path.size()-1);
|
||||
}
|
||||
|
||||
if(FLT_EPSILON >= fabs(-1. - parsed_way.speed)){
|
||||
if( ((0<parsed_way.forward.mode) && (FLT_EPSILON >= fabs(-1. - parsed_way.forward.speed))) ||
|
||||
((0<parsed_way.backward .mode) && (FLT_EPSILON >= fabs(-1. - parsed_way.backward.speed)))
|
||||
) {
|
||||
DEBUG("found way with bogus speed, id: " << parsed_way.id);
|
||||
return;
|
||||
}
|
||||
@ -90,56 +93,54 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) {
|
||||
parsed_way.nameID = string_map_iterator->second;
|
||||
}
|
||||
|
||||
if(ExtractionWay::opposite == parsed_way.direction) {
|
||||
std::reverse( parsed_way.path.begin(), parsed_way.path.end() );
|
||||
parsed_way.direction = ExtractionWay::oneway;
|
||||
std::swap( parsed_way.forward_mode, parsed_way.backward_mode );
|
||||
}
|
||||
bool split = parsed_way.IsBidirectional() && parsed_way.HasDiffDirections();
|
||||
|
||||
bool split_bidirectional_edge =
|
||||
((parsed_way.backward_speed > 0) && (parsed_way.speed != parsed_way.backward_speed)) ||
|
||||
((ExtractionWay::bidirectional == parsed_way.direction) && (parsed_way.forward_mode != parsed_way.backward_mode));
|
||||
|
||||
for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) {
|
||||
externalMemory->allEdges.push_back(
|
||||
InternalExtractorEdge(parsed_way.path[n],
|
||||
parsed_way.path[n+1],
|
||||
(split_bidirectional_edge ? ExtractionWay::oneway : parsed_way.direction),
|
||||
parsed_way.speed,
|
||||
parsed_way.nameID,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignoreInGrid,
|
||||
(0 < parsed_way.duration),
|
||||
parsed_way.isAccessRestricted,
|
||||
parsed_way.forward_mode
|
||||
)
|
||||
);
|
||||
externalMemory->usedNodeIDs.push_back(parsed_way.path[n]);
|
||||
}
|
||||
externalMemory->usedNodeIDs.push_back(parsed_way.path.back());
|
||||
if( !parsed_way.IsOpposite() ) {
|
||||
for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) {
|
||||
externalMemory->allEdges.push_back(
|
||||
InternalExtractorEdge(parsed_way.path[n],
|
||||
parsed_way.path[n+1],
|
||||
(split ? ExtractionWay::oneway : parsed_way.Direction()),
|
||||
parsed_way.forward.speed,
|
||||
parsed_way.nameID,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignoreInGrid,
|
||||
parsed_way.HasDuration(),
|
||||
parsed_way.isAccessRestricted,
|
||||
parsed_way.forward.mode
|
||||
)
|
||||
);
|
||||
}
|
||||
//used to identify start and end segments of restrictions
|
||||
externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back()));
|
||||
}
|
||||
|
||||
//The following information is needed to identify start and end segments of restrictions
|
||||
externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back()));
|
||||
if( parsed_way.IsOpposite() || split ) {
|
||||
std::reverse( parsed_way.path.begin(), parsed_way.path.end() );
|
||||
for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) {
|
||||
externalMemory->allEdges.push_back(
|
||||
InternalExtractorEdge(parsed_way.path[n],
|
||||
parsed_way.path[n+1],
|
||||
ExtractionWay::oneway,
|
||||
parsed_way.backward.speed,
|
||||
parsed_way.nameID,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignoreInGrid,
|
||||
parsed_way.HasDuration(),
|
||||
parsed_way.isAccessRestricted,
|
||||
parsed_way.backward.mode
|
||||
)
|
||||
);
|
||||
}
|
||||
//used to identify start and end segments of restrictions
|
||||
externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back()));
|
||||
}
|
||||
|
||||
//store node ids
|
||||
for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) {
|
||||
externalMemory->usedNodeIDs.push_back(parsed_way.path[n]);
|
||||
}
|
||||
externalMemory->usedNodeIDs.push_back(parsed_way.path.back());
|
||||
|
||||
if(split_bidirectional_edge) { //Only true if the way should be split
|
||||
std::reverse( parsed_way.path.begin(), parsed_way.path.end() );
|
||||
for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) {
|
||||
externalMemory->allEdges.push_back(
|
||||
InternalExtractorEdge(parsed_way.path[n],
|
||||
parsed_way.path[n+1],
|
||||
ExtractionWay::oneway,
|
||||
parsed_way.backward_speed,
|
||||
parsed_way.nameID,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignoreInGrid,
|
||||
(0 < parsed_way.duration),
|
||||
parsed_way.isAccessRestricted,
|
||||
(ExtractionWay::oneway == parsed_way.direction),
|
||||
parsed_way.backward_mode
|
||||
)
|
||||
);
|
||||
}
|
||||
externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,44 +41,57 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
typedef boost::unordered_map<std::string, NodeID > StringMap;
|
||||
typedef boost::unordered_map<std::string, std::pair<int, short> > StringToIntPairMap;
|
||||
|
||||
|
||||
struct ExtractionWay {
|
||||
ExtractionWay() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
inline void Clear(){
|
||||
id = UINT_MAX;
|
||||
nameID = UINT_MAX;
|
||||
path.clear();
|
||||
keyVals.EraseAll();
|
||||
direction = ExtractionWay::notSure;
|
||||
speed = -1;
|
||||
backward_speed = -1;
|
||||
duration = -1;
|
||||
access = true;
|
||||
roundabout = false;
|
||||
isAccessRestricted = false;
|
||||
ignoreInGrid = false;
|
||||
forward_mode = 0;
|
||||
backward_mode = 0;
|
||||
|
||||
struct SettingsForDirection {
|
||||
SettingsForDirection() : speed(-1), mode(0) {}
|
||||
|
||||
double speed;
|
||||
TravelMode mode;
|
||||
};
|
||||
|
||||
ExtractionWay() :
|
||||
id(UINT_MAX),
|
||||
nameID(UINT_MAX),
|
||||
duration(-1),
|
||||
access(true),
|
||||
roundabout(false),
|
||||
isAccessRestricted(false),
|
||||
ignoreInGrid(false) {
|
||||
path.clear();
|
||||
keyVals.EraseAll();
|
||||
}
|
||||
|
||||
enum Directions {
|
||||
notSure = 0, oneway, bidirectional, opposite
|
||||
oneway, bidirectional, opposite
|
||||
};
|
||||
Directions direction;
|
||||
|
||||
inline bool HasDuration() { return duration>0; }
|
||||
inline bool IsBidirectional() { return forward.mode!=0 && backward.mode!=0; }
|
||||
inline bool IsOneway() { return forward.mode!=0 && backward.mode==0; }
|
||||
inline bool IsOpposite() { return forward.mode==0 && backward.mode!=0; }
|
||||
inline bool HasDiffDirections() { return (forward.mode != backward.mode) || (forward.speed != backward.speed); }
|
||||
inline Directions Direction() {
|
||||
if( IsOneway() ) {
|
||||
return ExtractionWay::oneway;
|
||||
}
|
||||
if( IsOpposite() ) {
|
||||
return ExtractionWay::opposite;
|
||||
}
|
||||
return ExtractionWay::bidirectional;
|
||||
}
|
||||
|
||||
unsigned id;
|
||||
unsigned nameID;
|
||||
std::string name;
|
||||
double speed;
|
||||
double backward_speed;
|
||||
double duration;
|
||||
bool access;
|
||||
bool roundabout;
|
||||
bool isAccessRestricted;
|
||||
bool ignoreInGrid;
|
||||
TravelMode forward_mode;
|
||||
TravelMode backward_mode;
|
||||
SettingsForDirection forward;
|
||||
SettingsForDirection backward;
|
||||
std::vector< NodeID > path;
|
||||
HashTable<std::string, std::string> keyVals;
|
||||
};
|
||||
@ -96,7 +109,6 @@ struct InternalExtractorEdge {
|
||||
InternalExtractorEdge(NodeID s, NodeID t) : start(s), target(t), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false), isDurationSet(false), isAccessRestricted(false) {}
|
||||
InternalExtractorEdge(NodeID s, NodeID t, short d, double sp): start(s), target(t), direction(d), speed(sp), nameID(0), isRoundabout(false), ignoreInGrid(false), isDurationSet(false), isAccessRestricted(false) {}
|
||||
InternalExtractorEdge(NodeID s, NodeID t, short d, double sp, unsigned nid, bool isra, bool iing, bool ids, bool iar, TravelMode _mode): start(s), target(t), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing), isDurationSet(ids), isAccessRestricted(iar), mode(_mode) {}
|
||||
InternalExtractorEdge(NodeID s, NodeID t, short d, double sp, unsigned nid, bool isra, bool iing, bool ids, bool iar, bool icf, TravelMode _mode) : start(s), target(t), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing), isDurationSet(ids), isAccessRestricted(iar), mode(_mode) {}
|
||||
NodeID start;
|
||||
NodeID target;
|
||||
short direction;
|
||||
|
||||
@ -292,12 +292,11 @@ inline void PBFParser::parseRelation(_ThreadData * threadData) {
|
||||
}
|
||||
|
||||
inline void PBFParser::parseWay(_ThreadData * threadData) {
|
||||
ExtractionWay w;
|
||||
std::vector<ExtractionWay> waysToParse;
|
||||
const int number_of_ways = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways_size();
|
||||
waysToParse.reserve(number_of_ways);
|
||||
for(int i = 0; i < number_of_ways; ++i) {
|
||||
w.Clear();
|
||||
ExtractionWay w;
|
||||
const OSMPBF::Way& inputWay = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).ways( i );
|
||||
w.id = inputWay.id();
|
||||
unsigned pathNode(0);
|
||||
|
||||
@ -68,25 +68,22 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
|
||||
luabind::class_<ExtractionWay>("Way")
|
||||
.def(luabind::constructor<>())
|
||||
.def_readwrite("name", &ExtractionWay::name)
|
||||
.def_readwrite("speed", &ExtractionWay::speed)
|
||||
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
|
||||
.def_readwrite("duration", &ExtractionWay::duration)
|
||||
.def_readwrite("access", &ExtractionWay::access)
|
||||
.def_readwrite("roundabout", &ExtractionWay::roundabout)
|
||||
.def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted)
|
||||
.def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid)
|
||||
.def_readwrite("tags", &ExtractionWay::keyVals)
|
||||
.def_readwrite("direction", &ExtractionWay::direction)
|
||||
.def_readwrite("forward_mode", &ExtractionWay::forward_mode)
|
||||
.def_readwrite("backward_mode", &ExtractionWay::backward_mode)
|
||||
.enum_("constants")
|
||||
[
|
||||
luabind::value("notSure", 0),
|
||||
luabind::value("oneway", 1),
|
||||
luabind::value("bidirectional", 2),
|
||||
luabind::value("opposite", 3)
|
||||
]
|
||||
.def_readwrite("forward", &ExtractionWay::forward)
|
||||
.def_readwrite("backward", &ExtractionWay::backward)
|
||||
];
|
||||
|
||||
luabind::module(myLuaState) [
|
||||
luabind::class_<ExtractionWay::SettingsForDirection>("WaySettingsForDirection")
|
||||
.def_readwrite("speed", &ExtractionWay::SettingsForDirection::speed)
|
||||
.def_readwrite("mode", &ExtractionWay::SettingsForDirection::mode)
|
||||
];
|
||||
|
||||
luabind::module(myLuaState) [
|
||||
luabind::class_<std::vector<std::string> >("vector")
|
||||
.def("Add", &std::vector<std::string>::push_back)
|
||||
|
||||
@ -41,14 +41,14 @@ Feature: Bike - Squares and other areas
|
||||
|
||||
When I route I should get
|
||||
| from | to | route |
|
||||
| a | b | |
|
||||
| a | d | |
|
||||
| b | c | |
|
||||
| c | b | |
|
||||
| c | d | |
|
||||
| d | c | |
|
||||
| d | a | |
|
||||
| a | d | |
|
||||
| a | b | xa |
|
||||
| a | d | xa |
|
||||
| b | c | xa |
|
||||
| c | b | xa |
|
||||
| c | d | xa |
|
||||
| d | c | xa |
|
||||
| d | a | xa |
|
||||
| a | d | xa |
|
||||
|
||||
@parking
|
||||
Scenario: Bike - parking areas
|
||||
|
||||
@ -78,4 +78,4 @@ Reference: http://wiki.openstreetmap.org/wiki/Key:cycleway
|
||||
| motorway | lane | yes | x |
|
||||
| residential | lane | yes | x |
|
||||
| footway | lane | yes | x |
|
||||
| cycleway | lane | yes | x |
|
||||
| cycleway | lane | yes | x |
|
||||
@ -5,7 +5,6 @@ Test the input data descibed on https://github.com/DennisOSRM/Project-OSRM/wiki/
|
||||
Background:
|
||||
Given the profile "testbot"
|
||||
|
||||
@smallest
|
||||
Scenario: Graph transformation
|
||||
Given the node map
|
||||
| | | d |
|
||||
|
||||
@ -126,7 +126,7 @@ function node_function (node)
|
||||
end
|
||||
end
|
||||
|
||||
return 1
|
||||
return true
|
||||
end
|
||||
|
||||
function way_function (way)
|
||||
@ -144,18 +144,18 @@ function way_function (way)
|
||||
(not man_made or man_made=='') and
|
||||
(not public_transport or public_transport=='')
|
||||
then
|
||||
return 0
|
||||
return false
|
||||
end
|
||||
|
||||
-- don't route on ways or railways that are still under construction
|
||||
if highway=='construction' or railway=='construction' then
|
||||
return 0
|
||||
return false
|
||||
end
|
||||
|
||||
-- access
|
||||
local access = Access.find_access_tag(way, access_tags_hierachy)
|
||||
if access_tag_blacklist[access] then
|
||||
return 0
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
@ -192,173 +192,168 @@ function way_function (way)
|
||||
-- this encoding scheme is excepted to be a temporary solution
|
||||
end
|
||||
|
||||
way.forward_mode = 1
|
||||
way.backward_mode = 1
|
||||
way.forward.mode = 1
|
||||
way.backward.mode = 1
|
||||
|
||||
-- speed
|
||||
if route_speeds[route] then
|
||||
-- ferries (doesn't cover routes tagged using relations)
|
||||
way.direction = Way.bidirectional
|
||||
way.ignore_in_grid = true
|
||||
if durationIsValid(duration) then
|
||||
way.duration = math.max( 1, parseDuration(duration) )
|
||||
else
|
||||
way.speed = route_speeds[route]
|
||||
way.forward.speed = route_speeds[route]
|
||||
way.backward.speed = route_speeds[route]
|
||||
end
|
||||
way.forward_mode = 2
|
||||
way.backward_mode = 2
|
||||
elseif railway and platform_speeds[railway] then
|
||||
way.forward.mode = 2
|
||||
way.backward.mode = 2
|
||||
elseif platform_speeds[railway] then
|
||||
-- railway platforms (old tagging scheme)
|
||||
way.speed = platform_speeds[railway]
|
||||
way.forward.speed = platform_speeds[railway]
|
||||
way.backward.speed = platform_speeds[railway]
|
||||
elseif platform_speeds[public_transport] then
|
||||
-- public_transport platforms (new tagging platform)
|
||||
way.speed = platform_speeds[public_transport]
|
||||
elseif railway and railway_speeds[railway] then
|
||||
way.forward.speed = platform_speeds[public_transport]
|
||||
way.backward.speed = platform_speeds[public_transport]
|
||||
elseif railway_speeds[railway] then
|
||||
-- railways
|
||||
if access and access_tag_whitelist[access] then
|
||||
way.speed = railway_speeds[railway]
|
||||
way.direction = Way.bidirectional
|
||||
way.forward.speed = railway_speeds[railway]
|
||||
way.backward.speed = railway_speeds[railway]
|
||||
end
|
||||
elseif amenity and amenity_speeds[amenity] then
|
||||
elseif amenity_speeds[amenity] then
|
||||
-- parking areas
|
||||
way.speed = amenity_speeds[amenity]
|
||||
way.forward.speed = amenity_speeds[amenity]
|
||||
way.backward.speed = amenity_speeds[amenity]
|
||||
elseif bicycle_speeds[highway] then
|
||||
-- regular ways
|
||||
way.speed = bicycle_speeds[highway]
|
||||
elseif access and access_tag_whitelist[access] then
|
||||
way.forward.speed = bicycle_speeds[highway]
|
||||
way.backward.speed = bicycle_speeds[highway]
|
||||
elseif access_tag_whitelist[access] then
|
||||
-- unknown way, but valid access tag
|
||||
way.speed = default_speed
|
||||
way.forward.speed = default_speed
|
||||
way.backward.speed = default_speed
|
||||
else
|
||||
-- biking not allowed, maybe we can push our bike?
|
||||
-- essentially requires pedestrian profiling, for example foot=no mean we can't push a bike
|
||||
if foot ~= 'no' then
|
||||
if pedestrian_speeds[highway] then
|
||||
-- pedestrian-only ways and areas
|
||||
way.speed = pedestrian_speeds[highway]
|
||||
way.forward_mode = 3
|
||||
way.backward_mode = 3
|
||||
way.forward.speed = pedestrian_speeds[highway]
|
||||
way.backward.speed = pedestrian_speeds[highway]
|
||||
way.forward.mode = 3
|
||||
way.backward.mode = 3
|
||||
elseif man_made and man_made_speeds[man_made] then
|
||||
-- man made structures
|
||||
way.speed = man_made_speeds[man_made]
|
||||
way.forward_mode = 3
|
||||
way.backward_mode = 3
|
||||
way.forward.speed = man_made_speeds[man_made]
|
||||
way.backward.speed = man_made_speeds[man_made]
|
||||
way.forward.mode = 3
|
||||
way.backward.mode = 3
|
||||
elseif foot == 'yes' then
|
||||
way.speed = walking_speed
|
||||
way.forward_mode = 3
|
||||
way.backward_mode = 3
|
||||
way.forward.speed = walking_speed
|
||||
way.backward.speed = walking_speed
|
||||
way.forward.mode = 3
|
||||
way.backward.mode = 3
|
||||
elseif foot_forward == 'yes' then
|
||||
way.speed = walking_speed
|
||||
way.forward_mode = 3
|
||||
way.backward_mode = 0
|
||||
way.forward.speed = walking_speed
|
||||
way.forward.mode = 3
|
||||
way.backward.mode = 0
|
||||
elseif foot_backward == 'yes' then
|
||||
way.speed = 0
|
||||
way.backward_speed = walking_speed
|
||||
way.forward_mode = 0
|
||||
way.backward_mode = 3
|
||||
way.backward.speed = walking_speed
|
||||
way.backward.mode = 3
|
||||
way.forward.mode = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- direction
|
||||
way.direction = Way.bidirectional
|
||||
local impliedOneway = false
|
||||
if junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
|
||||
way.direction = Way.oneway
|
||||
impliedOneway = true
|
||||
end
|
||||
|
||||
if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then
|
||||
way.direction = Way.oneway
|
||||
way.backward.mode = 0
|
||||
elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
-- prevent implied oneway
|
||||
elseif onewayClass == "-1" then
|
||||
way.direction = Way.opposite
|
||||
way.forward.mode = 0
|
||||
elseif oneway == "no" or oneway == "0" or oneway == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
elseif cycleway and string.find(cycleway, "opposite") == 1 then
|
||||
-- prevent implied oneway
|
||||
elseif string.find(cycleway, "opposite") == 1 then
|
||||
if impliedOneway then
|
||||
way.direction = Way.opposite
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.forward.mode = 0
|
||||
way.backward.mode = 1
|
||||
end
|
||||
elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then
|
||||
way.direction = Way.bidirectional
|
||||
elseif cycleway_left and cycleway_tags[cycleway_left] then
|
||||
elseif cycleway_tags[cycleway_left] and cycleway_tags[cycleway_right] then
|
||||
-- prevent implied
|
||||
elseif cycleway_tags[cycleway_left] then
|
||||
if impliedOneway then
|
||||
way.direction = Way.opposite
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.forward.mode = 0
|
||||
way.backward.mode = 1
|
||||
end
|
||||
elseif cycleway_right and cycleway_tags[cycleway_right] then
|
||||
elseif cycleway_tags[cycleway_right] then
|
||||
if impliedOneway then
|
||||
way.direction = Way.oneway
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.forward.mode = 1
|
||||
way.backward.mode = 0
|
||||
end
|
||||
elseif oneway == "-1" then
|
||||
way.direction = Way.opposite
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" then
|
||||
way.direction = Way.oneway
|
||||
end
|
||||
way.forward.mode = 0
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" or impliedOneway then
|
||||
way.backward.mode = 0
|
||||
end
|
||||
|
||||
|
||||
-- pushing bikes
|
||||
if bicycle_speeds[highway] or pedestrian_speeds[highway] then
|
||||
if foot ~= 'no' then
|
||||
if foot ~= "no" then
|
||||
if junction ~= "roundabout" then
|
||||
if way.direction == Way.oneway then
|
||||
way.backward_speed = walking_speed
|
||||
way.backward_mode = 3
|
||||
elseif way.direction == Way.opposite then
|
||||
way.backward_speed = walking_speed
|
||||
way.backward_mode = 3
|
||||
way.speed = way.speed
|
||||
if way.backward.mode == 0 then
|
||||
way.backward.speed = walking_speed
|
||||
way.backward.mode = 3
|
||||
elseif way.forward.mode == 0 then
|
||||
way.forward.speed = walking_speed
|
||||
way.forward.mode = 3
|
||||
end
|
||||
end
|
||||
end
|
||||
if way.backward_speed == way.speed then
|
||||
way.direction = Way.bidirectional
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- cycleways
|
||||
if cycleway and cycleway_tags[cycleway] then
|
||||
way.speed = bicycle_speeds["cycleway"]
|
||||
elseif cycleway_left and cycleway_tags[cycleway_left] then
|
||||
way.speed = bicycle_speeds["cycleway"]
|
||||
elseif cycleway_right and cycleway_tags[cycleway_right] then
|
||||
way.speed = bicycle_speeds["cycleway"]
|
||||
-- cycleway speed
|
||||
if cycleway_tags[cycleway_right] then
|
||||
way.forward.speed = bicycle_speeds["cycleway"]
|
||||
elseif cycleway_tags[cycleway] then
|
||||
way.forward.speed = bicycle_speeds["cycleway"]
|
||||
end
|
||||
if cycleway_tags[cycleway_left] then
|
||||
way.backward.speed = bicycle_speeds["cycleway"]
|
||||
elseif cycleway_tags[cycleway] then
|
||||
way.backward.speed = bicycle_speeds["cycleway"]
|
||||
end
|
||||
|
||||
-- surfaces
|
||||
if surface then
|
||||
surface_speed = surface_speeds[surface]
|
||||
if surface_speed then
|
||||
way.speed = math.min(way.speed, surface_speed)
|
||||
way.backward_speed = math.min(way.backward_speed, surface_speed)
|
||||
way.forward.speed = math.min(way.forward.speed, surface_speed)
|
||||
way.backward.speed = math.min(way.backward.speed, surface_speed)
|
||||
end
|
||||
end
|
||||
|
||||
-- maxspeed
|
||||
-- TODO: maxspeed of backward direction
|
||||
if take_minimum_of_speeds then
|
||||
if maxspeed and maxspeed>0 then
|
||||
way.speed = math.min(way.speed, maxspeed)
|
||||
end
|
||||
if maxspeed_forward and maxspeed_forward>0 then
|
||||
way.forward.speed = math.min(way.forward.speed, maxspeed_forward)
|
||||
elseif maxspeed and maxspeed>0 then
|
||||
way.forward.speed = math.min(way.forward.speed, maxspeed)
|
||||
end
|
||||
|
||||
-- Override speed settings if explicit forward/backward maxspeeds are given
|
||||
if maxspeed_forward ~= nil and maxspeed_forward > 0 then
|
||||
if Way.bidirectional == way.direction then
|
||||
way.backward_speed = way.speed
|
||||
end
|
||||
way.speed = maxspeed_forward
|
||||
end
|
||||
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
|
||||
way.backward_speed = maxspeed_backward
|
||||
end
|
||||
|
||||
return 1
|
||||
|
||||
if maxspeed_backward and maxspeed_backward>0 then
|
||||
way.backward.speed = math.min(way.backward.speed, maxspeed_backward)
|
||||
elseif maxspeed and maxspeed>0 then
|
||||
way.backward.speed = math.min(way.backward.speed, maxspeed)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function turn_function (angle)
|
||||
|
||||
@ -130,39 +130,46 @@ function way_function (way)
|
||||
if "roundabout" == junction then
|
||||
way.roundabout = true;
|
||||
end
|
||||
|
||||
|
||||
-- Handling ferries and piers
|
||||
if (speed_profile[route] ~= nil and speed_profile[route] > 0) then
|
||||
if durationIsValid(duration) then
|
||||
way.duration = math.max( parseDuration(duration), 1 );
|
||||
way.forward.mode = 2
|
||||
way.backward.mode = 2
|
||||
end
|
||||
way.direction = Way.bidirectional
|
||||
if speed_profile[route] ~= nil then
|
||||
highway = route;
|
||||
end
|
||||
if tonumber(way.duration) < 0 then
|
||||
way.speed = speed_profile[highway]
|
||||
way.forward.speed = speed_profile[highway]
|
||||
way.backward.speed = speed_profile[highway]
|
||||
end
|
||||
end
|
||||
|
||||
-- Set the avg speed on the way if it is accessible by road class
|
||||
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
|
||||
if speed_profile[highway] ~= nil then
|
||||
way.forward.mode = 1
|
||||
way.backward.mode = 1
|
||||
if maxspeed > speed_profile[highway] then
|
||||
way.speed = maxspeed
|
||||
way.forward.speed = maxspeed
|
||||
way.backward.speed = maxspeed
|
||||
else
|
||||
if 0 == maxspeed then
|
||||
maxspeed = math.huge
|
||||
end
|
||||
way.speed = math.min(speed_profile[highway], maxspeed)
|
||||
way.forward.speed = math.min(speed_profile[highway], maxspeed)
|
||||
way.backward.speed = math.min(speed_profile[highway], maxspeed)
|
||||
end
|
||||
end
|
||||
|
||||
-- Set the avg speed on ways that are marked accessible
|
||||
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
|
||||
if "" ~= highway and access_tag_whitelist[access] then
|
||||
if 0 == maxspeed then
|
||||
maxspeed = math.huge
|
||||
end
|
||||
way.speed = math.min(speed_profile["default"], maxspeed)
|
||||
way.forward.speed = math.min(speed_profile["default"], maxspeed)
|
||||
way.backward.speed = math.min(speed_profile["default"], maxspeed)
|
||||
end
|
||||
|
||||
-- Set access restriction flag if access is allowed under certain restrictions only
|
||||
@ -178,27 +185,23 @@ function way_function (way)
|
||||
-- Set direction according to tags on way
|
||||
if obey_oneway then
|
||||
if oneway == "no" or oneway == "0" or oneway == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
--
|
||||
elseif oneway == "-1" then
|
||||
way.direction = Way.opposite
|
||||
way.forward.mode = 0
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
|
||||
way.direction = Way.oneway
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.backward.mode = 0
|
||||
end
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
end
|
||||
|
||||
-- Override speed settings if explicit forward/backward maxspeeds are given
|
||||
if maxspeed_forward ~= nil and maxspeed_forward > 0 then
|
||||
if Way.bidirectional == way.direction then
|
||||
way.backward_speed = way.speed
|
||||
if way.forward.mode>0 and way.backward.mode>0 then
|
||||
way.backward.speed = way.forward.speed
|
||||
end
|
||||
way.speed = maxspeed_forward
|
||||
way.forward.speed = maxspeed_forward
|
||||
end
|
||||
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
|
||||
way.backward_speed = maxspeed_backward
|
||||
way.backward.speed = maxspeed_backward
|
||||
end
|
||||
|
||||
-- Override general direction settings of there is a specific one for our mode of travel
|
||||
|
||||
@ -6,31 +6,31 @@ bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] =
|
||||
access_tag_whitelist = { ["yes"] = true, ["foot"] = true, ["permissive"] = true, ["designated"] = true }
|
||||
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true }
|
||||
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
|
||||
access_tags = { "foot" }
|
||||
access_tags = { "foot", "access" }
|
||||
service_tag_restricted = { ["parking_aisle"] = true }
|
||||
ignore_in_grid = { ["ferry"] = true }
|
||||
restriction_exception_tags = { "foot" }
|
||||
|
||||
speed_profile = {
|
||||
["primary"] = 5,
|
||||
["primary_link"] = 5,
|
||||
["secondary"] = 5,
|
||||
["secondary_link"] = 5,
|
||||
["tertiary"] = 5,
|
||||
["tertiary_link"] = 5,
|
||||
["unclassified"] = 5,
|
||||
["residential"] = 5,
|
||||
["road"] = 5,
|
||||
["living_street"] = 5,
|
||||
["service"] = 5,
|
||||
["track"] = 5,
|
||||
["path"] = 5,
|
||||
["steps"] = 5,
|
||||
["ferry"] = 5,
|
||||
["pedestrian"] = 5,
|
||||
["footway"] = 5,
|
||||
["pier"] = 5,
|
||||
["default"] = 5
|
||||
["primary"] = 5,
|
||||
["primary_link"] = 5,
|
||||
["secondary"] = 5,
|
||||
["secondary_link"] = 5,
|
||||
["tertiary"] = 5,
|
||||
["tertiary_link"] = 5,
|
||||
["unclassified"] = 5,
|
||||
["residential"] = 5,
|
||||
["road"] = 5,
|
||||
["living_street"] = 5,
|
||||
["service"] = 5,
|
||||
["track"] = 5,
|
||||
["path"] = 5,
|
||||
["steps"] = 5,
|
||||
["ferry"] = 5,
|
||||
["pedestrian"] = 5,
|
||||
["footway"] = 5,
|
||||
["pier"] = 5,
|
||||
["default"] = 5
|
||||
}
|
||||
|
||||
|
||||
@ -45,39 +45,39 @@ use_turn_restrictions = false
|
||||
-- End of globals
|
||||
|
||||
function get_exceptions(vector)
|
||||
for i,v in ipairs(restriction_exception_tags) do
|
||||
vector:Add(v)
|
||||
end
|
||||
for i,v in ipairs(restriction_exception_tags) do
|
||||
vector:Add(v)
|
||||
end
|
||||
end
|
||||
|
||||
function node_function (node)
|
||||
local barrier = node.tags:Find ("barrier")
|
||||
local access = node.tags:Find ("access")
|
||||
local traffic_signal = node.tags:Find("highway")
|
||||
|
||||
--flag node if it carries a traffic light
|
||||
|
||||
if traffic_signal == "traffic_signals" then
|
||||
node.traffic_light = true;
|
||||
end
|
||||
|
||||
if obey_bollards then
|
||||
--flag node as unpassable if it black listed as unpassable
|
||||
if access_tag_blacklist[barrier] then
|
||||
node.bollard = true;
|
||||
end
|
||||
|
||||
--reverse the previous flag if there is an access tag specifying entrance
|
||||
if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then
|
||||
node.bollard = false;
|
||||
end
|
||||
end
|
||||
return 1
|
||||
local barrier = node.tags:Find ("barrier")
|
||||
local access = node.tags:Find ("access")
|
||||
local traffic_signal = node.tags:Find("highway")
|
||||
|
||||
--flag node if it carries a traffic light
|
||||
|
||||
if traffic_signal == "traffic_signals" then
|
||||
node.traffic_light = true;
|
||||
end
|
||||
|
||||
if obey_bollards then
|
||||
--flag node as unpassable if it black listed as unpassable
|
||||
if access_tag_blacklist[barrier] then
|
||||
node.bollard = true;
|
||||
end
|
||||
|
||||
--reverse the previous flag if there is an access tag specifying entrance
|
||||
if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then
|
||||
node.bollard = false;
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function way_function (way)
|
||||
|
||||
-- First, get the properties of each way that we come across
|
||||
-- First, get the properties of each way that we come across
|
||||
local highway = way.tags:Find("highway")
|
||||
local name = way.tags:Find("name")
|
||||
local ref = way.tags:Find("ref")
|
||||
@ -87,106 +87,81 @@ function way_function (way)
|
||||
local man_made = way.tags:Find("man_made")
|
||||
local barrier = way.tags:Find("barrier")
|
||||
local oneway = way.tags:Find("oneway")
|
||||
local onewayClass = way.tags:Find("oneway:foot")
|
||||
local onewayClass = way.tags:Find("oneway:foot")
|
||||
local duration = way.tags:Find("duration")
|
||||
local service = way.tags:Find("service")
|
||||
local area = way.tags:Find("area")
|
||||
local access = way.tags:Find("access")
|
||||
|
||||
-- Second parse the way according to these properties
|
||||
-- Second parse the way according to these properties
|
||||
|
||||
if ignore_areas and ("yes" == area) then
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Check if we are allowed to access the way
|
||||
if access_tag_blacklist[access] ~=nil and access_tag_blacklist[access] then
|
||||
return 0;
|
||||
if ignore_areas and "yes"==area then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Check if our vehicle types are forbidden
|
||||
|
||||
-- Check if we are allowed to access the way
|
||||
if access_tag_blacklist[access] and access_tag_blacklist[access] then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Check if our vehicle types are forbidden
|
||||
for i,v in ipairs(access_tags) do
|
||||
local mode_value = way.tags:Find(v)
|
||||
if nil ~= mode_value and "no" == mode_value then
|
||||
return 0;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Set the name that will be used for instructions
|
||||
if "" ~= ref then
|
||||
way.name = ref
|
||||
elseif "" ~= name then
|
||||
way.name = name
|
||||
end
|
||||
|
||||
if "roundabout" == junction then
|
||||
way.roundabout = true;
|
||||
end
|
||||
|
||||
-- Handling ferries and piers
|
||||
|
||||
if (speed_profile[route] ~= nil and speed_profile[route] > 0) or
|
||||
(speed_profile[man_made] ~= nil and speed_profile[man_made] > 0)
|
||||
then
|
||||
if durationIsValid(duration) then
|
||||
way.speed = parseDuration(duration) / math.max(1, numberOfNodesInWay-1);
|
||||
way.is_duration_set = true;
|
||||
end
|
||||
way.direction = Way.bidirectional;
|
||||
if speed_profile[route] ~= nil then
|
||||
highway = route;
|
||||
elseif speed_profile[man_made] ~= nil then
|
||||
highway = man_made;
|
||||
end
|
||||
if not way.is_duration_set then
|
||||
way.speed = speed_profile[highway]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Set the avg speed on the way if it is accessible by road class
|
||||
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
|
||||
way.speed = speed_profile[highway]
|
||||
end
|
||||
|
||||
-- Set the avg speed on ways that are marked accessible
|
||||
if access_tag_whitelist[access] and way.speed == -1 then
|
||||
if (0 < maxspeed and not take_minimum_of_speeds) or maxspeed == 0 then
|
||||
maxspeed = math.huge
|
||||
end
|
||||
way.speed = math.min(speed_profile["default"], maxspeed)
|
||||
local mode_value = way.tags:Find(v)
|
||||
if mode_value and "no"==mode_value then
|
||||
return 0;
|
||||
end
|
||||
end
|
||||
|
||||
-- Set access restriction flag if access is allowed under certain restrictions only
|
||||
if access ~= "" and access_tag_restricted[access] then
|
||||
way.is_access_restricted = true
|
||||
|
||||
-- Set the name that will be used for instructions
|
||||
if "" ~= ref then
|
||||
way.name = ref
|
||||
elseif "" ~= name then
|
||||
way.name = name
|
||||
end
|
||||
|
||||
-- Set access restriction flag if service is allowed under certain restrictions only
|
||||
if service ~= "" and service_tag_restricted[service] then
|
||||
way.is_access_restricted = true
|
||||
if "roundabout" == junction then
|
||||
way.roundabout = true;
|
||||
end
|
||||
|
||||
-- Set direction according to tags on way
|
||||
if obey_oneway then
|
||||
if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then
|
||||
way.direction = Way.oneway
|
||||
elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
elseif onewayClass == "-1" then
|
||||
way.direction = Way.opposite
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
end
|
||||
|
||||
-- Handling ferries and piers
|
||||
if (speed_profile[route] and speed_profile[route]>0) or (speed_profile[man_made] and speed_profile[man_made]>0) then
|
||||
way.forward.mode = 2
|
||||
way.backward.mode = 2
|
||||
if durationIsValid(duration) then
|
||||
way.duration = math.max( 1, parseDuration(duration) )
|
||||
else
|
||||
way.forward.speed = speed_profile[highway]
|
||||
way.backward.speed = speed_profile[highway]
|
||||
end
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
if speed_profile[route] then
|
||||
highway = route
|
||||
elseif speed_profile[man_made] then
|
||||
highway = man_made
|
||||
end
|
||||
if speed_profile[highway] then
|
||||
way.forward.mode = 1
|
||||
way.backward.mode = 1
|
||||
way.forward.speed = speed_profile[highway]
|
||||
way.backward.speed = speed_profile[highway]
|
||||
end
|
||||
|
||||
-- ignore oneway, but respect oneway:foot
|
||||
if onewayClass=="yes" or onewayClass=="1" or onewayClass=="true" then
|
||||
way.backward.mode = 0
|
||||
elseif onewayClass=="-1" then
|
||||
way.forward.mode = 0
|
||||
end
|
||||
|
||||
-- restricted areas
|
||||
if access_tag_restricted[access] then
|
||||
way.is_access_restricted = true
|
||||
end
|
||||
if service_tag_restricted[service] then
|
||||
way.is_access_restricted = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Override general direction settings of there is a specific one for our mode of travel
|
||||
|
||||
if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then
|
||||
way.ignore_in_grid = true
|
||||
end
|
||||
return 1
|
||||
return true
|
||||
end
|
||||
|
||||
@ -73,61 +73,53 @@ function way_function (way)
|
||||
local maxspeed_forward = tonumber(way.tags:Find( "maxspeed:forward"))
|
||||
local maxspeed_backward = tonumber(way.tags:Find( "maxspeed:backward"))
|
||||
|
||||
way.forward_mode = 1
|
||||
way.backward_mode = 1
|
||||
way.name = name
|
||||
|
||||
if route ~= nil and durationIsValid(duration) then
|
||||
way.duration = math.max( 1, parseDuration(duration) )
|
||||
way.forward_mode = 2
|
||||
way.backward_mode = 2
|
||||
way.forward.mode = 2
|
||||
way.backward.mode = 2
|
||||
else
|
||||
local speed_forw = speed_profile[highway] or speed_profile['default']
|
||||
local speed_back = speed_forw
|
||||
local speed = speed_profile[highway] or speed_profile['default']
|
||||
|
||||
if highway == "river" then
|
||||
local temp_speed = speed_forw;
|
||||
speed_forw = temp_speed*1.5
|
||||
speed_back = temp_speed/1.5
|
||||
way.forward_mode = 3
|
||||
way.backward_mode = 4
|
||||
end
|
||||
|
||||
if highway == "steps" then
|
||||
way.forward_mode = 5
|
||||
way.backward_mode = 6
|
||||
way.forward.mode = 3
|
||||
way.backward.mode = 4
|
||||
way.forward.speed = speed*1.5
|
||||
way.backward.speed = speed/1.5
|
||||
else
|
||||
if highway == "steps" then
|
||||
way.forward.mode = 5
|
||||
way.backward.mode = 6
|
||||
else
|
||||
way.forward.mode = 1
|
||||
way.backward.mode = 1
|
||||
end
|
||||
way.forward.speed = speed
|
||||
way.backward.speed = speed
|
||||
end
|
||||
|
||||
if maxspeed_forward ~= nil and maxspeed_forward > 0 then
|
||||
speed_forw = maxspeed_forward
|
||||
way.forward.speed = maxspeed_forward
|
||||
else
|
||||
if maxspeed ~= nil and maxspeed > 0 and speed_forw > maxspeed then
|
||||
speed_forw = maxspeed
|
||||
if maxspeed ~= nil and maxspeed > 0 and way.forward.speed > maxspeed then
|
||||
way.forward.speed = maxspeed
|
||||
end
|
||||
end
|
||||
|
||||
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
|
||||
speed_back = maxspeed_backward
|
||||
way.backward.speed = maxspeed_backward
|
||||
else
|
||||
if maxspeed ~=nil and maxspeed > 0 and speed_back > maxspeed then
|
||||
speed_back = maxspeed
|
||||
if maxspeed ~=nil and maxspeed > 0 and way.backward.speed > maxspeed then
|
||||
way.backward.speed = maxspeed
|
||||
end
|
||||
end
|
||||
|
||||
way.speed = speed_forw
|
||||
if speed_back ~= way_forw then
|
||||
way.backward_speed = speed_back
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if oneway == "no" or oneway == "0" or oneway == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
elseif oneway == "-1" then
|
||||
way.direction = Way.opposite
|
||||
if oneway == "-1" then
|
||||
way.forward.mode = 0
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" then
|
||||
way.direction = Way.oneway
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
way.backward.mode = 0
|
||||
end
|
||||
|
||||
return 1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user