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):
<SPAN class="comment token"># Import arcpy module</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># Set Workspace</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">'C:\\ECC_Test\\Output'</SPAN>
<SPAN class="comment token"># Set Input Parameters</SPAN>
Min_Age1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
Min_PineBA1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
Max_PineBA1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
Min_FI1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN>
Max_FI1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">)</SPAN>
Max_FY1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Define Variables</SPAN>
fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C://ECC_Test//Output//Stands_2_t.shp"</SPAN>
<SPAN class="comment token">#Update Cursor</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Hist_Comm"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FIRE_FRQ"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LAST_YR"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"AGE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PINE_BA"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ECC"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>Min_Age1 <SPAN class="operator token">>=</SPAN> <SPAN class="number token">80</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">80</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>Min_PineBA1 <SPAN class="operator token">>=</SPAN> <SPAN class="number token">40</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>Max_PineBA1 <SPAN class="operator token"><=</SPAN> <SPAN class="number token">60</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN><SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">40</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token"><=</SPAN> <SPAN class="number token">60</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>Max_FI1 <SPAN class="operator token"><</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token"><</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>Max_FY1 <SPAN class="operator token"><</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token"><</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">elif</SPAN> <SPAN class="punctuation token">(</SPAN>Min_FI1 <SPAN class="operator token">>=</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>Max_FI1 <SPAN class="operator token"><=</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>Max_FY1 <SPAN class="operator token"><=</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token"><=</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="number token">3</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="number token">4</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> cursor<SPAN class="punctuation token">,</SPAN> row<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>