Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to avoid track changes at start of a route? #6

Closed
tomvanenckevort opened this issue Feb 23, 2020 · 7 comments
Closed

How to avoid track changes at start of a route? #6

tomvanenckevort opened this issue Feb 23, 2020 · 7 comments

Comments

@tomvanenckevort
Copy link

I've started playing around with OSRM and your train profile (the basic one) to use for calculating routes and distances between stations. And while that works pretty well, I have got a small issue around stations with many tracks and platforms.

If I'm trying to get a route between stations A & B I want to use the stations' central coordinates as the start and end point of the route.
But currently it seems that it starts from the track nearest to those exact coordinates and then routes it back and forth across the available tracks and points to get it onto the right track that takes it into the direction of station B.

Here is an example of such a route:
image

Is there any way to change the routing or profile parameters to avoid those initial track changes and instead start the route from the most direct track nearest to the station A coordinates?

@tomvanenckevort
Copy link
Author

tomvanenckevort commented Mar 14, 2020

Note from @C4ptainCrunch: This comment was moved to its own issue, #7.

So I have been playing around with this a bit more and decided to have a look at the OSRM tile service to plot the various ways, speeds and angles.

But when I do that all the speeds and angles displayed at turnings seem to be set to zero: image removed

I'm not really sure if that is a problem with the OSM data or the way OSRM has processed the data though?

@C4ptainCrunch
Copy link
Contributor

Hello Tom,

There is no such option in OSRM as stations are points on a map, not a surface. How would OSRM know how much it may move away from your point to find a better path ?

Nevertheless, i have in mind 2 solutions with a bit of code on your side:

A. Sample randomly a few positions in a radius of a few hundreds meters around your station and keep the route that gives you the shortest path. Note: if you are searching the shortest path between a pair of stations, querying for each pair of samples might get a bit big. Is it your usecase ?

B. Use the map-matching API with only 2 points (your arrival and destination) with big enough precision radiuses and let OSRM find the most probable path (Note: use a big enough timestamp difference between the 2 points so that the algorithm does not discard your points)

For the angles and speed of the turns, could you open another issue ?

@tomvanenckevort
Copy link
Author

Hi @C4ptainCrunch,

Thanks for your reply.

Yes, I'm looking for the shortest path between a pair of stations.
I'll try to give your suggestions a go in the next few days and let you know how I get on.

I've also opened a new issue #7 for the angles issue.

@C4ptainCrunch
Copy link
Contributor

Yes, I'm looking for the shortest path between a pair of stations.

Then, you could change the algorithm a bit:
Let's say you have station A and B

  1. Find the path between A and B
  2. Find point the middle of the polyline, call it C
  3. Sample a few A' points in the neighborhood of A, select the one, A" that has the shortest path to C
  4. Sample a few B' points in the neighborhood of B, select the one, B" that has the shortest path to C
    -> Shortest path should be A" to B"

Variation: if you really need to be precise, you could choose multiple values of C, by cutting the polyline not only at 50% but also at 45%, 55% and so on.

I've also opened a new issue #7 for the angles issue.

Thanks !

@C4ptainCrunch
Copy link
Contributor

C4ptainCrunch commented Mar 16, 2020

Side note: Almost all train stations have all their track in parallel, what you could also do to have better/faster results would be to sample all your points on a line (drawn in purple here) perpendicular to the start of your polyline.

image

First, you can take a point (call it A in blue) ~200m (most stations have at least a few hundreds meters of straight track) from the center (call it C, red).

Then draw a line perpendicular to A-C going through C (the purple line, call it L)

Last, you can sample your points at regular interval of a 1.5 m on that line (tracks should be >3m apart so doubling that should be enough)

@tomvanenckevort
Copy link
Author

Those are some excellent suggestions @C4ptainCrunch!
I will let you know how I get on with it. Thanks!

@tomvanenckevort
Copy link
Author

I've just tried your suggestion for using the map-matching API (since that was the easiest to try) and tried it with a few different routes and it seems to work really well actually.
So for now I'm going to stick with that one I think, but I might try your other suggestions as well if I find any more complex locations.

Thank you very much for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants