Skip to content

Commit 7434f18

Browse files
committed
Add OSM node barrier=height_restrictor handling
1 parent 7d1a12a commit 7434f18

File tree

7 files changed

+64
-32
lines changed

7 files changed

+64
-32
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
- Profile:
88
- FIXED: `highway=service` will now be used for restricted access, `access=private` is still disabled for snapping.
99
- ADDED #4775: Exposes more information to the turn function, now being able to set turn weights with highway and access information of the turn as well as other roads at the intersection [#4775](https://github.com/Project-OSRM/osrm-backend/issues/4775)
10-
- FIXED: #4763: Add support for non-numerical units in car profile for maxheight [#4763](https://github.com/Project-OSRM/osrm-backend/issues/4763)
10+
- FIXED #4763: Add support for non-numerical units in car profile for maxheight [#4763](https://github.com/Project-OSRM/osrm-backend/issues/4763)
11+
- ADDED #4872: Handling of `barrier=height_restrictor` nodes [#4872](https://github.com/Project-OSRM/osrm-backend/pull/4872)
1112

1213
# 5.15.1
1314
- Changes from 5.15.0:

features/car/barrier.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ Feature: Car - Barriers
4545
| bollard | | |
4646
| bollard | rising | x |
4747
| bollard | removable | |
48+
49+
Scenario: Car - Height restrictions
50+
Then routability should be
51+
| node/barrier | node/maxheight | bothw |
52+
| height_restrictor | | x |
53+
| height_restrictor | 1 | |
54+
| height_restrictor | 3 | x |
55+
| height_restrictor | default | x |

features/options/extract/lua.feature

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ Feature: osrm-extract lua ways:get_nodes()
129129
"""
130130
functions = require('testbot')
131131
132+
functions.process_node = function(profile, node, result, relations)
133+
print ('node ' .. tostring(node:get_location_tag('answer')))
134+
end
135+
132136
functions.process_way = function(profile, way, result, relations)
133-
print ('answer ' .. tostring(way:get_location_tag('answer')))
137+
print ('way ' .. tostring(way:get_location_tag('answer')))
134138
result.forward_mode = mode.driving
135139
result.forward_speed = 1
136140
end
@@ -148,4 +152,5 @@ Feature: osrm-extract lua ways:get_nodes()
148152

149153
When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson"
150154
Then it should exit successfully
151-
And stdout should contain "answer 42"
155+
And stdout should contain "node 42"
156+
And stdout should contain "way 42"

profiles/car.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Relations = require("lib/relations")
99
find_access_tag = require("lib/access").find_access_tag
1010
limit = require("lib/maxspeed").limit
1111
Utils = require("lib/utils")
12+
Measure = require("lib/measure")
1213

1314
function setup()
1415
return {
@@ -54,7 +55,8 @@ function setup()
5455
'gate',
5556
'lift_gate',
5657
'no',
57-
'entrance'
58+
'entrance',
59+
'height_restrictor'
5860
},
5961

6062
access_tag_whitelist = Set {
@@ -320,11 +322,18 @@ function process_node(profile, node, result, relations)
320322
else
321323
local barrier = node:get_value_by_key("barrier")
322324
if barrier then
325+
-- check height restriction barriers
326+
local restricted_by_height = false
327+
if barrier == 'height_restrictor' then
328+
local maxheight = Measure.get_max_height(node:get_value_by_key("maxheight"), node)
329+
restricted_by_height = maxheight and maxheight < profile.vehicle_height
330+
end
331+
323332
-- make an exception for rising bollard barriers
324333
local bollard = node:get_value_by_key("bollard")
325334
local rising_bollard = bollard and "rising" == bollard
326335

327-
if not profile.barrier_whitelist[barrier] and not rising_bollard then
336+
if not profile.barrier_whitelist[barrier] and not rising_bollard or restricted_by_height then
328337
result.barrier = true
329338
end
330339
end

profiles/lib/measure.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ local height_non_numerical_values = Set { "default", "none", "no-sign", "unsigne
6262

6363
--- Get maxheight of specified way in meters. If there are no
6464
--- max height, then return nil
65-
function Measure.get_max_height(raw_value,way)
65+
function Measure.get_max_height(raw_value, element)
6666
if raw_value then
6767
if height_non_numerical_values[raw_value] then
68-
if way then
69-
return way:get_location_tag('maxheight') or default_maxheight
68+
if element then
69+
return element:get_location_tag('maxheight') or default_maxheight
7070
else
7171
return default_maxheight
7272
end

src/extractor/scripting_environment_lua.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,22 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
218218
"valid",
219219
&osmium::Location::valid);
220220

221+
auto get_location_tag = [](auto &context, const auto &location, const char *key) {
222+
if (context.location_dependent_data.empty())
223+
return sol::object(sol::nil);
224+
225+
const LocationDependentData::point_t point{location.lon(), location.lat()};
226+
if (!boost::geometry::equals(context.last_location_point, point))
227+
{
228+
context.last_location_point = point;
229+
context.last_location_indexes =
230+
context.location_dependent_data.GetPropertyIndexes(point);
231+
}
232+
233+
auto value = context.location_dependent_data.FindByKey(context.last_location_indexes, key);
234+
return boost::apply_visitor(to_lua_object(context.state), value);
235+
};
236+
221237
context.state.new_usertype<osmium::Way>(
222238
"Way",
223239
"get_value_by_key",
@@ -229,37 +245,29 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
229245
"get_nodes",
230246
[](const osmium::Way &way) { return sol::as_table(way.nodes()); },
231247
"get_location_tag",
232-
[&context](const osmium::Way &way, const char *key) {
233-
if (context.location_dependent_data.empty())
234-
return sol::object(sol::nil);
248+
[&context, &get_location_tag](const osmium::Way &way, const char *key) {
235249
// HEURISTIC: use a single node (last) of the way to localize the way
236250
// For more complicated scenarios a proper merging of multiple tags
237251
// at one or many locations must be provided
238252
const auto &nodes = way.nodes();
239253
const auto &location = nodes.back().location();
240-
const LocationDependentData::point_t point{location.lon(), location.lat()};
241-
242-
if (!boost::geometry::equals(context.last_location_point, point))
243-
{
244-
context.last_location_point = point;
245-
context.last_location_indexes =
246-
context.location_dependent_data.GetPropertyIndexes(point);
247-
}
248-
249-
auto value =
250-
context.location_dependent_data.FindByKey(context.last_location_indexes, key);
251-
return boost::apply_visitor(to_lua_object(context.state), value);
254+
return get_location_tag(context, location, key);
252255
});
253256

254-
context.state.new_usertype<osmium::Node>("Node",
255-
"location",
256-
&osmium::Node::location,
257-
"get_value_by_key",
258-
&get_value_by_key<osmium::Node>,
259-
"id",
260-
&osmium::Node::id,
261-
"version",
262-
&osmium::Node::version);
257+
context.state.new_usertype<osmium::Node>(
258+
"Node",
259+
"location",
260+
&osmium::Node::location,
261+
"get_value_by_key",
262+
&get_value_by_key<osmium::Node>,
263+
"id",
264+
&osmium::Node::id,
265+
"version",
266+
&osmium::Node::version,
267+
"get_location_tag",
268+
[&context, &get_location_tag](const osmium::Node &node, const char *key) {
269+
return get_location_tag(context, node.location(), key);
270+
});
263271

264272
context.state.new_usertype<ExtractionNode>("ResultNode",
265273
"traffic_lights",

taginfo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
{"key": "access", "value": "emergency"},
140140
{"key": "access", "value": "psv"},
141141
{"key": "access", "value": "delivery"},
142+
{"key": "maxheight", "object_types": ["node", "way"]},
142143
{"key": "maxspeed", "value": "none"},
143144
{"key": "maxspeed", "value": "urban"},
144145
{"key": "maxspeed", "value": "rural"},

0 commit comments

Comments
 (0)