In Calculating attribute for network distance between multiple points in ArcGIS Desktop?, an explanation has already been given how to find road distances from a certain point to each point in another feature class. I am now trying to find out how to find such road (not Euclidean) distance between each pair of points in the same (large) feature class. In other words, I am trying to obtain a matrix showing the road distance from each point in a feature class to all others.

What is the easiest way of doing this in ArcGIS?

I presume that this, too, involves Network Analyst, but I could be wrong about this.

  • Did you tried Near Tools or point distance tools in ArcGIS toolbox or not? I think those tools can be helpful.
    – Navid
    Nov 17, 2015 at 8:34

1 Answer 1


If you need to use the road distance as the cost of travel, then you would indeed need to use Network Analyst if you are using ArcGIS and want to take advantage of the restrictions imposed on the roads in the network dataset (one-way, turns, etc.).

The solver you would need for this is OD Cost Matrix. You basically need to generate a matrix where each point is routed to all other points. The OD matrix is usually used for modelling business cases where you have a couple of origins (warehouses) and many consumers (retail network points) and you want to report the travel costs between the origins and the destinations.

In your case, however, because everything is stored in the same feature class, you need to load your feature class points both into origins and destinations (i.e., they will be identical). This is a valid approach, and I am using the OD cost matrix this way quite often myself, too.

The number of lines generated for a feature class with N points will be (N*N) - N. This is because after the solve, you would exclude those pairs where the source and the origin are the same. You can filter them out easily by using the SQL query on the output cost (travel time or distance) field (traveltimefield > 0).

Performance wise, it would be wise to choose None for the Output shape type option. I don't know how many points you have in your feature classes, but ~1500 points both in origins and destinations (resulting in ~2.4 mln lines) never was a problem for me to run in just a couple of minutes (I have a decent laptop with i7 CPU though). If you have more points in your feature class, you can run out of memory in ArcMap (it's a 32bit application that cannot take more than just a couple of GBs of RAM).

If you will hit a RAM limit of ArcMap, you might consider running this solve from Python 64bit process. This is what I usually do when processing large road networks (the RAM consumption for the running Python process was about 12GB at peak, no problem).

There are other options of generating the OD matrix outside of ArcGIS if you are OK with just one-way restrictions and no access to other ArcGIS network dataset based restrictions (vehicle height, turns, etc). networkx - a Python package for working with graphs is something I use often for network analysis, but you would need to program Python then.

  • I tried the OD Cost Matrix tool. Is there any way to format the output such that each origin-destination pair is a row-column pair (or vice versa?)
    – Mhoram
    Nov 19, 2015 at 23:37
  • Also, am I right that each point will be named with the contents of the Name attribute field and, if there is no such field in my attribute table and there are n features, ArcGIS will name them Location 1, Location 2, ... Location n in the output?
    – Mhoram
    Nov 19, 2015 at 23:41
  • Finally, is there any way of having the tool assign a certain (very low) cost to travel from each origin to itself (i.e., WITHIN the location)?
    – Mhoram
    Nov 19, 2015 at 23:45
  • That is too much to comment. Please create individual questions for those. Nov 20, 2015 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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