2

Following my Other Question about non-network integrating routing, I have tried the with-points functions using the code proposed in the answer.

The problem is I don't get the shortest path using these functions

For clarification the pink polyline represents the With-points result and the green one represents Dijkstra's result

Edited

The code I used to calculate the with_points route is

SELECT *
FROM   pgr_withPoints(
         'SELECT id, source, target, st_length(the_geom)  as cost FROM vr',
         'SELECT pnt.id AS pid,
                 edg.edge_id,
                 edg.fraction
          FROM   points_table AS pnt
          CROSS JOIN LATERAL (
            SELECT id AS edge_id,
                   ST_LineLocatePoint(the_geom, pnt.geom) AS fraction
            FROM   vr
            ORDER BY
                   the_geom <-> pnt.geom
            LIMIT  1
          ) AS edg',
        -888888, -607,
        details := TRUE
      );

vr is my edge table, -888888 and -607 are start and end point id enter image description here

Ismail
  • 113
  • 7
  • 1
    With just a screenshot it's not possible to guess what could be wrong. Could you also post your queries and even better, could you provide a sample network to reproduce your case? – dkastl Dec 08 '20 at 11:33

1 Answers1

3

You have specified a cost but not a reverse_cost, so the default of -1 is used, meaning the segment is ignored.

You can try with

'SELECT id, source, target, st_length(the_geom) as cost, st_length(the_geom) as reverse_cost FROM vr',

JGH
  • 41,794
  • 3
  • 43
  • 89
  • Thank you so much, it works now, but I need more information about the reverse cost, because as much as I know even if you don't insert the reverse cost in the Dijkstra you get the shortest path, and the with points function is based on dijkstra? am I wrong ? – Ismail Dec 08 '20 at 14:39
  • For both functions, you can use directed=false and then only use the cost – JGH Dec 08 '20 at 14:46