in_fc = "C:/Users/Olivia/Desktop/Desktop Developement/Module3_Lab_Data.gdb/Customers"
nearest_dict = dict()
with arcpy.da.SearchCursor(in_fc, ["OID@", "NEAR_FID"]) as rows:
for row in rows:
nearest_id = row[0] #get OID value
input_id = row[1] #get Near_ID value
if input_id in nearest_dict:
#if a dict key already exists, append it
nearest_dict[input_id].append(nearest_id)
else:
#if not, create new list with near_ID and add to dictionary
nearest_dict[input_id]= [nearest_id]
print(nearest_dict)
I have 5 HQ's that need to have customers closest to them assigned to the HQ that is the closest. This prints out a dictionary with all of the OBJECTID's of the points or customers that are closest to each HQ. The key is the HQ number and the values are the customer ID's. How do I populate the field within the customer layer with the sales team that is closest? I have the result of where each point should go but I don't know how to populate the field in the customer layer.
You could create an additional Update cursor to loop through and update the rows based on the items and values in the dictionary.
From the help - Use UpdateCursor to update a field value by evaluating the values of other fields.