Here is a new "report" of my work around PostGIS, OSM, QGis, PgRouting, etc.
When displaying a shortest path, the "end" of the path can be far away from the point we want to reach. So I wondered how to "solve" this.
When you ask for a shortest path, you get a set of geometries. They are almost always in the "wrong" order : we don't care for just displaying the path, but If you want to really work with your paths, you need to fix this. It's easy to do : just use the source and target ids to check if they are in correct order, something like A-B B-C C-D and so on. I do this in the script that talk with PgSQL, in Java, with a few loops and comparisons. Now we can determine the last geometry.
Our geometries are multilines,so we need to find witch segment is the closest to the target point T. It would be either the first or the last one, but another one may be a good choice too; so we'll test all the segments of our last path. I say segments, but actually we have to check distance between each points and our target point and keep the one with the lowest result. In my example, this is the path from A to E.
Now we need to find a point on the segment D-E closer to our target point T than point E. We have two methods we can use:
- The first one is to use interpolation : you can either use ST_Interpolate in PostGis or like me code it by yourself. This is the I cyan point in the picture.
- The second one is to use an orthogonal projection : here again I code it by myself, don't know any PostGis equivalent. This is green H point.
As you can see, even if it's less accurate than orthogonal projection, interpolation can do a good job.