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 am using postgreSQL, postGIS and pgrouting. Now I am really confused on how am I going to find the shortest path between multiple points.

I know how to find it between two points through dijkstra but I am confused how to accomplish the same result with more than two points.

I have done some research and found this:

But still I did not understand if its the right way and how to install it.

share|improve this question
A shortest path is between two points by definition so you might want to route to point a, then point b, then point c. Alternately you could select all possible routes and then filter for those those routes containing points you are seeking. – lewis Feb 6 '13 at 14:07
Travelling Salesman Problem (TSP) - – Mapperz Feb 6 '13 at 14:47
Would be interested in your findings – ca0v Feb 12 '13 at 14:35

The function you referred may deliver a distance matrix between points, but does not find the shortest path to visit all points. That's indeed the NP-hard Travelling Salesman Problem. Selecting all possible routes is a bad strategy as the number of possible routes will grow exponential with the number of points, e.g. for visiting n locations there are n! routes.

You'd better check this page:

share|improve this answer

Your problem is known as the Traveling Salesman problem where you don't return to the initial place. In pgRouting 2, this can done using the pgr_tsp function which is documented here.

share|improve this answer

Your Answer


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

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