I've been trying to use the select layer by location tool in a loop to select features that are within a specific distance to one feature class for each feature in a different feature class (each retaining wall has a search distance around it of twice its height). Unfortunately I've realized from Esri Support that it isn't possible to use a FIELD as the argument for the "Search Distance" Parameter.
Is there any other way to do what I'm trying to do here without using the Select Layer by Location tool? I'll post the relevant pieces of my code below.
Retain=arcpy.GetParameterAsText(0) TSafetyRW=arcpy.GetParameterAsText(1) if Retain=="": Retain=dataPath+"/LayerHome.gdb/Retaining_Walls" if TSafetyRW =="": TSafetyRW=dataPath+"/LayerHome.gdb/Transportation_Safety_RW" inRetain=os.path.splitext(os.path.basename(Retain)) inTSafetyRW=os.path.splitext(os.path.basename(TSafetyRW)) TranspoSafetyScore = "Socio_Transpo_Safety" Wall_Height = "RW_Height" Road_to_Wall_Dist = "Distance" Road_Class = "Class_Type" Twice_Height = "Threshold_Distance" ##Adding and assigning a default value to some fields arcpy.AddField_management(inRetain, TranspoSafetyScore, "FLOAT") arcpy.CalculateField_management(inRetain, TranspoSafetyScore, 1) ##Tuples used to assign a Road Class to a Retaining wall Road_to_Wall = [("No Road", 1), ("MUP", 1), ("Sidewalk", 1), ("Collector", 2), ("Major Collector", 2), ("Railway", 3), ("Arterial", 4), ("Transitway", 4), ("City Freeway", 4)] ##Tuple calculation which creats a temporary layer of the TSafetyRW FC for each road class for pairs in Road_to_Wall: (roadclass, score) = pairs arcpy.MakeFeatureLayer_management(TSafetyRW, "justselected", "\""+Road_Class+"\"='"+str(roadclass+"'")) arcpy.SelectLayerByLocation_management(inRetain,"WITHIN_A_DISTANCE","justselected", Twice_Height,"NEW_SELECTION") arcpy.CalculateField_management(inRetain, TranspoSafetyScore, score) arcpy.SelectLayerByAttribute_management(inRetain, "CLEAR_SELECTION") arcpy.Delete_management("justselected")
As I mentioned above, I know that you can't have a field as the search distance parameter for the Select by Location tool so I know that this code won't run properly.
I specified the type of variable that I wanted to use for the search distance parameter in the first paragraph
In other words, I want to use a field from the Target Feature Class as a variable, so it's constantly changing with each retaining wall as the loop is executed. In this case I want to use the Twice_Height variable as the search distance, which is the field "Threshold_Distance" which is a part of the target Feature Class "inRetain".