1

I use a river network on which has a lot of nodes to test pgRouting,

enter image description here

and I run the SQL, searching for the shortest path between nodes.

SELECT * FROM shortest_path('
            SELECT gid as id,
                     start_id::int4 AS source, 
                     end_id::int4 AS target,
                     shape_leng::double precision as cost
                    FROM network',
            10, 20, false, false)

enter image description here

But if I want to search for the distance between node#10 and node#21, I need to type the code again and run the SQL.

The result below is parts of distance from node#10 to node#20, but I want is the total distance from starting node to ending node.

In my case, I have 159 nodes and I want to know if there are more efficient way using pgRouting?(like type the SQL code once and I can get all total distance between all nodes)

1 Answer 1

2

With the "Driving Distance" function (the one that returns the "raw" list of points and not the polygon), you can query the cost from a start node to all nodes within a maximum cost.

So if you define your cost as distance and set the limit high enough to reach all nodes in your river network, then it will return the distance from your start node to all other nodes. So you get a 1:n distance matrix, which should be already better, right?

6
  • Thank you very much, it does work, but as I use this function, I can get many rows of distance but not all(I set the tolerance to 10000000000000000). In my case, I got total 159 points, but I got only 50 rows using Driving Distance. How to solve this problem?
    – Heinz
    Commented Apr 18, 2013 at 3:57
  • @dkasl the link you gave me was broken, and now I can't find the 2 sql of driving_distance that I could use to get the distance, could you give me the sql or some other advice? Thank you!
    – Heinz
    Commented Nov 26, 2013 at 17:20
  • There was a new pgRouting release in the meanwhile, which makes this wrapper function obsolete. Take a look at the new pgRouting docs (docs.pgrouting.org), if you're planning to use the new release. Otherwise you find the old source in this Github branch: github.com/pgrouting/pgrouting/tree/pgr-1.x
    – dkastl
    Commented Nov 28, 2013 at 2:03
  • @dkasl Thank you for the comment above. I have seen the new pgRouting docs and I thought the "pgr_apspWarshall" function can do the same thing that "driving_distance" can in version 1.x. So I will try the new version of pgRouting!
    – Heinz
    Commented Dec 1, 2013 at 15:07
  • @dkasl Sorry for bothering you that I have another question of pgRouting 1.x in this post:gis.stackexchange.com/questions/59289/…. If you got time, I really want to discuss this strange problem with you.
    – Heinz
    Commented Dec 1, 2013 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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