6

I have two raster layers representing the U and V components of a vector wind. I could generate the magnitude raster by applying (u*u+v*v) in Map Algebra in ArcGIS.

Now I need to generate the direction raster with the following function:

if(u > 0 && v > 0,( atan(u/v) + 180),if(u < 0 && v < 0,(atan(u/v) + 0),if(u > 0 && v < 0,( atan(u/v) + 360), if(u < 0 && v > 0,( atan(u/v)+270)))))

but I don't know how to apply it in ArcGIS. Any help please?

3 Answers 3

8

Use ATan2, as in

ATan2(-v, -u) * (180 / 3.14159265)

Note that

  1. The wind direction vector is assumed to be (u, v).

  2. Because the construction in the question appears to compute the reverse direction, the direction is reversed by negating both components.

  3. The second component of (-u, -v) is the first argument to ATan2 (the help page does not explain this crucial point).

  4. The result is in radians, which is converted to degrees via the multiplication.


Because this result will lie in the range (-180, 180] and the question appears to want a value in the range [0, 360), a modulus function can be used to change the range. Unfortunately, the Mod function in ArcGIS only works on integers. For full precision we need to implement the modulus ourselves using an alternative such as Int. A streamlined pair of formulas is

x = ATan2(-v, -u) / (2*3.14159265) + 1
(x - Int(x)) * 360

Here, x represents the bearing of (-u,-v) as a fraction of a whole circle. The addition of 1 guarantees the fraction will lie between 1/2 and 3/2. The expression x - Int(x) extracts the fractional part of that number.

For example, with u=-1 and v=1 (a direction pointing towards the northwest) we find that ATan2(-v, -u) = ATan2(-1, 1) = -0.7853982. Dividing by 2*Pi (=2*3.14159265 in single precision) yields -0.125. The addition of 1 increases that to 0.875 (of the way around the circle). The operation of subtracting its integer part leaves it unchanged at 0.875, which in degrees is 0.875 * 360 = 315. That is the direction counterclockwise relative to east. To obtain the bearing clockwise relative to north simply reverse the roles of u and v in the formula.


Because adding or subtracting a half circle to any bearing reverses its direction, an equivalent but more efficient expression to use is

(ATan2(v, u) / (2*3.14159265) + 0.5) * 360

The additive constant 0.5 arises as the difference between 1 and 0.5 (the half circle). When you read this formula, think like this:

ATan2 finds the bearing of (u,v) (via ATan2(v, u)) counterclockwise relative to East. That's converted to a fraction of the whole circle (/ (2*3.14159264)), which is then spun around by a half-circle to reverse it and, incidentally, make the result non-negative (+ 0.5). Finally the whole thing is converted to degrees (* 360).

5
  • Can you add how to do this if you had integers and used the Mod function. So of you rant an INT on the 180 to -180 and used Mod. Jun 22, 2016 at 16:08
  • @Ifyoudonotknow-justGIS I believe all that information is already in this post.
    – whuber
    Jun 22, 2016 at 16:15
  • 1
    a remarkably elegant solution. I did it manually from eol.ucar.edu/content/wind-direction-quick-reference and followed directions above. I can confirm this answer works and is a very elegant approach. Jun 22, 2016 at 18:48
  • I don't know if I understand well which one should I use in the end, so what I need to do is to use this expression: (ATan2(v, u) / (2*3.14159265) + 0.5) * 360 Is that correct? Dec 10, 2019 at 21:49
  • 1
    @carolina Because the expressions I gave are mathematically equivalent, the choice is yours. More efficient is usually better.
    – whuber
    Dec 10, 2019 at 23:41
4

Instead of if(), use Con() (conditional) in Raster Calculator.

The logical if/else structure is essentially the same, but the syntax is different (also, single & to combine conditions):

Con(u > 0 & v > 0, (atan(u/v) + 180), Con(u < 0 & v < 0, (atan(u/v) + 0), Con(u > 0 & v < 0, (atan(u/v) + 360), Con(u < 0 & v > 0, (atan(u/v) + 270)))))
0

In Arcgis, the formula is calculated in a specific and different way than in R, Matlab or Excel...etc.

The exact formula for the wind direction in Arcgis is : ATan2( v , u)* (180 / 3.14159265359)

I do not agree with the other formulas presented, as they give wrong wind directions.

1
  • I am trying the formula you have suggested. So, which orientation do we need to select for plotting the wind direction vectors? Is it arithmetic orientation or geographic orientation in ArcMap? Jul 11, 2023 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.