|
| 1 | +# Areas |
| 2 | + |
| 3 | +This OSRM feature provides routing through areas. The area type is configurable. |
| 4 | + |
| 5 | +## Routing over pedestrian areas |
| 6 | + |
| 7 | +Pedestrian areas in OSM are either closed ways or multipolygon relations. Currently OSRM |
| 8 | +routes along the perimeter of a closed way area. It does not route over multipolygon |
| 9 | +areas at all. |
| 10 | + |
| 11 | +This feature routes over the inside of the area. It does so by "meshing" the area, ie. |
| 12 | +by creating virtual ways between every two entry points of the area. These new ways |
| 13 | +follow lines of sight, they never go through obstacles in the area. |
| 14 | + |
| 15 | +This feature is opt-in: To enable it you must define a `process_relation` function in |
| 16 | +your profile and return it like this: |
| 17 | + |
| 18 | +```lua |
| 19 | +return { |
| 20 | + setup = setup, |
| 21 | + process_way = process_way, |
| 22 | + process_node = process_node, |
| 23 | + process_turn = process_turn, |
| 24 | + process_relation = process_relation |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +You must also keep multipolygon relations, so that you can use the name on the relation |
| 29 | +for turn directions. (Remember that the ways in the relation are untagged.) In your |
| 30 | +profile's setup function add or edit the `relation_types` sequence to include the type |
| 31 | +"multipolygon": |
| 32 | + |
| 33 | +```lua |
| 34 | +function setup() |
| 35 | + ... |
| 36 | + return { |
| 37 | + ... |
| 38 | + relation_types = Sequence { |
| 39 | + "multipolygon" |
| 40 | + } |
| 41 | + ... |
| 42 | + } |
| 43 | +end |
| 44 | +``` |
| 45 | + |
| 46 | +### process_relation(profile, relation, relations) |
| 47 | + |
| 48 | +The `process_relation` function is called for every relation in the input file. If you |
| 49 | +want a relation to be meshed, call `area_manager:relation(relation)`. |
| 50 | + |
| 51 | +Example of a process_relation function: |
| 52 | + |
| 53 | +```lua |
| 54 | +function process_relation(profile, relation, relations) |
| 55 | + type = relation:get_value_by_key('type') |
| 56 | + highway = relation:get_value_by_key('highway') |
| 57 | + if type == 'multipolygon' and highway == 'pedestrian' then |
| 58 | + -- register the relation |
| 59 | + area_manager:relation(relation) |
| 60 | + end |
| 61 | +end |
| 62 | +``` |
| 63 | + |
| 64 | +### process_way(profile, way, result, relations) |
| 65 | + |
| 66 | +The `process_way` function is called for every way in the input file. If you want a |
| 67 | +closed way to be meshed, call `area_manager:way(way)`. (Note that open ways cannot be |
| 68 | +meshed and will be ignored.) |
| 69 | + |
| 70 | +Multipolygons need some support too. Since the member ways of a multipolygon relation |
| 71 | +are as a rule untagged, you have to copy at least the defining tag (and maybe the name) |
| 72 | +from the relation to the way. OSRM discards untagged ways. |
| 73 | + |
| 74 | +Example of a process_way function: |
| 75 | + |
| 76 | +```lua |
| 77 | +function process_way(profile, way, result, relations) |
| 78 | + ... |
| 79 | + if way:get_value_by_key('highway') == 'pedestrian' then |
| 80 | + -- register the way |
| 81 | + area_manager:way(way) |
| 82 | + end |
| 83 | + |
| 84 | + for _, rel_id in pairs(area_manager:get_relations(way)) do |
| 85 | + -- if this way is a member of a registered relation |
| 86 | + -- we have to set at least one defining tag |
| 87 | + local rel = relations:relation(rel_id) |
| 88 | + data.highway = rel:get_value_by_key('highway') |
| 89 | + end |
| 90 | + ... |
| 91 | +end |
| 92 | +``` |
| 93 | + |
| 94 | +### area_manager |
| 95 | + |
| 96 | +A global user type. |
| 97 | + |
| 98 | +#### area_manager:relation(relation) |
| 99 | +Call this function inside `process_relation()` to register a relation for meshing. The |
| 100 | +relation must be a multipolygon relation. |
| 101 | + |
| 102 | +Argument | Type | Notes |
| 103 | +---------|-------------|----------------------------------------------------- |
| 104 | +relation | OSMRelation | The same relation as passed into `process_relation`. |
| 105 | + |
| 106 | +#### area_manager:way(way) |
| 107 | +Call this function inside `process_way()` to register a way for meshing. The way must be |
| 108 | +closed. |
| 109 | + |
| 110 | +Argument | Type | Notes |
| 111 | +---------|----------|------------------------------------------- |
| 112 | +way | OSMWay | The same way as passed into `process_way`. |
| 113 | + |
| 114 | +#### area_manager:get_relations(way) |
| 115 | +Call this function inside `process_way()`. If this way is a member of a relation that |
| 116 | +was registered for meshing, that relation will be returned. Since the member ways of a |
| 117 | +multipolygon relation are as a rule untagged, you have to copy at least the defining tag |
| 118 | +(and maybe the name) from the relation to the way. OSRM discards untagged ways. |
| 119 | + |
| 120 | +Argument | Type | Notes |
| 121 | +---------|----------|------------------------------------------- |
| 122 | +way | OSMWay | The same way as passed into `process_way`. |
| 123 | + |
| 124 | +Usage example: |
| 125 | + |
| 126 | +```lua |
| 127 | +for _, rel_id in pairs(area_manager:get_relations(way)) do |
| 128 | + local rel = relations:relation(rel_id) |
| 129 | + data.highway = rel:get_value_by_key('highway') |
| 130 | + WayHandlers.names(profile, rel, result, data) |
| 131 | +end |
| 132 | +``` |
0 commit comments