Repository navigation
Description
Probably the simplest measure for road steepness that could be implemented as encoded value is the average slope of an edge, i.e. the elevation difference between the tower nodes divided by the 2D length of the edge. Typically this is scaled by a factor of 100 and given as 'grade' in %:
average_slope = 100 * height_difference / distance_2(!)d
I just did a quick search* for typical values: For example the maximum legal slope for railways at train stations in Germany is 0.25%. The railway slope for Stuttgart 21 will be 1.5%. A 5% ramp is considered accessible for wheelchairs, 10% and above is already a serious/challenging slope for cyclists. 25% is a serious challenge even for elite cyclists and the steepest road in the world is around 35% steep. Hiking paths can be even steeper of course, especially Via Ferrata that include ladders etc. For most routing applications we probably need to distinguish values between -15%..+15% and maybe the maximum value needed is around 30% (just guessing based on my short research).
Note that the average_slope is just a rough approximation for the actual steepness of the single sections of a road a vehicle needs to overcome. In theory, it can even be zero even when the road passes a large mountain between the tower nodes (when it first goes up and then down again by the same margin).
One reason it is easier to implement than other elevation-related encoded values is that the average slope remains the same when the road is split into two virtual edges. For more advanced steepness measures we would need to recalculate the value for virtual edges, see the discussion in #2451.
Still, implementing average_slope already comes with a few challenges:
- the value can be positive or negative
- the value depends on the direction of the edge, but both values are related (the forward value is just the negative of the backward value). we could of course store one value for each direction, but we could also exploit this fact to save half the memory.
- we need to calculate this encoded value per edge, but so far we only calculate encoded values per way
- we probably need to deal with elevation artifacts with unrealistic slopes, especially for short edges. Maybe similar to
Bike2WeightFlagEncoder - since we need to limit the range somehow (say our maximum is 30%) we need to express something like "> 30%" somehow
Note that OSM also has the incline tag, which is similar to average_slope in some ways, but I think we should probably treat this differently.
*) sources:
- https://wiki.openstreetmap.org/wiki/Key:incline
- https://www.un.org/esa/socdev/enable/designm/AD2-01.htm
- https://web.archive.org/web/20160822200115/http://www.boa-bw.de/downloads/frei/ce08e20d-934f-41f9-b25f-68ac963bba8c/0/kopfbahnhof-21.de/fileadmin/downloads/presseberichte/ERI_6_2011_andersen.pdf
- http://theclimbingcyclist.com/gradients-and-cycling-an-introduction/
Activity
easbar commentedon Nov 4, 2021
I would just map all values > 30 to 30 (assuming 30 is the maximum). If we needed to distinguish larger values we could just increase the maximum.
glc-rsarrazin commentedon Apr 2, 2022
Hello, there is some news about this feature (or min/max slope)? :) thanks.
karussell commentedon Jul 18, 2022
Most of the things are now done it seems :)
And additional to the
average_slope(withnegateReverseDirection=true) we could fill a non-direction-dependentmax_slopeEncodedValue. Not sure if these two EVs are better or equivalent to what you proposed in #2451.For average+max_slope I have a draft, but once again the tricky thing is the fluctuation of the raw elevation data. Should we avoid it with a mechanism like the one in
bike2? Or maybe we look elsewhere for other ideas :) ? (although this is a bit an encrypted description atm to me :) )We could use useMaximumAsInfinity=true? (in case of a ladder on a hiking trial this would be even an infinity or near-infinity slope in the real world :) )
Ah, distance_2d is a bit ugly as it is different to the edge_distance we already calculate.
karussell commentedon Jul 27, 2022
Maybe if someone (@ratrun @easbar) has time to play around with this and elevation-aware routing: ramer_smoothing...slope_evs
Details
Works relative good already to avoid hills for
bike(compared it tobike2).And also for (electric) cars or trucks with e.g.:
{ "speed": [ { "if": "average_slope > 5", "multiply_by": "0.3" } ], "priority": [ { "if": "average_slope > 0 && max_slope > 11", "multiply_by": "0.5" } ] }(And also to prefer hills for e.g. mountain bike.)
Then I thought that using the
max_slopedirectly as priority value (on "right hand side") would work even better, but it turns out that something is not yet working properly:{ "priority": [ { "if": "average_slope > 2", "multiply_by": "1-0.03*max_slope" } ] }ratrun commentedon Jul 28, 2022
I believe that the elevation data is just not precise enough such that a computed slope can reasonably influence the weighting and that therefore the results will be rather random. For this reason I would evaluate the incline tag for such a purpose.
Here is a segment which visualizes what I mean: https://www.komoot.de/highlight/219539 . I was there and you won't believe that even a kid could easily and rather safley ride there. It might be interesting what the result of this PR is there. If you have arguments that the result is not random then I might have a look.
easbar commentedon Jul 28, 2022
But the incline tag is not nearly used for all roads.
What do you mean? Is it or is it not possible to ride there for kids? You mean it is not particularly steep? But the elevation data makes it look as if it was steep? And isn't this just a very extreme edge case (a single trail in the middle of a near vertical cliff)? In the vast majority of cases the slope of the roads will be not extreme, but still for cyclists it makes a huge difference whether or not there are elevation changes or not. Don't you think that with the current precision one can at least distinguish flat road sections from those with a clear incline? Maybe it is still hard to detect and correctly classify short steep sections, but for longer road segments with an incline this should be possible?
otbutz commentedon Jul 28, 2022
Would it make sense to combine them? Using the value explicitly tagged via
inclinewhere present and falling back to our elevation data based approach if not.ratrun commentedon Jul 28, 2022
With the extreme example above I wanted to visualise the problem with the approach. I expect there high values for the computed slope values, where nobody would expect that even a kid masters the grade easily.
I like the idea from @otbutz with the combination of both approaches. Do you think that this is possible?
karussell commentedon Jul 28, 2022
@ratrun can you try it out :) ?
But we already do that for bike2 and it works rather well :) (and this approach here is working even better from the current examples I used). And many other routing engines rely on it as well with success.
With the ramer smoothing that I proposed (and this PR is based on), a combination of max_slope and average_slope and some individual tweaks and ideas, I think this is very powerful and helpful. (reducing the elevation fluctuation further will improve the routing of course, but should be another task)
Yes and even if it is mapped it is often just "up" - often completely meaningless. We shall not rely on this, also not in a combination with elevation data.
What problem? The only use case for elevation-aware routing is not about judging whether you can or should ride it, but to slow down speed or decrease or increase priority and improve the overall bike, e-car and energy-efficient truck routing.