[R-sig-Geo] Problem with raster package and nc4 file
Michael Sumner
mdsumner at gmail.com
Sat Jun 6 00:53:46 CEST 2015
On Sat, 6 Jun 2015 at 08:04 Andrea Timmermann <timmermann at gmx.at> wrote:
> 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).
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
> 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.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list