AnsweredAssumed Answered

Nested cursors problem/question

Question asked by Alesinar on Feb 9, 2014
Latest reply on Feb 13, 2014 by rfairhur24

I'm trying to write a script, that will select certain polygons according to their position in relation to some other polygons. The idea is to use a cursor in one table to select polygons with aspect ratio equal or more than two. When such polygon is selected an identifier is written to memory and select layer by location tool triggers with this polygon as selection feature. After that another cursor attempts to find which features were selected by polygon above in the select layer by location tool's input feature layer.The purpose of this cursor is that adds a value of 1 and FID of the selecting polygon to the selected polygon's  attribure table.

The script works for 1 values but it only adds one FID (119).

Could some one take a look and tell me what is missing?

depressions = depressionsLocation + "depressions.shp" selectingBuffer = depressionsLocation + "dissolvedBuffers.shp" wasSelectedField = ('SELECTED', 'SELECTOR') isSelectorField = ('ASPECT_R', 'ID')  try:     arcpy.MakeFeatureLayer_management(depressions, "depressionsLayer")       arcpy.MakeFeatureLayer_management(selectingBuffer, "selectingBufferLayer")  except:     print "Could not create feature layers"        try:           with arcpy.da.UpdateCursor("selectingBufferLayer", isSelectorField) as cursor:         for row in cursor:             if (row[0] >= 2):                 oid = row[1]                 arcpy.SelectLayerByLocation_management("depressionsLayer", "INTERSECT", "selectingBufferLayer")                 with arcpy.da.UpdateCursor("depressionsLayer", wasSelectedField) as cursor:                     for row in cursor:                         row[0] = "True"                         row[0] = "1"                         row[1] = oid                         cursor.updateRow(row) finally:      arcpy.Delete_management("selectingBufferLayer")     arcpy.Delete_management("depressionsLayer")