Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.35k stars 3.36k forks source link

Huge amount of speed limits missing #5194

Closed stavskal closed 2 years ago

stavskal commented 6 years ago

I have a use case where I want to expose the speed limits during query time so I append it to the result's name during build and parse the name when I query my OSRM build.

The problem is that in some countries I see that I have close to 80% nil values. When I check these roads on OpenStreetMaps, they do have a correct speed limit. I've tried getting this value from forward = Handlers.parse_maxspeed(forward,profile) or backward = Handlers.parse_maxspeed(backward,profile) or local ms = way:get_value_by_key("maxspeed")

I still get a lot of missing values. How would I go about exposing the true values of the speed limit?

I'm using OSRM v580

danpat commented 6 years ago

@stavskal Can you point to a particular way in OSM where you think this should be working but it isn't?

stavskal commented 6 years ago

I'll try to pinpoint a few examples. In the meantime, do you know how OSRM maxspeed value relates to OSM? is it a one-to-one matching on the way?

Also, the way I pasted above of getting the maxspeed value in the lua script, is that correct?

danpat commented 6 years ago

@stavskal you're looking roughly at the right spot. However, the forward and reverse variables do get adjusted a bit after we pull them from the maxspeed tag, so if you're appending the forward value to your name, it may not match the tag.

The functions that pull the maxspeed tag in Lua are here:

https://github.com/Project-OSRM/osrm-backend/blob/master/profiles/lib/way_handlers.lua#L433-L471

I would take this bit of code:

https://github.com/Project-OSRM/osrm-backend/blob/master/profiles/lib/way_handlers.lua#L435-L438

and copy/paste it into WayHandlers.name here:

https://github.com/Project-OSRM/osrm-backend/blob/master/profiles/lib/way_handlers.lua#L38

and use the freshly fetched values to set the updated way name.

stavskal commented 6 years ago

Perfect, thanks you very much!

One last question: is it true / false that the 'maxspeed' value for every way starts with the identical value in OSM? (setting aside any modifications done in the lua script)

Should I expect that every maxspeed value in OSRM comes directly from the relevant tag in OSM?

danpat commented 6 years ago

is it true / false that the 'maxspeed' value for every way starts with the identical value in OSM? (setting aside any modifications done in the lua script)

I'm not quite sure what you mean by this. OSRM only looks at the maxspeed:advisory and maxspeed tags on ways (There are quite a few other variants, but we don't use them, see https://wiki.openstreetmap.org/wiki/Key:maxspeed for the list).

One thing I forgot to mention: parse_maxspeed converts whatever value that's in OSM into km/h for internal use - you might want to change that if you're expecting to render the value that's on the road signage. In OSM, maxspeed=25 means "25 km/h", so we have code to handle maxspeed=25 mph and maxspeed=25 mp/h.

Also be aware that there are some non-numeric maxspeed tags in OSM, like maxspeed=FR:urban, so simply looking at the tag data isn't enough to come up with a number you can display on screen, you need a lookup table for these country/class defaults (see the OSM wiki page). OSRM's scripts have a table of values we know about here:

https://github.com/Project-OSRM/osrm-backend/blob/master/profiles/car.lua#L268