Hi,
I'm trying to calculate one field in the attribute table of a feature class based on another field with an if/else clause (please see script).
As a test, I used the values of "10" and "20" as results and it works. Now I need to replace that with two more complex expressions using other fields within the attribute table. That is:
Instead of "10" : 0.0006*B*(Q0.31) *(Area_km20.5) *(Z_MAX/1000)*MAT
and
Instead of "20" : 0.02B(Q)-0.31 *Area_km20.5 *(Z_MAX/1000)
"B"; "Q"; "Area_km2"; "Z_MAX"; "MAT" being those other fields in the attribute table.
I'm not quiet sure how to include those fields as well as the Power function within the codeblock part of the script.
Any help would be greatly appreciate it.
Many thanks
<SPAN class="comment token"># Add "BQART_QS" field to Nodes FC</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>nodes<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BQART_QS"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Double"</SPAN><SPAN class="punctuation token">)</SPAN>
BQART_QS_expression <SPAN class="operator token">=</SPAN> <SPAN class="string token">"calc(!MAT!)"</SPAN>
codeblock <SPAN class="operator token">=</SPAN> <SPAN class="string token">"""def calc(val):
if val >= 2:
return 10
else:
return 20"""</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>nodes<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BQART_QS"</SPAN><SPAN class="punctuation token">,</SPAN> BQART_QS_expression<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PYTHON"</SPAN><SPAN class="punctuation token">,</SPAN>codeblock<SPAN class="punctuation token">)</SPAN>
<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>