|
| 1 | +# How to route through pedestrian areas {#pedestrian_areas} |
| 2 | + |
| 3 | +@sa AreaManager |
| 4 | + |
| 5 | +How to route through pedestrian areas, or any other area where you can travel freely in |
| 6 | +all directions. |
| 7 | + |
| 8 | +OSRM routes over the inside of an area by "meshing" it, that is, by adding a virtual way |
| 9 | +between every pair of entry points of the area. These virtual ways always follow lines |
| 10 | +of sight and only use existing nodes. An entry point is where another way connects to |
| 11 | +the area. |
| 12 | + |
| 13 | +## Configuration |
| 14 | + |
| 15 | +This feature is EXPERIMENTAL and you must opt-in to it. To opt-in, you must declare the |
| 16 | +algorithm to be used for area meshing. In your LUA profile properties insert this line: |
| 17 | + |
| 18 | +```lua |
| 19 | +function setup() |
| 20 | + ... |
| 21 | + return { |
| 22 | + properties = { |
| 23 | + ... |
| 24 | + area_meshing_algorithm = 'visgraph+dijkstra', -- << insert this line |
| 25 | + ... |
| 26 | + }, |
| 27 | + } |
| 28 | +end |
| 29 | +``` |
| 30 | + |
| 31 | +Note: Only one algorithm is available currently. |
| 32 | + |
| 33 | +All areas to be meshed must be registered with the @ref AreaManager. Areas are mapped |
| 34 | +either as a closed way or a multipolygon relation. Both types must be configured |
| 35 | +separately. |
| 36 | + |
| 37 | +### process_relation(profile, relation, relations) |
| 38 | + |
| 39 | +To mesh a multipolygon relation you must register it in your @ref process_relation |
| 40 | +function. The process_relation function is called for every relation in the input file. |
| 41 | +You'll have to create the function like this: |
| 42 | + |
| 43 | +```lua |
| 44 | +function process_relation(profile, relation, relations) |
| 45 | + if relation:has_tag('type', 'multipolygon') and relation:has_tag('highway', 'pedestrian') then |
| 46 | + -- register the relation |
| 47 | + area_manager:relation(relation) |
| 48 | + end |
| 49 | +end |
| 50 | + |
| 51 | +-- don't forget to return the process_relation function from the profile |
| 52 | +return { |
| 53 | + setup = setup, |
| 54 | + process_way = process_way, |
| 55 | + process_node = process_node, |
| 56 | + process_relation = process_relation, -- << add this |
| 57 | + ... |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### process_way(profile, way, result, relations) |
| 62 | + |
| 63 | +To mesh a closed way you must register it in your @ref process_way function. The |
| 64 | +process_way function is called for every way in the input file. Insert following lines |
| 65 | +into your process_way function: |
| 66 | + |
| 67 | +```lua |
| 68 | +function process_way(profile, way, result, relations) |
| 69 | + ... |
| 70 | + if way:has_tag('highway', 'pedestrian') and way:has_true_tag('area') then |
| 71 | + -- register the way |
| 72 | + area_manager:way(way) |
| 73 | + end |
| 74 | + ... |
| 75 | +end |
| 76 | +``` |
| 77 | + |
| 78 | +(Note that open ways cannot be meshed and will be ignored.) |
| 79 | + |
| 80 | +Some support for multipolygons is needed in this function too. Since the member ways of |
| 81 | +a multipolygon relation are untagged, and OSRM discards untagged ways, you must copy at |
| 82 | +least the defining tag (and the name, if you want guidance) from the relation to the |
| 83 | +way: |
| 84 | + |
| 85 | +```lua |
| 86 | +function process_way(profile, way, result, relations) |
| 87 | + ... |
| 88 | + for _, rel_id in pairs(area_manager:get_relations(way)) do |
| 89 | + -- if this way is a member of a previously registered relation |
| 90 | + -- we have to set at least one defining tag, else OSRM will discard it |
| 91 | + local rel = relations:relation(rel_id) |
| 92 | + data.highway = rel:get_value_by_key('highway') |
| 93 | + -- also copy the name tag(s) from the relation the to way |
| 94 | + WayHandlers.names(profile, rel, result, data) |
| 95 | + end |
| 96 | + ... |
| 97 | +end |
| 98 | +``` |
| 99 | + |
| 100 | +At this point you have a basic configuration. Refer to @ref AreaManager for further |
| 101 | +details. A complete profile example is found in the file: |
| 102 | +[profiles/foot_area.lua](../profiles/foot_area.lua). |
0 commit comments