AnsweredAssumed Answered

Create pairs of points

Question asked by forknuts on Jun 3, 2012
Latest reply on Jun 5, 2012 by forknuts
Hi there!

I'm trying to create pairs of point features from a point dataset. I'm not really sure on how to get my for loops working to create only 1 instance of each pair.
For example if I have points A, B, C and D, the final pairs would be AB, AC, AD, BC, BD & CD.

My script in its current state is below - this will print all pairs twice except for those containing the first point in the list, which are only printed once. (I hope that makes sense!)

The ultimate aim is to create a table with XY co-ordinates or geometries of each pair, but at this stage I'm just printing the pairs to screen for checking. I'm a complete python (and programming in general) novice and I'd be really grateful if someone could give me so tips on how to make this happen.

Thanks!
Adam

import arcpy  infc =r"D:\POINTS.shp"  #identify geometry field desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName  #Create primary Search Cursor rows = arcpy.SearchCursor(infc)  pointsList = []   count = 0 #iterator counter for testing  #create a list of the points for row in rows:     feat = row.getValue(shapefieldname)     point = feat.getPart()     pointsList.append(point)  count = 0  for point1 in pointsList:     #print point1.X     for point2 in pointsList[1:]:         if point1 != point2:             print (point1,point2)

Outcomes