khan18

Code snippet in Calculate Value

Discussion created by khan18 on Aug 10, 2011
Hi,

I want to run a set of if statements on raster layers using values but facing a tough time due to weak understanding with python. Following is what i've been using:

Input is from "iterate raster"

Expression: str(%Name%)
Code Block:
nt(1) = 0
nt(2) = 1.8
nb(1) = 1.8
nb(2) = 4.2
t(1) = 0
t(2) = 5
b(1) = 5
b(2) = 10

for l in nt(l):
for k in nb(k):
def str(Name):
if (t(l) <= nt(k)) & (b(l) >= nb(k)):
return:
sum1 = %Name% * (nb(k) - nt(k))
elif: (t(l) <= nt(k)) & (b(l) > nt(k)):
return:
sum1 = sum1 + %Name% * (b(l) - nt(k))
elif: (t(l) > nt(k)) & (b(l) < nb(k)):
return:
sum1 = sum1+ %Name% * (b(l) - t(l))
elif: (t(l) < nb(k)) & (b(l) >= nb(k)):
return:
sum1 = sum1 + %Name% * (nb(k) - t(l))


Any help to make it work would be deeply appreciative. Thanks!

Outcomes