I have an ArcMap document with 100 locations plotted using their latitude and longitude values. I want to show connections between the 100 points in the graph. Essentially 100*100 = 10,000 lines. Is there a way to construct a graph showing these connections using ArcMap?

  • Points To Line will work for display purposes, but it will return one huge polyline unless you have an Advanced license to use Split Line At Vertices to chop it up into 10,000 lines. – John Jul 24 '15 at 19:17

One solution (and a great chance to implement itertools) would be:

import arcpy, os, itertools

infc = r"C:\MyFolder\MyGDB\MyInputFeatureClass" # Replace with the path to your input feature class
outfc = r"C:\MyFolder\MyGDB\MyOutputFeatureClass" # Replace with the path to your output feature class
spatialref = arcpy.Describe(infc).spatialReference

if not arcpy.Exists(outfc):
    arcpy.CreateFeatureclass_management(os.path.dirname(outfc), os.path.basename(outfc), "POLYLINE", "", "", "", spatialref)

points = [arcpy.Point(row[0][0], row[0][1]) for row in arcpy.da.SearchCursor(infc, "SHAPE@XY")]

with arcpy.da.InsertCursor(outfc, "SHAPE@") as cursor:
    for combination in itertools.combinations(points, 2):
        line = arcpy.Polyline(arcpy.Array(combination))

Make sure the path you copy-and-paste from ArcCatalog/Windows explorer is in a raw string r"". And the input has a coordinate system defined, or define one using Define Projection.

  • 1
    Points to Line will not work as I tested it, because that was the first thing that came to my mind as well. It will connect all the points, but it will not connect every point with every other point. Well, actually it was the second thing I thought of, with OD Cost Matrix of Network Analyst being the first, but since there's no network to use... @Ross it may also be worth adding to your question whether straight-line or geodesic lines are desired. – Chris W Jul 25 '15 at 19:34
  • @John I am getting a runtime error on line 5 spatialref = arcpy.Describe(infc).spatialReference . I am not sure why ? – Ross Jul 25 '15 at 21:49
  • 1
    Don't expect 100×100 lines. It's n×(n-1) combinations for n-long set – FelixIP Jul 25 '15 at 23:03
  • Hi Ross, is your infc an existing point feature class with a coordinate system defined? Or is the path correct? You'll need to use a raw string to define the path, such as r"C:\Users\Ross\Desktop\My Docs\Data\SampleGDB.gdb\PointFC". – John Jul 27 '15 at 12:42
  • You're right @ChrisW. I went back and verified and it doesn't create a matrix, just a straight path through each point 1-100. Edited and remove from answer. Thanks for the check. – John Jul 27 '15 at 13:33

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.