dijkstra (#16) - Problem with route (#212) - Message List

Problem with route

Hi, I was following the tutorial for openlayers and pgrouting and it's showing a route, but is quite wrong... It doesn't start or end in the point I selected in the map.. It always select a near point in the road but is not exact... Any ideas why could this happen?

  • Message #759

    Do you mean the workshop 2007 tutorial?

    Well, a shortest path query always has to start from a node (Dijkstra & A*) or from an edge (Shooting *).
    When you click on the map you usually don't hit exactly, so you need to select one nearby (usually the closest edge). For the tutorial we just take one of the nodes (start- or end node).

    If you want to be more exact, you can test which one is closer, or even better: you split the link and take the substring only. But this is not essential for the usage of the shortest path query itself, so it's not part of the tutorial (just would make it more complicated).

    • Message #760

      Yeah I saw that in the PHP code, I thought that was more accurate :) .. Can you tell me what do you mean with split the link and take the substring only??

      Thanks

      • Message #761

        You can do that with PostGIS functions ST_line_locate_point and ST_line_substring for example.

        I would for example take start- or endpoint first (you can choose as you like), and when you got the shortest path result you need to check if you have to add the substring to the result set or if you need to take it away.

        Shortest path algorithms are not supposed to be the all-in-one functions, but you can use them like any other PostgreSQL function.