Implement route relation parse in car.lua
This commit is contained in:
		
							parent
							
								
									1d4c5b2e4d
								
							
						
					
					
						commit
						9a660e3c18
					
				| @ -5,6 +5,7 @@ api_version = 3 | ||||
| Set = require('lib/set') | ||||
| Sequence = require('lib/sequence') | ||||
| Handlers = require("lib/way_handlers") | ||||
| Relations = require("lib/relations") | ||||
| find_access_tag = require("lib/access").find_access_tag | ||||
| limit = require("lib/maxspeed").limit | ||||
| 
 | ||||
| @ -283,7 +284,7 @@ function setup() | ||||
|   } | ||||
| end | ||||
| 
 | ||||
| function process_node(profile, node, result) | ||||
| function process_node(profile, node, result, relations) | ||||
|   -- parse access and barrier tags | ||||
|   local access = find_access_tag(node, profile.access_tags_hierarchy) | ||||
|   if access then | ||||
| @ -395,6 +396,51 @@ function process_way(profile, way, result, relations) | ||||
|   } | ||||
| 
 | ||||
|   WayHandlers.run(profile, way, result, data, handlers, relations) | ||||
| 
 | ||||
|   -- now process relations data | ||||
|   local data = Relations.Merge(relations) | ||||
|   local direction = data["route_direction"] | ||||
|   if direction then | ||||
|     if result.ref then | ||||
|       if result.ref:len() > 0 then | ||||
|         result.ref = result.ref .. ' ' .. direction | ||||
|       else | ||||
|         result.ref = direction | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
| 
 | ||||
| function process_relation(profile, relation, result) | ||||
|   local t = relation:get_value_by_key("type") | ||||
| 
 | ||||
|   if t == "route" then | ||||
|     local route = relation:get_value_by_key("route") | ||||
|     if route == "road" then | ||||
|       for _, m in ipairs(relation:members()) do | ||||
|         -- process case, where directions set as role | ||||
|         local role = string.lower(m:role()) | ||||
|         if role == "north" or role == "south" or role == "west" or role == "east" then | ||||
|           result[m]["route_direction"] = role | ||||
|         end | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|     local direction = relation:get_value_by_key("direction") | ||||
|     if direction then | ||||
|       direction = string.lower(direction) | ||||
|       if direction == "north" or direction == "south" or direction == "west" or direction == "east" then | ||||
|         for _, m in ipairs(relation:members()) do | ||||
|           if m:role() == "forward" then | ||||
|             result[m]["route_direction"] = direction | ||||
|           end | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|    | ||||
| 
 | ||||
| end | ||||
| 
 | ||||
| function process_turn(profile, turn) | ||||
|  | ||||
							
								
								
									
										20
									
								
								profiles/lib/relations.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								profiles/lib/relations.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| -- Profile functions dealing with various aspects of relation parsing | ||||
| -- | ||||
| -- You can run a selection you find useful in your profile, | ||||
| -- or do you own processing if/when required. | ||||
| 
 | ||||
| Relations = {} | ||||
| 
 | ||||
| function Relations.Merge(relations) | ||||
|   local result = {} | ||||
| 
 | ||||
|   for _, r in ipairs(relations) do | ||||
|     for k, v in pairs(r) do | ||||
|       result[k] = v | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   return result | ||||
| end | ||||
| 
 | ||||
| return Relations | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user