@@ -316,6 +316,48 @@ function process_node(profile, node, result, relations)
316316 end
317317end
318318
319+ function parse_relation (relation , obj )
320+ local t = relation :get_value_by_key (" type" )
321+ local role = relation :get_role (obj )
322+ local result = {}
323+
324+ function add_extra_data (m )
325+ local name = relation :get_value_by_key (" name" )
326+ if name then
327+ result [' route_name' ] = name
328+ end
329+
330+ local ref = relation :get_value_by_key (" ref" )
331+ if ref then
332+ result [' route_ref' ] = ref
333+ end
334+ end
335+
336+ if t == ' route' then
337+ local route = relation :get_value_by_key (" route" )
338+ if route == ' road' then
339+ -- process case, where directions set as role
340+ if role == ' north' or role == ' south' or role == ' west' or role == ' east' then
341+ result [' route_direction' ] = role
342+ add_extra_data (m )
343+ end
344+ end
345+
346+ local direction = relation :get_value_by_key (' direction' )
347+ if direction then
348+ direction = string.lower (direction )
349+ if direction == ' north' or direction == ' south' or direction == ' west' or direction == ' east' then
350+ if role == ' forward' then
351+ result [' route_direction' ] = direction
352+ add_extra_data (m )
353+ end
354+ end
355+ end
356+ end
357+
358+ return result
359+ end
360+
319361function process_way (profile , way , result , relations )
320362 -- the intial filtering of ways based on presence of tags
321363 -- affects processing times significantly, because all ways
@@ -402,11 +444,18 @@ function process_way(profile, way, result, relations)
402444
403445 WayHandlers .run (profile , way , result , data , handlers , relations )
404446
447+ local parsed_rel_list = {}
448+ local rel_id_list = relations :get_relations (way )
449+ for i , r in ipairs (rel_id_list ) do
450+ local rel_id = relations :relation (r )
451+ parsed_rel_list [i ] = parse_relation (rel_id , way )
452+ end
453+
405454 -- now process relations data
406455 local matched_refs = nil ;
407456 if result .ref then
408- local match_res = Relations .match_to_ref (relations , result .ref )
409-
457+ local match_res = Relations .match_to_ref (parsed_rel_list , result .ref )
458+
410459 local ref = ' '
411460 for _ , m in pairs (match_res ) do
412461 if ref ~= ' ' then
@@ -422,53 +471,6 @@ function process_way(profile, way, result, relations)
422471
423472 result .ref = ref
424473 end
425-
426- end
427-
428- function process_relation (profile , relation , result )
429- local t = relation :get_value_by_key (" type" )
430-
431- function add_extra_data (m )
432- local name = relation :get_value_by_key (" name" )
433- if name then
434- result [m ][' route_name' ] = name
435- end
436-
437- local ref = relation :get_value_by_key (" ref" )
438- if ref then
439- result [m ][' route_ref' ] = ref
440- end
441- end
442-
443- if t == ' route' then
444- local route = relation :get_value_by_key (" route" )
445- if route == ' road' then
446- for _ , m in ipairs (relation :members ()) do
447- -- process case, where directions set as role
448- local role = string.lower (m :role ())
449- if role == ' north' or role == ' south' or role == ' west' or role == ' east' then
450- result [m ][' route_direction' ] = role
451- add_extra_data (m )
452- end
453- end
454- end
455-
456- local direction = relation :get_value_by_key (' direction' )
457- if direction then
458- direction = string.lower (direction )
459- if direction == ' north' or direction == ' south' or direction == ' west' or direction == ' east' then
460- for _ , m in ipairs (relation :members ()) do
461- if m :role () == ' forward' then
462- result [m ][' route_direction' ] = direction
463- add_extra_data (m )
464- end
465- end
466- end
467- end
468- end
469-
470-
471-
472474end
473475
474476function process_turn (profile , turn )
0 commit comments