Project-OSRM / osrm-backend

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

Support for road id #1605

Closed leandropls closed 9 years ago

leandropls commented 9 years ago

When querying for a route, sometimes the origin or destination is in a location that has multiple streets running above each other going to different places. If known, It would be very useful to be able to inform OSRM which one the vehicle is in.

Maybe we could inform osm_ids to complement the coordinates?

danpat commented 9 years ago

The typical way to do this is to encode the ID in the "name" value here:

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

and then parse the ID out of the name field when you display the data for the user. The problem with explicitly adding an ID to the internal data structure is that it will increase memory usage quite a lot.

leandropls commented 9 years ago

That sure does help when parsing the output of OSRM, your tip will indeed help me. Thanks!

But how do you differentiate overlapping streets on an input?

danpat commented 9 years ago

What do you mean by that? Can you point to an example in OSM?

leandropls commented 9 years ago

Here it is: http://www.openstreetmap.org/#map=16/-22.9207/-43.2111

Via Elevada Engenheiro Freyssinet (Elevated Way Engineer Freyssinnet) runs above Avenida Paulo de Frontin (Paulo de Frontin Avenue). The difference in their position isn't expressed in terms of lng, lat, but height.

Here is a view of it on Google Street View: https://www.google.com.br/maps/@-22.918975,-43.2101666,3a,90y,75.17h,81.37t/data=!3m6!1e1!3m4!1sy78CWIiN3DTIj-4gRl_V6Q!2e0!7i13312!8i6656

danpat commented 9 years ago

Visually those roads may overlap, but in OSM, they're modeled as separate ways, so there will be no problem routing on them or getting them confused.

leandropls commented 9 years ago

I understand that there is no problem in routing through them. My point is than given a (lng, lat) of them as origin/destination, OSRM might choose to select any of the two roads to use as origin/destination, since the (lng, lat) pair isn't enough to tell them apart. Does that make sense?

danpat commented 9 years ago

OSRM uses a "nearest neighbor" method to find the closest spot to the requested routing point.

There is no good linear referencing method for OSM right now, and even if there was one, it would be difficult for the user to enter the data properly when compared to dropping a location marker.

Practically, it's not easy to draw ways directly one on top of the other, so you'll probably find that you will be able to get the pin on the correct road with a little bit of adjusting.

OSRM also has a "map-matching" plug in which uses a Hidden-Markov model to match a GPS trace to the most likely route. If you're trying to snap location coordinates to the correct road, you should use the map-matching plugin, it does a pretty good job of selecting the real route if you give it enough points to work with.

leandropls commented 9 years ago

Alright, thanks.