[R-sig-Geo] Problem with raster package and nc4 file

Andrea Timmermann timmermann at gmx.at
Sat Jun 6 00:03:39 CEST 2015


Hi, 

I have daymet data in nc4 format and could open it with the ncdf4 package. I also have the coordinates of some polygons representing ecological areas. 
Both, the polygon vertices and the nc4 file have the same projection (LCC) and units (degrees). What I would like to do is to get the average temperature for each ecological area. So I wanted to use the polygons as a mask for the temperature raster and then get the average temperature for each polygon. 

I wanted to create a raster object (using the raster function in the raster package):

ncic <- nc_open("tmin_1980.nc4")
raster(ncic, 'tmin')

But I get this error:
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘raster’ for signature ‘"ncdf4"’

Does anyone know how to fix this? Is there another way to get the data that I need?

I am a bit confused by the fact that the temperature data consists of one matrix with latitude data, one with longitude data and one with the temperature values. And by the fact that the spacing between the latitude and longitude matrices is not uniform. Is the raster package accounting somehow for this? 

Thanks a lot. Andi.



More information about the R-sig-Geo mailing list