Hello
I´m trying to calclulate Wind Speed from u and v Values which I have in an Attribute Table. Basically the function should calclulate when u and v are simultaneously different from 0
If u and v are simultaneously different from 0 then the function should calculate
Sqr(u**2 + v **2)
In the Code-Block I typed:
Dim z as double
u = [GRID_COD_1]
v = [GRID_CODE]
If (( u = 0) And (v = 0)) Then
z = 0
elseIf (( u <> 0) and (v <> 0)) Then
z= Sqr(( u **2) + (v **2))
EndIf
and after that
z=speed
but it diosnt seem to work. What do I do wrong?
Greets,
Christian
Solved! Go to Solution.
Someone is going to tell me how to comment with proper python syntax, and i forgot how so that comment is welcome.
assuming "z" is your wind speed field.
switch to python .
in the top box
-------------------------------------------
def myupdate(u,v):
if u == 0 and v == 0:
return 0
else:
return math.sqrt(math.pow( u ,2)+ math.pow( v ,2))
----------------------------------------------------
bottom box
---------------------------------------------------
myupdate( !u! , !v! )
-------------------------------------------------------
this should work
Someone is going to tell me how to comment with proper python syntax, and i forgot how so that comment is welcome.
assuming "z" is your wind speed field.
switch to python .
in the top box
-------------------------------------------
def myupdate(u,v):
if u == 0 and v == 0:
return 0
else:
return math.sqrt(math.pow( u ,2)+ math.pow( v ,2))
----------------------------------------------------
bottom box
---------------------------------------------------
myupdate( !u! , !v! )
-------------------------------------------------------
this should work
Great !! It Works.
Thanks,
Christian
btw:
Wind direction would be
(180/3.14)*math.atan2( !u!, !v!)
Any idea why this results in values between -180 and 180 and how to change it to 0 till 360 ?
atan2 is the angle relative to the x-axis in a graph +/-180 is West, +90 is N, 0 is E, -90 is S
there are various expressions on how to adjust it to the range 0,360 with N = 0, pick one you understand since variants are simplifications of the math. There are lots of examples on GeoNet, I won't taint your decision with examples. Azimuth or sometimes Bearing are key words.