Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using pgrouting shortest_path_astar with a complicated cost function. It gives back the edges, vertices and costs. I would like to get the total distance of this shortest path (i.e., the sum of lengths of edges, not the sum of costs of edges).

For now, I use:

SELECT SUM(t2.length) FROM (
    SELECT edge_id FROM shortest_path_astar(..., TRUE, TRUE)
) as t1,
routing.edges as t2 where t1.edge_id = t2.edge_id

Is it the most efficient way to get the distance? I need to run this query many times and I want to be sure to do it in the fastest way.

share|improve this question
You could try if a LEFT JOIN is faster, but I think the PostGIS query analyzer should do a good job and figure it out anyway. – underdark Aug 11 '12 at 9:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.