Skip to content

Commit

Permalink
let :forward and :backward tags override access for supported mod…
Browse files Browse the repository at this point in the history
…es (valhalla#4204)

* coalesce the various gurka access tests into one

* add failing test

* add handling for :forward tags for all major modes

* lint

* update taginfo

* changelog

* lint

* we can delude ourselves that bikes are vehicles
  • Loading branch information
kevinkreiser authored Jul 23, 2023
1 parent e59975b commit 11feaf0
Show file tree
Hide file tree
Showing 11 changed files with 817 additions and 618 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* ADDED: `source_percent_along` & `target_percent_along` to /trace_attributes JSON response [#4199](https://github.com/valhalla/valhalla/pull/4199)
* ADDED: sqlite database to store landmarks along with interfaces of insert and bounding box queries [#4189](https://github.com/valhalla/valhalla/pull/4189)
* CHANGED: refactor landmark database interface to use a pimpl [#4202](https://github.com/valhalla/valhalla/pull/4202)
* ADDED: support for `:forward` and `:backward` for `motor_vehicle`, `vehicle`, `foot` and `bicycle` tag prefixes [#4204](https://github.com/valhalla/valhalla/pull/4204)

## Release Date: 2023-05-11 Valhalla 3.4.0
* **Removed**
Expand Down
69 changes: 61 additions & 8 deletions lua/graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,11 @@ function filter_tags_generic(kv)
return 1
end

--toss actual areas
if kv["area"] == "yes" then
return 1
end

--figure out what basic type of road it is
local forward = highway[kv["highway"]]
if kv["highway"] == "construction" then
Expand Down Expand Up @@ -991,7 +996,7 @@ function filter_tags_generic(kv)
if kv["motorroad"] == "yes" then
kv["motorroad_tag"] = "true"
end

-- its not a highway type that we know of
else
--if its a ferry and these tags dont show up we want to set them to true
local default_val = tostring(ferry)
Expand Down Expand Up @@ -1256,6 +1261,10 @@ function filter_tags_generic(kv)
else
kv["pedestrian_backward"] = kv["pedestrian_forward"]
end

-- what on earth is going on here? if there is no oneway tagging we say the way is bidirectional despite all the
-- backward/forward crap we did above? this has to be the most common case (no oneway tag) so why on earth does it
-- reset any of the other directional tagging that is parsed above?
elseif oneway_norm == nil or oneway_norm == "false" then
kv["auto_backward"] = kv["auto_forward"]
kv["truck_backward"] = kv["truck_forward"]
Expand Down Expand Up @@ -1305,6 +1314,42 @@ function filter_tags_generic(kv)
kv["bus_backward"] = "true"
end

--let all the :forward overrides through
local mv_forward = kv["motor_vehicle:forward"] or kv["vehicle:forward"]
if mv_forward ~= nil then
kv["auto_forward"] = motor_vehicle[mv_forward]
kv["truck_forward"] = motor_vehicle[mv_forward]
kv["bus_forward"] = motor_vehicle[mv_forward]
kv["taxi_forward"] = motor_vehicle[mv_forward]
kv["moped_forward"] = motor_vehicle[mv_forward]
kv["motorcycle_forward"] = motor_vehicle[mv_forward]
end
if kv["foot:forward"] ~= nil then
kv["pedestrian_forward"] = foot[kv["foot:forward"]]
end
local bk_forward = kv["bicycle:forward"] or kv["vehicle:forward"]
if bk_forward ~= nil then
kv["bike_forward"] = bicycle[bk_forward]
end

--let all the :backward overrides through, some of this is redundant but the code is a mess...
local mv_backward = kv["motor_vehicle:backward"] or kv["vehicle:backward"]
if mv_backward ~= nil then
kv["auto_backward"] = motor_vehicle[mv_backward]
kv["truck_backward"] = motor_vehicle[mv_backward]
kv["bus_backward"] = motor_vehicle[mv_backward]
kv["taxi_backward"] = motor_vehicle[mv_backward]
kv["moped_backward"] = motor_vehicle[mv_backward]
kv["motorcycle_backward"] = motor_vehicle[mv_backward]
end
if kv["foot:backward"] ~= nil then
kv["pedestrian_backward"] = foot[kv["foot:backward"]]
end
local bk_backward = kv["bicycle:backward"] or kv["vehicle:backward"]
if bk_backward ~= nil then
kv["bike_backward"] = bicycle[bk_backward]
end

kv["oneway_reverse"] = "false"

--flip the onewayness
Expand Down Expand Up @@ -1413,13 +1458,7 @@ function filter_tags_generic(kv)
end
end

--toss actual areas
if kv["area"] == "yes" then
return 1
end

delete_tags = { 'FIXME', 'note', 'source' }

for i,k in ipairs(delete_tags) do
kv[k] = nil
end
Expand Down Expand Up @@ -2167,6 +2206,20 @@ function nodes_proc (kv, nokeys)
return 0, kv
end

-- useful for dumping the main kv table to see before and after tag filtering
-- function dump(o)
-- if type(o) == 'table' then
-- local s = '{ '
-- for k,v in pairs(o) do
-- if type(k) ~= 'number' then k = '"'..k..'"' end
-- s = s .. '['..k..'] = ' .. dump(v) .. ','
-- end
-- return s .. '} '
-- else
-- return tostring(o)
-- end
-- end

function ways_proc (kv, nokeys)
--if there were no tags passed in, ie keyvalues is empty
if nokeys == 0 then
Expand All @@ -2176,7 +2229,7 @@ function ways_proc (kv, nokeys)
--does it at least have some interesting tags
filter = filter_tags_generic(kv)

--let the caller know if its a keeper or not and give back the modified tags
--let the caller know if its a keeper or not and give back the modified tags
--also tell it whether or not its a polygon or road
return filter, kv, 0, 0
end
Expand Down
1 change: 0 additions & 1 deletion src/mjolnir/luatagtransform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ Tags LuaTagTransform::Transform(OSMType type, uint64_t osmid, const Tags& maptag
result.clear();
}
} catch (std::exception& e) {
// ..gets sent back to the main thread
LOG_ERROR((boost::format("Exception in Lua function: %1%: %2%") % lua_func % e.what()).str());
} catch (...) {
LOG_ERROR((boost::format("Unknown exception in Lua function: %1%.") % lua_func).str());
Expand Down
128 changes: 128 additions & 0 deletions taginfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -7352,6 +7352,134 @@
"way"
],
"description": "Considers the way lit"
},
{
"key": "motor_vehicle:forward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables motor_vehicle access in the forward direction"
},
{
"key": "motor_vehicle:forward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables motor_vehicle access in the forward direction"
},
{
"key": "motor_vehicle:backward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables motor_vehicle access in the backward direction"
},
{
"key": "motor_vehicle:backward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables motor_vehicle access in the backward direction"
},
{
"key": "vehicle:forward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables vehicle access in the forward direction"
},
{
"key": "vehicle:forward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables vehicle access in the forward direction"
},
{
"key": "vehicle:backward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables vehicle access in the backward direction"
},
{
"key": "vehicle:backward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables vehicle access in the backward direction"
},
{
"key": "foot:forward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables foot access in the forward direction"
},
{
"key": "foot:forward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables foot access in the forward direction"
},
{
"key": "foot:backward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables foot access in the backward direction"
},
{
"key": "foot:backward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables foot access in the backward direction"
},
{
"key": "bicycle:forward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables bicycle access in the forward direction"
},
{
"key": "bicycle:forward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables bicycle access in the forward direction"
},
{
"key": "bicycle:backward",
"value": "yes",
"object_types": [
"way"
],
"description": "Enables bicycle access in the backward direction"
},
{
"key": "bicycle:backward",
"value": "no",
"object_types": [
"way"
],
"description": "Disables bicycle access in the backward direction"
}
]
}
Loading

0 comments on commit 11feaf0

Please sign in to comment.