arcpy.GenerateNearTable_analysis(featureClass, featureClass, pairsTable)
This results in two rows for each pair, when feature A is nearest feature B and when feature B is nearest feature A. Feature C may also be nearest feature B. I'm trying to come up with a table of unique pairs using arcpy (e.g. keep A-B, C-B, but remove B-A).
I started out doing this using a selection based on a cursor, and it seems to work but it is extremely slow (~20min for 1300 points), there must be a simpler way.
arcpy.MakeFeatureLayer_management(pairsTable, "lyr") pairs_lst= with arcpy.da.SearchCursor(pairsTable, ["IN_FID", "NEAR_FID"]) as cursor: for row in cursor: pairs_lst.append([row,row]) if [row, row not in pairs_lst: exp = '"IN_FID" = ' + str(row) arcpy.SelectLayerByAttribute_management("lyr", "ADD_TO_SELECTION", exp) arcpy.CopyFeatures("lyr", pairsTable2)