Some success. I am now iterating through rows of a layer with a selection in the correct descending Rank and my other layer selection is correctly nested meaning a refresh of the select by attribute of that layer prior to the SelectLayerByLocation:
print ('Creating Confirmed and Pending subsets...')
arcpy.MakeFeatureLayer_management (ScotWind_Applications_Scoring, "ScotWind_Applications_Pending")
arcpy.management.SelectLayerByAttribute ("ScotWind_Applications_Pending", "NEW_SELECTION", "Status = 'Pending'", None)
print ('Comparing Pending against Confirmed...')
with arcpy.da.SearchCursor("ScotWind_Applications_Pending", ["OBJECTID", "ScotWind_Applications_SMPJoin_AppID", "Rank", "SHAPE@AREA"], sql_clause=(None, "ORDER BY Rank DESC")) as cursor:
for row in cursor:
arcpy.SelectLayerByAttribute_management ("ScotWind_Applications_Pending","NEW_SELECTION", "OBJECTID = {}".format(row[0]))
arcpy.MakeFeatureLayer_management (ScotWind_Applications_Scoring, "ScotWind_Applications_Confirmed")
arcpy.management.SelectLayerByAttribute ("ScotWind_Applications_Confirmed", "NEW_SELECTION", "Status = 'Confirmed'", None)
arcpy.management.SelectLayerByLocation("ScotWind_Applications_Confirmed", "INTERSECT", "ScotWind_Applications_Pending", "5 Kilometers", "SUBSET_SELECTION", "NOT_INVERT")
featurecount = int(arcpy.GetCount_management("ScotWind_Applications_Confirmed").getOutput(0))
print (u'{0}, {1}, {2}, {3}'.format(row[0], row[1], row[2], row[3]))
print (featurecount)
codeblock5 = """def Reclass(Status):
if featurecount == 0:
return 'Confirmed'
else:
return 'Defeated'"""
arcpy.management.CalculateField("ScotWind_Applications_Pending", "Status", "Reclass(!Status!)", "PYTHON3", codeblock5)
arcpy.Delete_management("ScotWind_Applications_Confirmed")
I would now like to get the sum of the SHAPE@AREA of ScotWind_Applications_Confirmed and the current SHAPE@AREA of the current row of ScotWind_Applications_Pending in each pass of searchcursor in order to write a pre-condition. If the sum of both is > a numerical maximum, say 8,900, update Status to "Capped Out" else carry out the codeblock 5 and it's calculatefield.