Nested cursors problem/question

869
10
Jump to solution
02-09-2014 02:49 AM
GrljAles
Occasional Contributor
Hi,

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")
Tags (2)
0 Kudos
10 Replies
RichardFairhurst
MVP Honored Contributor
Please mark the thread as answered on the post that was most helpful in getting to your final solution.  You can also give points to any of my posts that you found particularly helpful.  See this link for more information on marking answers and granting points.  Doing this helps others find the most useful information in a thread when they have similar problems.
0 Kudos