@@ -7,6 +7,10 @@ Utils = require('lib/utils')
77
88Relations = {}
99
10+ function is_direction (role )
11+ return (role == ' north' or role == ' south' or role == ' west' or role == ' east' )
12+ end
13+
1014-- match ref values to relations data
1115function Relations .match_to_ref (relations , ref )
1216
@@ -91,37 +95,71 @@ function Relations.match_to_ref(relations, ref)
9195 return result
9296end
9397
94- function Relations .parse_route_relation (relation , obj )
95- local t = relation :get_value_by_key (" type" )
96- local role = relation :get_role (obj )
98+ function get_direction_from_superrel (rel , relations )
99+ local result = nil
100+ local result_id = nil
101+ local rel_id_list = relations :get_relations (rel )
102+
103+ function set_result (direction , current_rel )
104+ if (result ~= nil ) and (direction ~= nil ) then
105+ print (' WARNING: relation ' .. rel :id () .. ' is a part of more then one supperrelations ' .. result_id .. ' and ' .. current_rel :id ())
106+ else
107+ result = direction
108+ result_id = current_rel :id ()
109+ end
110+ end
111+
112+ for i , rel_id in ipairs (rel_id_list ) do
113+ local parent_rel = relations :relation (rel_id )
114+ if parent_rel :get_value_by_key (' type' ) == ' route' then
115+ local role = parent_rel :get_role (rel )
116+
117+ if is_direction (role ) then
118+ set_result (role , parent_rel )
119+ else
120+ local dir = parent_rel :get_value_by_key (' direction' )
121+ if is_direction (dir ) then
122+ set_result (dir , parent_rel )
123+ end
124+ end
125+ end
126+ -- TODO: support forward/backward
127+ end
128+
129+ return result
130+ end
131+
132+ function Relations .parse_route_relation (rel , way , relations )
133+ local t = rel :get_value_by_key (" type" )
134+ local role = rel :get_role (way )
97135 local result = {}
98136
99137 function add_extra_data (m )
100- local name = relation :get_value_by_key (" name" )
138+ local name = rel :get_value_by_key (" name" )
101139 if name then
102140 result [' route_name' ] = name
103141 end
104142
105- local ref = relation :get_value_by_key (" ref" )
143+ local ref = rel :get_value_by_key (" ref" )
106144 if ref then
107145 result [' route_ref' ] = ref
108146 end
109147 end
110148
111149 if t == ' route' then
112- local route = relation :get_value_by_key (" route" )
150+ local route = rel :get_value_by_key (" route" )
113151 if route == ' road' then
114152 -- process case, where directions set as role
115- if role == ' north ' or role == ' south ' or role == ' west ' or role == ' east ' then
153+ if is_direction ( role ) then
116154 result [' route_direction' ] = role
117155 add_extra_data (m )
118156 end
119157 end
120158
121- local direction = relation :get_value_by_key (' direction' )
159+ local direction = rel :get_value_by_key (' direction' )
122160 if direction then
123161 direction = string.lower (direction )
124- if direction == ' north ' or direction == ' south ' or direction == ' west ' or direction == ' east ' then
162+ if is_direction ( direction ) then
125163 if role == ' forward' then
126164 result [' route_direction' ] = direction
127165 add_extra_data (m )
@@ -130,6 +168,20 @@ function Relations.parse_route_relation(relation, obj)
130168 end
131169 end
132170
171+ -- process superrelations
172+ local super_dir = get_direction_from_superrel (rel , relations )
173+
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
180+
181+ if (dir == nil ) and (super_dir ~= nil ) then
182+ result [' route_direction' ] = super_dir
183+ end
184+
133185 return result
134186end
135187
0 commit comments