osrm-backend
osrm-backend copied to clipboard
How to add maxspeed value to the nearest service reply?
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?
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]}]}
Nice hack😄
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,
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.