I need to calculate in gdal_calc the following python script.
if (A == 0 and B == 0):
wd = 0.0
else:
wd = np.arctan2(A,B)
I have tried
if(A = 0 && B = 0,(0.0), else,(arctan2(A,B)))
But the result isn't correct.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityNupmpy's arctan2
function already returns 0.0
when A==0
and B==0
so you don't need your if/else statement. Additionally, this function takes positional arguments of the form arctan2(y,x)
so be sure to check this aligns with your intended calculation.
Based on your specified parameters, try --calc="arctan2(A,B)"
. If you can update your question with your actual gdal_calc
command it will help with any further troubleshooting.
For more information on syntax see the gdal_calc
documentation and this answer to a similar question.
The correct syntax formula for what I intended to do is:
((degrees (arctan2 (A,B)))+360)*((degrees (arctan2 (A,B)))<0)+(degrees (arctan2 (A,B)))*((degrees (arctan2 (A,B)))>=0)
This formula returns the wind direction in degrees [0, 360[ from U and V wind components.