2

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?

2
  • 1
    Ok got it now, I can`t use ST_Segmentize as it does not generate individual LineStrings, using ST_DumpSegments works Commented Sep 16, 2024 at 12:30
  • 1
    Put that into an answer to mark this thread as completed. Commented Sep 17, 2024 at 7:04

1 Answer 1

0

Ok got it now, I can`t use ST_Segmentize as it does not generate individual LineStrings, using ST_DumpSegments works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.