2

I currently use the pgr_kdijkstraCost() function to calculate the travel times of a few origins and destinations. But I would also like to return the distance length of these trips. Is this possible? If so, how would you go about it?

If it is not possible for a k matrix, is it possible for a single origin and destination?

  • 2
    I think you should put your second question in a new question by itself, as it has nothing to do with the title of this question. – Richard Law Oct 2 '15 at 19:42
  • Welcome to GIS SE! As a new user be sure to take the Tour where you will see that @alpha-beta-soup is right about the desirability of one question per question. – PolyGeo Oct 3 '15 at 7:19
3

Just addressing the length question here. The pgRouting docs give an example of pgr_kdijkstraPath where the result includes the path geometry. Then you just need to use ST_Length on the output geometry.

Example from the docs to get the geometry:

SELECT id1 as path, st_astext(st_linemerge(st_union(b.the_geom))) as the_geom
  FROM pgr_kdijkstraPath(
                  'SELECT id, source, target, cost FROM edge_table',
                  10, array[4,12], false, false
            ) a,
            edge_table b
WHERE a.id3=b.id
GROUP by id1
ORDER by id1;

path |            the_geom
------+---------------------------------
    4 | LINESTRING(2 3,3 3,4 3,4 2,4 1)
   12 | LINESTRING(2 3,3 3,4 3)
(2 rows)

Therefore if you want length, just use st_length(st_linemerge(st_union(b.the_geom)))

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.