I'm looking for a way in which to generate a set of routes between every point in a layer.

To be clear, if I have four points [A,B,C,D] I want to get routes:

  • A - B
  • A - C
  • A - D
  • B - A
  • B - C
  • ...

... and so on for a total of (4*3=) 12 routes in this example; in fact, I have 35 points in my dataset so it's a bit more than that!

I can't ascertain a way to do this programmatically in QGIS using the Road Graph function or the OSM Route plugin (although it does give good results for a single route), and web searches have turned up nothing (most answers relate to routes that follow a number of points).

Preferably, as this is for cycling purposes, I'd like to use a routing service that would take the method of travel in to account, but not strictly necessary as I'd be happy just to use my line vector layer that I have for the area containing my points.

  • Why can't you generate the route as you need it? Is it imperative to store every possible combination and direction? There was a similar question to this about a week ago... that one received no response. I would suggest to iterate through your points, create a single route, store it (somehow) and then create a new single route if you must have all the routes solved and ready. Do you have any python ability? How are the solved routes to be consumed? May 24, 2016 at 22:11
  • Yes, I do need all pf the routes at once as this forms part of network analysis. I do have python ability, though I've never used it in qgis before. The solved routes are to be consumed within qgis to create a heatmap.
    – jmk
    May 25, 2016 at 7:11

1 Answer 1


You could use pgr_dijkstraCost from PGRouting in many-to-many mode.

Then you could run something like:

SELECT * FROM pgr_dijkstraCost(
    'select id, source, target, cost, reverse_cost from edge_table',

Where the arrays are the ids of you start/finish nodes.

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.