How do I create a dictionary that has the linkID of a link as key and linkID of touching links as values?
I have used this code in ArcPy but it takes a very long time.
arcpy.CopyFeatures_management(link,link1)
arcpy.MakeFeatureLayer_management(link,"link")
arcpy.MakeFeatureLayer_management(link,"link1")
fid_fid_dict = {} #the dictionary that has linkID and its connecting linkIDs
with arcpy.da.SearchCursor(link, ["FID"]) as curs:
for row in curs:
arcpy.SelectLayerByAttribute_management("link", "NEW_SELECTION", '"FID" = {}'.format(row[0])) #selects a link
arcpy.SelectLayerByLocation_management('link1', "INTERSECT", "link", "", "NEW_SELECTION") #selects touching links
fid_fid_dict[row[0]] = [_row_[0] for _row_ in arcpy.da.SearchCursor("link1", ['FID'])] #gets the IDs of touching links
The final dictionary should be:
dict = {linkID:[linkID1, linkID2, linkID3, linkID4]}
networkx
would abstract the code away into just a few lines of code.