Else If in Field Calcluator

5426
3
Jump to solution
03-22-2016 06:21 AM
ChristianGeißler
New Contributor

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

0 Kudos
1 Solution

Accepted Solutions
BenjaminMittler
Occasional Contributor III

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

View solution in original post

0 Kudos
3 Replies
BenjaminMittler
Occasional Contributor III

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

0 Kudos
ChristianGeißler
New Contributor

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 ?

0 Kudos
DanPatterson_Retired
MVP Emeritus

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.

0 Kudos