I'm working on a project to identify points that fall along lengths of road. The roads are stored a single featureclass within a file geodatabase, as are the points. I'm using ArcGIS 10.3.
I'm trying to use an arcpy search cursor, configured with a for statement to iterate through my roads dataset. Within the for loop I'm using the function row.getValue to return a 3 digit short integer stored within a field called 'FacilityID' within the attributes of the roads layer. I wish to then use this value to select the appropriate row within the roads layer. Further down the line I would then use this selected row as the basis of a select by location query. At the moment my code doesn't iterate through selections. I can get it to print all the 3 digit integers within the 'FacilityID' field, but it ceases to work if I use the arcpy.SelectLayerByAttribute_management tool.
As I feel I'm not explaining all of this very well, I will include a cut down version of my code:
import arcpy, os
from arcpy import env
arcpy.env.workspace = "C:\Temp\Test.gdb"
env.overwriteOutput = True
ROADS = "Test_Roads"
FIELD = "FacilityID"
roadcursor = arcpy.SearchCursor(roads_lyr)
for row in roadcursor:
ROADID = (row.getValue(FIELD))
print ROADID, type(ROADID)
expression1 = "\"FacilityID\" = " + str(ROADID)
arcpy.SelectLayerByAttribute_management(roads_lyr, "NEW_SELECTION", expression1)
arcpy.SelectLayerByAttribute_management(roads_lyr, "REMOVE_FROM_SELECTION", expression1)
I've changed the selection type to 'clear selection' in the second, and get the same result.
NEW_SELECTION
with each iteration and omit the next selection where you're callingREMOVE_FROM_SELECTION
.REMOVE_FROM_SELECTION
code would be better replaced by aCLEAR_SELECTION
outside (after) yourfor
loop. Selection won't affect iterating through a cursor. Also, make sure your layer doesn't have a selection applied to it before you create your cursor object.