I am trying to find the shortest path between two nodes using pgr_dijkstra, but I am not getting any output. Here's what I've done so far:
I generated a hexagonal grid from a traversable polygon geometry. I converted the hexagons to LineStrings and used these lines as edges for pathfinding with the following query:
CREATE TABLE hex_edges AS WITH mesh_geom AS (...), hex_grid AS ( SELECT i, j, geom FROM ST_HexagonGrid(0.5, (SELECT geom FROM mesh_geom)) AS hex WHERE ST_DWithin(hex.geom, (SELECT geom FROM mesh_geom), 0.1) ), hex_lines AS ( SELECT row_number() OVER () AS id, ST_ExteriorRing(geom) AS lines FROM hex_grid ) SELECT id, (ST_Dump(ST_Segmentize(lines, 999))).geom AS geom FROM hex_lines; I added a cost column with a default value of 1, as all lines should have the same length:
ALTER TABLE hex_edges ADD COLUMN cost FLOAT DEFAULT 1; Then, I added the source and target columns for pathfinding:
ALTER TABLE hex_edges ADD COLUMN source BIGINT; ALTER TABLE hex_edges ADD COLUMN target BIGINT; Topology Creation:
SELECT pgr_createTopology('hex_edges', 0.001, 'geom', 'id'); Attempted to use pgr_dijkstra. The subqueries for finding the source and destination nodes seem to work:
SELECT * FROM pgr_dijkstra( 'SELECT id, source, target, cost FROM hex_edges', (SELECT source FROM hex_edges ORDER BY ST_Distance(geom, ST_SetSRID(ST_MakePoint(x, y), 3857)) LIMIT 1), (SELECT source FROM hex_edges ORDER BY ST_Distance(geom, ST_SetSRID(ST_MakePoint(x, y), 3857)) LIMIT 1) ); The problem is that all rows in the hex_edges table have the same values for id, source, and target. This seems to be the reason for the lack of output, but I'm not sure where the issue lies.
Any ideas on what I´M doing wrong?