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?


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).

| improve this answer | |
  • 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. – If you do not know- just GIS Jun 22 '16 at 16:08
  • @Ifyoudonotknow-justGIS I believe all that information is already in this post. – whuber Jun 22 '16 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. – If you do not know- just GIS Jun 22 '16 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? – carolina passos Dec 10 '19 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 '19 at 23:41

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)))))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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