POST
|
With the String to Long fix, I am only getting the ECC classes of 0 and 4 being assigned. In querying the attribute table I can see that there are data that should be classified as class 3 but are classified as 4. I am sure there is something pretty straight forward I am missing. I am new to using Cursors so bare with me.
... View more
09-07-2016
06:36 AM
|
0
|
1
|
892
|
POST
|
Neil, Your question helped me with one issue and pointed out my boneheaded mistake. They are integers and are now defined as Long not String. Thanks! Krista
... View more
09-07-2016
06:02 AM
|
0
|
0
|
892
|
POST
|
Dan, Thank you for reformatting the code. In my haste i didn't see the Python formatting. I also forgot to include the final "else" in the code. So if the data doesn't meet those criteria it is assigned a zero. #Update Cursor
with arcpy.da.UpdateCursor(fc, ["Hist_Comm", "FIRE_FRQ", "LAST_YR", "AGE", "PINE_BA", "ECC"]) as cursor:
for row in cursor:
if (row[0] >= 3) and (Min_Age1 >= 80) and (row[3] >= 80):
if (Min_PineBA1 >= 40) and (Max_PineBA1 <= 60) and(row[4] >= 40) and (row[4] <= 60):
if (Max_FI1 < 3) and (row[1] < 3) and (Max_FY1 < 3) and (row[2] < 3):
row[5] = 1
elif (Min_FI1 >= 3) and (row[1] >= 3) and (Max_FI1 <= 6) and (row[1] >= 3) and (Max_FY1 <= 6) and (row[2] <= 6):
row[5] = 3
else:
row[5] = 4
cursor.updateRow(row)
else:
row[5] = 0
del cursor, row
... View more
09-07-2016
05:35 AM
|
0
|
1
|
892
|
POST
|
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
import arcpy
# 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"
#Update Cursor
with arcpy.da.UpdateCursor(fc, ["Hist_Comm", "FIRE_FRQ", "LAST_YR", "AGE", "PINE_BA", "ECC"]) as cursor:
for row in cursor:
if (row[0] >= 3) and (Min_Age1 >= 80) and (row[3] >= 80):
if (Min_PineBA1 >= 40) and (Max_PineBA1 <= 60) and(row[4] >= 40) and (row[4] <= 60):
if (Max_FI1 < 3) and (row[1] < 3) and (Max_FY1 < 3) and (row[2] < 3):
row[5] = 1
elif (Min_FI1 >= 3) and (row[1] >= 3) and (Max_FI1 <= 6) and (row[1] >= 3) and (Max_FY1 <= 6) and (row[2] <= 6):
row[5] = 3
else:
row[5] = 4
cursor.updateRow(row)
del cursor, row
... View more
09-06-2016
02:10 PM
|
0
|
8
|
2840
|
Online Status |
Offline
|
Date Last Visited |
05-09-2022
10:13 AM
|