Skip to content

Commit f9c7e1e

Browse files
deniskoronchikPatrick Niklaus
authored andcommitted
Support route relation tests
1 parent 4b8daac commit f9c7e1e

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

features/car/route_relations.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Feature: Car - route relations
2222

2323

2424
When I route I should get
25-
| waypoints | route | ref |
26-
| b,a | westbound,westbound | I 80 $west,I 80 $west |
25+
| waypoints | route | ref |
26+
| b,a | westbound,westbound | I 80 $west,I 80 $west |
2727
| c,d | eastbound,eastbound | I 80 $east; CO 93 $east,I 80 $east; CO 93 $east |
2828

2929
Scenario: Assignment using relation direction property (no role on members)
@@ -133,7 +133,7 @@ Feature: Car - route relations
133133

134134
And the relations
135135
| type | direction | relation | route | ref | network | name |
136-
| route | east | baserelation | road | 80 | US:I | superrelation |
136+
| route | west | baserelation | road | 80 | US:I | superrelation |
137137

138138
When I route I should get
139139
| waypoints | route | ref |

profiles/car.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ function process_way(profile, way, result, relations)
427427
end
428428
end
429429

430+
-- print(result.name, ref)
431+
430432
result.ref = ref
431433
end
432434
end

profiles/lib/relations.lua

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function get_direction_from_superrel(rel, relations)
103103
function set_result(direction, current_rel)
104104
if (result ~= nil) and (direction ~= nil) then
105105
print('WARNING: relation ' .. rel:id() .. ' is a part of more then one supperrelations ' .. result_id .. ' and ' .. current_rel:id())
106+
result = nil
106107
else
107108
result = direction
108109
result_id = current_rel:id()
@@ -147,41 +148,54 @@ function Relations.parse_route_relation(rel, way, relations)
147148
end
148149

149150
if t == 'route' then
151+
local role_direction = nil
150152
local route = rel:get_value_by_key("route")
151153
if route == 'road' then
152154
-- process case, where directions set as role
153155
if is_direction(role) then
154-
result['route_direction'] = role
155-
add_extra_data(m)
156+
role_direction = role
156157
end
157158
end
158159

160+
local tag_direction = nil
159161
local direction = rel:get_value_by_key('direction')
160162
if direction then
161163
direction = string.lower(direction)
162164
if is_direction(direction) then
163-
if role == 'forward' then
164-
result['route_direction'] = direction
165-
add_extra_data(m)
166-
end
165+
tag_direction = direction
167166
end
168167
end
169-
end
170168

171-
-- process superrelations
172-
local super_dir = get_direction_from_superrel(rel, relations)
169+
-- determine direction
170+
local result_direction = role_direction
171+
if result_direction == nil and tag_direction ~= '' then
172+
result_direction = tag_direction
173+
end
173174

174-
-- check if there are data error
175-
local dir = result['route_direction']
176-
if (dir ~= nil) and (super_dir ~= nil) and (dir ~= super_dir) then
177-
print('ERROR: conflicting relation directions found for way ' .. way:id() ..
178-
' relation direction is ' .. dir .. ' superrelation direction is ' .. super_dir)
179-
end
175+
if role_direction ~= nil and tag_direction ~= nil and role_direction ~= tag_direction then
176+
result_direction = nil
177+
print('WARNING: conflict direction in role of way ' .. way:id() .. ' and direction tag in relation ' .. rel:id())
178+
end
180179

181-
if (dir == nil) and (super_dir ~= nil) then
182-
result['route_direction'] = super_dir
180+
181+
-- process superrelations
182+
local super_dir = get_direction_from_superrel(rel, relations)
183+
184+
-- check if there are data error
185+
186+
if (result_direction ~= nil) and (super_dir ~= nil) and (result_direction ~= super_dir) then
187+
print('ERROR: conflicting relation directions found for way ' .. way:id() ..
188+
' relation direction is ' .. result_direction .. ' superrelation direction is ' .. super_dir)
189+
result_direction = nil
190+
elseif result_direction == nil then
191+
result_direction = super_dir
192+
end
193+
194+
result['route_direction'] = result_direction
195+
add_extra_data(m)
183196
end
184197

198+
185199
return result
186200
end
187201

0 commit comments

Comments
 (0)