I've been trying to write an ArcPy script that gets the nearest point to the endpoint of a line feature and puts the value of a certain attribute into a field of the new layer and updates the row. Been trying to figure this out for weeks but nothing is working for me. I can't use Arcade, I've tried doing spatial join and that also didn't work. My path and everything works perfectly and the layer is being created just fine. but the problem is that the rows that I want updated in the new layer are not updating at all. Here is my code but please assume that all parameters and paths pertaining to things like MakeFeature and SelectByLocation are correct, because I believe that they are since the new layer is being created successfully. I believe there is a flaw with my logic for updating the cursor but I'm not sure where.
import arcpy
import numpy as np
arcpy.MakeFeatureLayer_management(parameter_drop, new_layer)
arcpy.SelectLayerByLocation_management(new_layer, "within", parameter_poly)
arcpy.AddMessage("Number of selected features: " + str(arcpy.GetCount_management(new_layer)[0]))
arcpy.CopyFeatures_management(new_layer, parameter_out)
arcpy.SelectLayerByLocation_management(parameter_SA, "WITHIN_A_DISTANCE", new_layer, "50 Feet")
with arcpy.da.UpdateCursor(new_layer, ["SHAPE@", "ADDRESS_TDS_LOCATION_ID"]) as cursor:
#get XY of endpoints on drop layer and loop through
for row in cursor:
#SHAPE@ method
drop = row[0]
end_x = drop.lastPoint.X
end_y = drop.lastPoint.Y
min_distance = float("inf")
#get XY of SA Layer and loop through features in SA layer
with arcpy.da.SearchCursor(parameter_SA, ["SHAPE@XY", "ADDRESS_UUID"]) as SA_cursor:
for SA_row in SA_cursor:
SA_x, SA_y = SA_row[0]
distance = np.sqrt((SA_x - end_x) ** 2 + (SA_y - end_y) ** 2)
if distance < min_distance:
row[1] = SA_row[1]
min_distance = distance
cursor.updateRow(row)