Interpolate the sine and cosine of the angle, and then convert back to an angle with the atan function. These functions are available in QGIS' expression engine. There is an atan2(dy,dx)
function like the one in R I use below...
Here's an R function to illustrate. I've used mean
here to give the interpolation:
dinterp = function(d){
r=d*pi/180
(180/pi)*atan2(mean(sin(r)),mean(cos(r)))
}
which gives:
> dinterp(c(10,20))
[1] 15 *as expected*
> dinterp(c(340,20))
[1] 3.384676e-15 *approximately zero*
> dinterp(c(0,180))
[1] 90 *could be +/- 90
> dinterp(c(359,180))
[1] -90.5 *small adjustment makes it go to ~-90
In QGIS, assuming you are creating a raster interpolated from a point data set, your workflow will be as follows:
- Create two new attributes at each point,
sinwind
and coswind
, from your wind direction in degrees. Make sure you convert to radians if necessary.
- Create two interpolated rasters, one from
sinwind
and one from coswind
.
- Use raster calculator to convert back to direction by computing
atan2
of the interpolated sine and cosine rasters.
- Convert to degrees if required.
You could create a processing workflow for this - there may also already be a plugin. Note that although this gives you an interpolation of the wind direction, any assessment of the uncertainty of that interpolation is a bit tricky, and requires some circular statistics methods.