Skip to main content

You can check which ID is assigned to each point. Ideally, you would take a much larger distance, then keep the ID of the nearest neighbor.

That being said, it is likely not the issue here.

Even though you have instructed to use an undirected graph, you must still use set a cost and a reverse_cost (which can be the same).

SELECT gid as id, source, target, 
        length:: double precision AS cost, 
        length:: double precision AS reverse_cost
 FROM bristol_roads

See the examples from the docdoc:

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost, reverse_cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    2 |    1 |        0
   2 |        2 |    3 |   -1 |    0 |        1
(2 rows)

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    4 |    1 |        0
   2 |        2 |    5 |    8 |    1 |        1
   3 |        3 |    6 |    5 |    1 |        2
   4 |        4 |    3 |   -1 |    0 |        3
(4 rows)

You can check which ID is assigned to each point. Ideally, you would take a much larger distance, then keep the ID of the nearest neighbor.

That being said, it is likely not the issue here.

Even though you have instructed to use an undirected graph, you must still use set a cost and a reverse_cost (which can be the same).

SELECT gid as id, source, target, 
        length:: double precision AS cost, 
        length:: double precision AS reverse_cost
 FROM bristol_roads

See the examples from the doc:

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost, reverse_cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    2 |    1 |        0
   2 |        2 |    3 |   -1 |    0 |        1
(2 rows)

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    4 |    1 |        0
   2 |        2 |    5 |    8 |    1 |        1
   3 |        3 |    6 |    5 |    1 |        2
   4 |        4 |    3 |   -1 |    0 |        3
(4 rows)

You can check which ID is assigned to each point. Ideally, you would take a much larger distance, then keep the ID of the nearest neighbor.

That being said, it is likely not the issue here.

Even though you have instructed to use an undirected graph, you must still use set a cost and a reverse_cost (which can be the same).

SELECT gid as id, source, target, 
        length:: double precision AS cost, 
        length:: double precision AS reverse_cost
 FROM bristol_roads

See the examples from the doc:

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost, reverse_cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    2 |    1 |        0
   2 |        2 |    3 |   -1 |    0 |        1
(2 rows)

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    4 |    1 |        0
   2 |        2 |    5 |    8 |    1 |        1
   3 |        3 |    6 |    5 |    1 |        2
   4 |        4 |    3 |   -1 |    0 |        3
(4 rows)
Source Link
JGH
  • 43.1k
  • 3
  • 46
  • 93

You can check which ID is assigned to each point. Ideally, you would take a much larger distance, then keep the ID of the nearest neighbor.

That being said, it is likely not the issue here.

Even though you have instructed to use an undirected graph, you must still use set a cost and a reverse_cost (which can be the same).

SELECT gid as id, source, target, 
        length:: double precision AS cost, 
        length:: double precision AS reverse_cost
 FROM bristol_roads

See the examples from the doc:

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost, reverse_cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    2 |    1 |        0
   2 |        2 |    3 |   -1 |    0 |        1
(2 rows)

SELECT * FROM pgr_dijkstra(
    'SELECT id, source, target, cost FROM edge_table',
    2, 3,
    FALSE
);
 seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
   1 |        1 |    2 |    4 |    1 |        0
   2 |        2 |    5 |    8 |    1 |        1
   3 |        3 |    6 |    5 |    1 |        2
   4 |        4 |    3 |   -1 |    0 |        3
(4 rows)