I have a layer of points A (around 30), a layer of points B (around 2000), all recorded as in longitude and latitude. Need to calculate the distance between each pair (Ai, Bj) based on the transportation network. (only distance is needed, not direction, when I say distance I meant shortest distance, but we have a high tolerance to the accuracy, imagine as the result popped out from Google map direction)

I have tried everything, the closest thing I find here is the Network Analyst module in ArcGIS, but the result of Closest Facility (How to find network distances between two sets of origins and destinations?) is not what I wanted. I need a full matrix instead of just nearest facility. Also I tried Google Distance Matrix API, that did work for me, but the usage limit is 2500 elements per day.

I meant to write a little python code looping the Routing/Direction function in ArcGIS, but i'm really new to python, if you can give me a brief idea how to implement this, that would be much much helpful.

2 Answers 2


Take a look at OD Cost Matrix within Network Analyst, sounds like it should work for what you describe you need.

  • 1
    The OD Cost Matrix is exactly what I used to match 30,000 well locations to possible 20 testing drop off sites. You can also specify if you want all possible distances or a .shp file of lines for just the shortest distance. I think the auto is all distances, so make sure you look into that as the processing time will be heavy for all lines. Commented Oct 16, 2014 at 19:27
  • Exactly! Actually I just figured out, and I thought I'd better come back to update that solution, and here you are. Thank you though.:) Commented Oct 16, 2014 at 21:09

In QGIS this is possible using "Distance Matrix" from the processing toolbox.

Ensure both layers have unique id's first. enter image description here

You now have distance for all the pairs

enter image description here

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.