I am using a road network and the following postgres/postgis operations to perform routing using pg_routing and the pgr_dijkstra method. I am successfully generating routes but they are not the shortest. Here are my methods..
Uploaded road data to postgis.
Added columns source and target.
alter table roads_4326 add column source integer;
alter table roads_4326 add column target integer;
Created topology.
select pgr_createTopology('roads_4326', .0001, 'geom', 'id');
Which successfully produces the '..vertices_pgr' layer.
Then I run the following to route from source id=1 to target id=99.
SELECT seq, edge, geom
FROM pgr_dijkstra(
'SELECT id,
source,
target,
st_length(geom) AS cost
FROM roads_4326',
1, 99,
directed => false
) AS a
JOIN roads_4326 AS b ON (a.edge = b.id) ORDER BY seq;
A route is generated but I am unsure why much shorter routes are not returned. Image 1 is returned.
Why are the much shorter connections in Image 2 ignored?