Changing projection of a netcdf

1.8k views Asked by At

I have netcdf files of daily temperature and precipitation data How is it possible to Change projection of a netcdf?

I have tried to doing this using raster function to read the files and reproject them with projectraster?

Code_used

a <-raster(file.nc)
cr1<-"+proj=longlat +datum=NAD83 +no_defs+ellps=GRS80 +towgs84=0,0,0"
 projectRaster(a, cr1,res =  0.04166667)

ERROR_

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function β€˜res’ for signature β€˜"character"’ In addition: Warning message: In min(dim(to)[1:2]) : no non-missing arguments to min; returning Inf

1

There are 1 answers

2
Spacedman On

The help for projectRaster gives this usage:

Usage:

     projectRaster(from, to, res, crs, method="bilinear", 
                  alignOnly=FALSE, over=FALSE, filename="", ...) 

if you call it with two unnamed arguments, they get matched to from and to, and to is:

  to: Raster* object with the parameters to which 'from' should be
      projected

if instead you name the second argument, this should work:

  a_project = projectRaster(a, crs = cr1, res =  0.04166667)

because now the second argument is matched as the crs argument.

BUT if you just want to transform a gdal-compatible data set then you can use gdaltransform, either from the command line or via the function with the same name from the gdalUtils package.