I am trying to work through an Update cursor issue. I have a forest stands shapefile with the following fields: Age, Historical Community (Hist_Comm), Pine Basal Area (PINE_BA), Fire Return Interval (FIRE_FRQ), Time Since Last Fire (LAST_YR), and then a Class (ECC). The goal is to use the AGE, Hist_Comm, FIRE_FRQ, and LAST_YR fields along with several user inputs to assign an ECC value.
This is how it would work:
If the Historical Community field (Hist_Comm) is greater than 3:
and If the Age (Min_Age1) is greater than 80:
and if the Pine Basal Area (Min_PineBA1) is greater than or equal to 40 or Pine Basal Area (Max_PineBA1) is less
than or equal to 60:
and if the Fire Frequency (Max_FI1) is less than 3 and the Time Since Last Fire (Max_FY1) is less than 3:
then ECC = 1
or elif the Fire Frequency (Min_FI1) is greater than or equal to 3 but less than or equal to 6 (Max_FI1) and the Time
Since Last Fire (Max_FY1) is less than or equal to 6:
then ECC = 3
It should search through the attribute table selecting the rows from the fields Hist_Comm, AGE, PINE_BA, FIRE_FRQ, and LAST_YR that fit the above criteria and assign then assign a value to the ECC field.
I think (stress think) I am having an issue with the user inputs working within multiple levels of nested if statements.
The script has been added to a toolbox. Each input variable Data Type is defined as a string. Each input variable will be an integer value.
Here's the code (also attached):
# Import arcpy module
# Set Workspace
arcpy.env.workspace = 'C:\\ECC_Test\\Output'
# Set Input Parameters
Min_Age1 = arcpy.GetParameterAsText(0)
Min_PineBA1 = arcpy.GetParameterAsText(1)
Max_PineBA1 = arcpy.GetParameterAsText(2)
Min_FI1 = arcpy.GetParameterAsText(3)
Max_FI1 = arcpy.GetParameterAsText(4)
Max_FY1 = arcpy.GetParameterAsText(5)
# Define Variables
fc = "C://ECC_Test//Output//Stands_2_t.shp"
with arcpy.da.UpdateCursor(fc, ["Hist_Comm", "FIRE_FRQ", "LAST_YR", "AGE", "PINE_BA", "ECC"]) as cursor:
for row in cursor:
if (row >= 3) and (Min_Age1 >= 80) and (row >= 80):
if (Min_PineBA1 >= 40) and (Max_PineBA1 <= 60) and(row >= 40) and (row <= 60):
if (Max_FI1 < 3) and (row < 3) and (Max_FY1 < 3) and (row < 3):
row = 1
elif (Min_FI1 >= 3) and (row >= 3) and (Max_FI1 <= 6) and (row >= 3) and (Max_FY1 <= 6) and (row <= 6):
row = 3
row = 4
del cursor, row