I want to use pgrouting on a rail network, stored in PostGIS. For each service number I have all the station it stops at. Until now, I set up start and end nodes for the rail edges and created the topology in Postgis.

Unfortunately, the coordinates of the stations don't correspond with the positions of the vertices of the edges, although they overlap with the edges. What should be achieved in the end, is routing along the train lines, e.g.

"show pathway of the line X, which stops at stations [5565,5619,7719]"

Because the underlying data changes more or less often and I need their original IDs, I want to avoid to change it too much by splitting the lines. Is there a way in pgrouting to use multiple interim points for calculating the shortest path?

Example of interim points


1 Answer 1


You can use viaEdges version of TRSP: https://docs.pgrouting.org/latest/en/pgr_trsp.html#support-for-vias

To find fractional positions on edges you can use ST_LineLocatePoint from PostGIS.

  • That worked now, thank you!
    – sequoia
    Commented Oct 10, 2019 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.