osrm-backend icon indicating copy to clipboard operation
osrm-backend copied to clipboard

How to add maxspeed value to the nearest service reply?

Open boooch opened this issue 3 years ago • 3 comments

Hi all! I need to find solution to add maximum allowed speed for the road in nearest service. It can be additional parameter in json or even just concatenated string for the road name. For example: {"code":"Ok","waypoints":[{"nodes":[0,7791036014],"distance":0,"name":"Road Name|60","location":[7.420355,43.726739]}]} I need to place value of maxspeed if this tag exists for the way or calculated maxspeed depending on way type using maxspeed_table_default and maxspeed_table from car.lua Can somebody help with this?

boooch avatar Jul 13 '22 07:07 boooch

Seems that I found solution.

Step1

change in lib/way_handlers.lua

 -- Set the name that will be used for instructions
  if name then
    result.name = name
  end

to

 -- Set the name that will be used for instructions
  if name then
    result.name = name.."|"..(result.forward_speed/profile.speed_reduction)
  else
    result.name = "|"..(result.forward_speed/profile.speed_reduction)
  end

Step 2

in car.lua move WayHandlers.names to place it immediately after WayHandlers.maxspeed:

 -- compute speed taking into account way type, maxspeed tags, etc.
    WayHandlers.speed,
    WayHandlers.maxspeed,
    WayHandlers.names,
    WayHandlers.surface,
    WayHandlers.penalties,

Now you will receive: {"code":"Ok","waypoints":[{"nodes":[1351871310,89108783],"distance":8709.991254,"name":"An der Sandscholle|30","location":[13.113544,52.386378]}]}

boooch avatar Jul 13 '22 09:07 boooch

Nice hack😄

nilsnolde avatar Jul 13 '22 09:07 nilsnolde

One thing you must change also in car.lua file. This speeds is not maximum allowed speeds for this types of the roads, so you must set them to maximum allowed speeds:

 highway = {
        motorway        = 90,
        motorway_link   = 45,
        trunk           = 85,
        trunk_link      = 40,
        primary         = 65,
        primary_link    = 30,
        secondary       = 55,
        secondary_link  = 25,
        tertiary        = 40,
        tertiary_link   = 20,
        unclassified    = 25,
        residential     = 25,
        living_street   = 10,
        service         = 15
      }

And also set speed_reduction = 1,

boooch avatar Jul 19 '22 10:07 boooch

Doing it like this will add a lot of "new name" instructions though, as the name changes for every speed change. @boooch do you still use this solution and how did you overcome the additional "new name" instructions? What i also noticed with this approach is that it can break some instructions, as in some scenarios multiple instructions are collapsed into one which then does not always work anymore, as some scenarios are not recognized anymore.

SamuelBrucksch avatar Mar 11 '23 11:03 SamuelBrucksch