Skip to content
Prev 22921 / 29559 Next

Problem with raster package and nc4 file

On Sat, 6 Jun 2015 at 08:04 Andrea Timmermann <timmermann at gmx.at> wrote:

            
Do you have grid data in LCC but stored with longitude/latitude
coordinates? This is unfortunate, but you can restore the LCC grid
probably. I would try

r <- raster("tmin_1980.nc4")

and then print it out and tell us the result (or post the errors if it
fails):

r

Do you have the details of the LCC projection? At a bare minimum you need
the centre longitude and centre latitude, and the two standard parallels,
and the datum/ellipsoid.  Can you open the file with ncdf4 and print out
this?

ncic <- nc_open("tmin_1980.nc4")
print(ncic)

 You are not supposed to mix use of the ncdf4 package functions with those
of raster, raster is designed to do all the work - but it does expect
sensibly specified regular grids.  If your data really are regular in LCC I
would recommend sorting that out. Can you share the file, or a link to an
analogous one?

Once you have it sorted out in raster, you can read your shapefile in and
do this

meanpolydata <- extract(r, poly, fun = mean)

Cheers, Mike.

What I would like to do is to get the average temperature for each