Is there a way in ArcPy to iterate through a dataset and do something with the current feature without having to manually select that feature?
Two examples for clarification:
- export each feature as a seperate shapefile
- using a file containing many buffers and a file containing many points: for each buffer count how many points it contains.
Ideally you would be able to call a method named something like getFeatures(), which is available in QGIS and many webmapping APIs. Then you could, using a loop, for each feature execute some code.
In ArcPy I cannot find such a method, and I feel like it should exist.
Right now I am solving this using a cursor:
- returning the current row's FID
- using that FID to select the feature
- executing the code
bufferCursor = arcpy.da.UpdateCursor(firstBuffer,['FID'])with bufferCursor as cursor: for row in cursor: currentFID = row[0] query = '"FID" = ' + str(currentFID) arcpy.SelectLayerByAttribute_management(bufferFL,'NEW_SELECTION', query) arcpy.SelectLayerByLocation_management(cldcFL,'WITHIN',bufferFL) ...Creating a cursor each time, and selecting the current element seems like overkill, costs time, and is actually very annoying.
What am I missing in the API that would let me skip that step?
أكثر...
Two examples for clarification:
- export each feature as a seperate shapefile
- using a file containing many buffers and a file containing many points: for each buffer count how many points it contains.
Ideally you would be able to call a method named something like getFeatures(), which is available in QGIS and many webmapping APIs. Then you could, using a loop, for each feature execute some code.
In ArcPy I cannot find such a method, and I feel like it should exist.
Right now I am solving this using a cursor:
- returning the current row's FID
- using that FID to select the feature
- executing the code
bufferCursor = arcpy.da.UpdateCursor(firstBuffer,['FID'])with bufferCursor as cursor: for row in cursor: currentFID = row[0] query = '"FID" = ' + str(currentFID) arcpy.SelectLayerByAttribute_management(bufferFL,'NEW_SELECTION', query) arcpy.SelectLayerByLocation_management(cldcFL,'WITHIN',bufferFL) ...Creating a cursor each time, and selecting the current element seems like overkill, costs time, and is actually very annoying.
What am I missing in the API that would let me skip that step?
أكثر...