2

I've tried Floyd-Warshall algorithm using pgrouting with the following code;

SELECT * FROM pgr_floydwarshall(
'SELECT gid AS id, 
      source, 
      target, 
      meters AS cost
      FROM jalan')

and the result is: result table from pgadmin

The question is How to extract path to new table from the result above if the source node = 9 and target node = 24?

1

First, to filter your result, simply add your required condition to your query. So here, it's your query with the addition WHERE start_vid = 9 AND end_vid = 24.

Here you can find further info on the usage of WHERE clauses.

After that, just insert your result into your desired table as explained in the documentation.

  • I'm able to have a result using where clause as the picture below, tinypic.com/r/2nkuln8/9 the next question is how can i join the result with road table (geom column) so that it can be visualized in a map/join with geom column? – Latief Zainulhayat Jun 29 '16 at 11:23
  • You cannot do that using the FloydWarshall, because it doesn't give you the path itself, but only the cost. See the documentation. docs.pgrouting.org/2.2/en/src/allpairs/doc/… If you need the path, you can use a path finding algorithm like Dijkstra or A-star. – karpfen Jun 29 '16 at 12:10
  • I compare some algorithms for my thesis, including floyd-warshall and dijkstra. Is there a way to get the shortest path from floyd-warshall algorithm using pgrouting? – Latief Zainulhayat Jun 29 '16 at 13:35
  • No there isn't. See the first point of the main characteristics. – karpfen Jun 29 '16 at 13:47
1
SELECT * FROM pgr_floydwarshall(
'SELECT gid AS id, 
  source, 
  target, 
  meters AS cost
  FROM jalan')
  WHERE start_vid = 9 AND end_vid = 24;

You were actually computing the shortest path from/to every node you have which was surely taking too much time, you need to add the where clause to you query so you can specify the origin and destination

  • I'm able to have a result using where clause as the picture below, tinypic.com/r/2nkuln8/9 the next question is how can i join the result with road table (geom column) so that it can be visualized in a map? – Latief Zainulhayat Jun 28 '16 at 17:39
  • you can launch your query from the database manager in qgis this way you import the result directly in the map – Hicham Zouarhi Jun 28 '16 at 17:42
  • I'm sorry I still didn't get it, because the DB manager asked me to define the unique values and geometry column which is not found in the query result (as attached in pic below). How can I handle this? tinypic.com/r/wtiwjm/9 – Latief Zainulhayat Jun 28 '16 at 17:50
  • I assume that you have a table with the geometries, different from the jalan table, right ? if yes can you post a screenshot of select * from yourTable; please – Hicham Zouarhi Jun 28 '16 at 17:57
  • I used "jalan" table as my edge_table, the table has gid, cost and of course it has "geom" column. The issue is when I run the floyd warshall query, the result table did not include "geom" and/or "ID" column. tinypic.com/r/hwamia/9 – Latief Zainulhayat Jun 29 '16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.