Skip to content

Add average_slope encoded value #2456

Closed

Description

@easbar

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:

Activity

  1. easbar commented on Nov 4, 2021

    @easbar
    MemberAuthor

    since we need to limit the range somehow (say our maximum is 30%) we need to express something like "> 30%" somehow

    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.

  2. glc-rsarrazin commented on Apr 2, 2022

    @glc-rsarrazin

    Hello, there is some news about this feature (or min/max slope)? :) thanks.

  3. karussell commented on Jul 18, 2022

    @karussell
    Member

    Still, implementing average_slope already comes with a few challenges:

    Most of the things are now done it seems :)

    And additional to the average_slope (with negateReverseDirection=true) we could fill a non-direction-dependent max_slope EncodedValue. 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 :) )

    since we need to limit the range somehow (say our maximum is 30%) we need to express something like "> 30%" somehow

    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 :) )

    Typically this is scaled by a factor of 100 and given as 'grade' in %:
    average_slope = 100 * height_difference / distance_2(!)d

    Ah, distance_2d is a bit ugly as it is different to the edge_distance we already calculate.

  4. karussell commented on Jul 27, 2022

    @karussell
    Member

    Maybe if someone (@ratrun @easbar) has time to play around with this and elevation-aware routing: ramer_smoothing...slope_evs

    Details
      graph.elevation.provider: cgiar
      graph.elevation.cache_dir: /tmp/cgiar
      graph.elevation.interpolate: bilinear
      graph.elevation.cgiar.clear: false
      graph.elevation.long_edge_sampling_distance: 60
      graph.elevation.way_point_max_distance: 5
      graph.elevation.edge_smoothing: ramer
      graph.elevation.edge_smoothing.ramer.max_elevation: 5
    
      graph.encoded_values: surface,toll,track_type,average_slope,max_slope
    
      profiles:
        - name: car
          vehicle: car
          weighting: custom
          custom_model:
            distance_influence: 1
        - name: foot
          vehicle: foot
          weighting: custom
          custom_model:
            distance_influence: 1
        - name: bike
          vehicle: bike
          weighting: custom
          custom_model:
            distance_influence: 1

    Works relative good already to avoid hills for bike (compared it to bike2).

    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_slope directly 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"
        }
      ]
    }
  5. ratrun commented on Jul 28, 2022

    @ratrun
    Contributor

    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.

  6. easbar commented on Jul 28, 2022

    @easbar
    MemberAuthor

    For this reason I would evaluate the incline tag for such a purpose.

    But the incline tag is not nearly used for all roads.

    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.

    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?

  7. otbutz commented on Jul 28, 2022

    @otbutz
    Contributor

    Would it make sense to combine them? Using the value explicitly tagged via incline where present and falling back to our elevation data based approach if not.

  8. ratrun commented on Jul 28, 2022

    @ratrun
    Contributor

    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?

  9. karussell commented on Jul 28, 2022

    @karussell
    Member

    @ratrun can you try it out :) ?

    I believe that the elevation data is just not precise enough such that a computed slope can reasonably influence the weighting

    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)

    But the incline tag is not nearly used for all roads.

    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.

    With the extreme example above I wanted to visualise the problem with the approach.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions