Test cases for route relation cardinal directions.

This commit is contained in:
Daniel Patterson 2017-10-03 23:47:17 -07:00 committed by Patrick Niklaus
parent fc9a89ea8b
commit 6b357a7783
4 changed files with 243 additions and 58 deletions

View File

@ -3,66 +3,230 @@ Feature: Car - route relations
Background: Background:
Given the profile "car" Given the profile "car"
@sliproads Scenario: Assignment using relation membership roles
Scenario: Cardinal direction assignment to refs
Given the node map Given the node map
""" """
a b a----------------b
| | c----------------d
c------+--+------d
e------+--+------f
| |
g h
i----------------j
k----------------l
x----------------y
z----------------w
""" """
And the ways And the ways
| nodes | name | highway | ref | | nodes | name | highway | ref |
| ag | southbound | motorway | I 80 | | ba | westbound | motorway | I 80 |
| hb | northbound | motorway | I 80 | | cd | eastbound | motorway | I 80;CO 93 |
| dc | westbound | motorway | I 85;CO 93 |
| ef | eastbound | motorway | I 85;US 12 |
| ij | westbound-2 | motorway | I 99 |
| ji | eastbound-2 | motorway | I 99 |
| kl | eastbound-2 | motorway | I 99 |
| lk | eastbound-2 | motorway | I 99 |
| xy | watermill | motorway | I 45M; US 3 |
And the relations And the relations
| type | way:south | route | ref | | type | way:east | way:west | route | ref | network |
| route | ag | road | 80 | | route | cd | ba | road | 80 | US:I |
| route | ef | road | 12 | | route | cd | ba | road | 93 | US:CO |
And the relations
| type | way:north | route | ref |
| route | hb | road | 80 |
| route | cd | road | 93 |
And the relations
| type | way:west | route | ref |
| route | dc | road | 85 |
| route | ij | road | 99 |
| route | xy | road | I 45 |
And the relations
| type | way:east | route | ref |
| route | lk | road | I 99 |
And the relations
| type | way:east | route | ref |
| route | xy | road | US 3 |
When I route I should get When I route I should get
| waypoints | route | ref | | waypoints | route | ref |
| a,g | southbound,southbound | I 80 $south,I 80 $south | | b,a | westbound,westbound | I 80 $west,I 80 $west |
| h,b | northbound,northbound | I 80 $north,I 80 $north | | c,d | eastbound,eastbound | I 80 $east; CO 93 $east,I 80 $east; CO 93 $east |
| d,c | westbound,westbound | I 85 $west; CO 93 $north,I 85 $west; CO 93 $north |
| e,f | eastbound,eastbound | I 85; US 12 $south,I 85; US 12 $south | Scenario: Assignment using relation direction property (no role on members)
| i,j | westbound-2,westbound-2 | I 99 $west,I 99 $west | Given the node map
| l,k | eastbound-2,eastbound-2 | I 99 $east,I 99 $east | """
| x,y | watermill,watermill | I 45M $west; US 3 $east,I 45M $west; US 3 $east | a----------------b
c----------------d
"""
And the ways
| nodes | name | highway | ref |
| ba | westbound | motorway | I 80 |
| cd | eastbound | motorway | I 80;CO 93 |
And the relations
| type | direction | way | route | ref | network |
| route | west | ba | road | 80 | US:I |
| route | east | cd | road | 80 | US:I |
| route | east | cd | road | 93 | US:CO |
When I route I should get
| waypoints | route | ref |
| b,a | westbound,westbound | I 80 $west,I 80 $west |
| c,d | eastbound,eastbound | I 80 $east; CO 93 $east,I 80 $east; CO 93 $east |
Scenario: Forward assignment on one-way roads using relation direction property
Given the node map
"""
a----------------b
c----------------d
"""
And the ways
| nodes | name | highway | ref |
| ba | westbound | motorway | I 80 |
| cd | eastbound | motorway | I 80;CO 93 |
And the relations
| type | direction | way:forward | route | ref | network |
| route | west | ba | road | 80 | US:I |
| route | east | cd | road | 80 | US:I |
| route | east | cd | road | 93 | US:CO |
When I route I should get
| waypoints | route | ref |
| b,a | westbound,westbound | I 80 $west,I 80 $west |
| c,d | eastbound,eastbound | I 80 $east; CO 93 $east,I 80 $east; CO 93 $east |
Scenario: Forward/backward assignment on non-divided roads with role direction tag
Given the node map
"""
a----------------b
"""
And the ways
| nodes | name | highway | ref | oneway |
| ab | mainroad | motorway | I 80 | no |
And the relations
| type | direction | way:forward | route | ref | network |
| route | west | ab | road | 80 | US:I |
And the relations
| type | direction | way:backward | route | ref | network |
| route | east | ab | road | 80 | US:I |
When I route I should get
| waypoints | route | ref |
| b,a | mainroad,mainroad | I 80 $west,I 80 $west |
| a,b | mainroad,mainroad | I 80 $east,I 80 $east |
Scenario: Conflict between role and direction
Given the node map
"""
a----------------b
"""
And the ways
| nodes | name | highway | ref |
| ab | eastbound | motorway | I 80 |
And the relations
| type | direction | way:east | route | ref | network |
| route | west | ab | road | 80 | US:I |
When I route I should get
| waypoints | route | ref |
| a,b | eastbound,eastbound | I 80,I 80 |
Scenario: Conflict between role and superrelation direction
Given the node map
"""
a----------------b
"""
And the ways
| nodes | name | highway | ref |
| ab | eastbound | motorway | I 80 |
And the relations
| type | way:east | route | ref | network | name |
| route | ab | road | 80 | US:I | baserelation |
And the relations
| type | direction | relation | route | ref | network | name |
| route | east | baserelation | road | 80 | US:I | superrelation |
When I route I should get
| waypoints | route | ref |
| a,b | eastbound,eastbound | I 80,I 80 |
Scenario: Conflict between role and superrelation role
Given the node map
"""
a----------------b
"""
And the ways
| nodes | name | highway | ref |
| ab | eastbound | motorway | I 80 |
And the relations
| type | way:east | route | ref | network | name |
| route | ab | road | 80 | US:I | baserelation |
And the relations
| type | relation:west | route | ref | network | name |
| route | baserelation | road | 80 | US:I | superrelation |
When I route I should get
| waypoints | route | ref |
| a,b | eastbound,eastbound | I 80,I 80 |
Scenario: Direction only available via superrelation role
Given the node map
"""
a----------------b
"""
And the ways
| nodes | name | highway | ref |
| ab | eastbound | motorway | I 80 |
And the relations
| type | way:forward | route | ref | network | name |
| route | ab | road | 80 | US:I | baserelation |
And the relations
| type | relation:east | route | ref | network | name |
| route | baserelation | road | 80 | US:I | superrelation |
When I route I should get
| waypoints | route | ref |
| a,b | eastbound,eastbound | I 80 $east,I 80 $east |
Scenario: Direction only available via superrelation direction
Given the node map
"""
a----------------b
"""
And the ways
| nodes | name | highway | ref |
| ab | eastbound | motorway | I 80 |
And the relations
| type | way:forward | route | ref | network | name |
| route | ab | road | 80 | US:I | baserelation |
And the relations
| type | direction | relation | route | ref | network | name |
| route | east | baserelation | road | 80 | US:I | superrelation |
When I route I should get
| waypoints | route | ref |
| a,b | eastbound,eastbound | I 80 $east,I 80 $east |
Scenario: Three levels of indirection
Given the node map
"""
a----------------b
"""
And the ways
| nodes | name | highway | ref |
| ab | eastbound | motorway | I 80 |
And the relations
| type | way:forward | route | ref | network | name |
| route | ab | road | 80 | US:I | baserelation |
And the relations
| type | relation | route | ref | network | name |
| route | baserelation | road | 80 | US:I | superrelation1 |
And the relations
| type | direction | relation | route | ref | network | name |
| route | east | superrelation1 | road | 80 | US:I | superrelation2 |
When I route I should get
| waypoints | route | ref |
| a,b | eastbound,eastbound | I 80 $east,I 80 $east |

View File

@ -86,11 +86,12 @@ class DB {
}); });
r.members.forEach((m) => { r.members.forEach((m) => {
relation.ele('member', { var d = {
type: m.type, type: m.type,
ref: m.id, ref: m.id
role: m.role };
}); if (m.role) d.role = m.role;
relation.ele('member', d);
}); });
for (var k in r.tags) { for (var k in r.tags) {

View File

@ -188,9 +188,12 @@ module.exports = function () {
let addRelation = (row, cb) => { let addRelation = (row, cb) => {
let relation = new OSM.Relation(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID); let relation = new OSM.Relation(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
var name = null;
for (let key in row) { for (let key in row) {
let isNode = key.match(/^node:(.*)/), let isNode = key.match(/^node:?(.*)/),
isWay = key.match(/^way:(.*)/), isWay = key.match(/^way:?(.*)/),
isRelation = key.match(/^relation:?(.*)/),
isColonSeparated = key.match(/^(.*):(.*)/); isColonSeparated = key.match(/^(.*):(.*)/);
if (isNode) { if (isNode) {
row[key].split(',').map(function(v) { return v.trim(); }).forEach((nodeName) => { row[key].split(',').map(function(v) { return v.trim(); }).forEach((nodeName) => {
@ -205,14 +208,26 @@ module.exports = function () {
if (!way) throw new Error(util.format('*** unknown relation way member "%s"', wayName)); if (!way) throw new Error(util.format('*** unknown relation way member "%s"', wayName));
relation.addMember('way', way.id, isWay[1]); relation.addMember('way', way.id, isWay[1]);
}); });
} else if (isRelation) {
row[key].split(',').map(function(v) { return v.trim(); }).forEach((relName) => {
let otherrelation = this.findRelationByName(relName);
if (!otherrelation) throw new Error(util.format('*** unknown relation relation member "%s"', relName));
relation.addMember('relation', otherrelation.id, isRelation[1]);
});
} else if (isColonSeparated && isColonSeparated[1] !== 'restriction') { } else if (isColonSeparated && isColonSeparated[1] !== 'restriction') {
throw new Error(util.format('*** unknown relation member type "%s:%s", must be either "node" or "way"', isColonSeparated[1], isColonSeparated[2])); throw new Error(util.format('*** unknown relation member type "%s:%s", must be either "node" or "way"', isColonSeparated[1], isColonSeparated[2]));
} else { } else {
relation.addTag(key, row[key]); relation.addTag(key, row[key]);
if (key.match(/name/)) name = row[key];
} }
} }
relation.uid = this.OSM_UID; relation.uid = this.OSM_UID;
if (name) {
this.nameRelationHash[name] = relation;
}
this.OSMDB.addRelation(relation); this.OSMDB.addRelation(relation);
cb(); cb();

View File

@ -144,6 +144,10 @@ module.exports = function () {
return this.nameWayHash[s.toString()] || this.nameWayHash[s.toString().split('').reverse().join('')]; return this.nameWayHash[s.toString()] || this.nameWayHash[s.toString().split('').reverse().join('')];
}; };
this.findRelationByName = (s) => {
return this.nameRelationHash[s.toString()] || this.nameRelationHash[s.toString().split('').reverse().join('')];
};
this.makeOSMId = () => { this.makeOSMId = () => {
this.osmID = this.osmID + 1; this.osmID = this.osmID + 1;
return this.osmID; return this.osmID;
@ -155,6 +159,7 @@ module.exports = function () {
this.locationHash = {}; this.locationHash = {};
this.shortcutsHash = {}; this.shortcutsHash = {};
this.nameWayHash = {}; this.nameWayHash = {};
this.nameRelationHash = {};
this.osmID = 0; this.osmID = 0;
}; };