Skip to content
Prev 24347 / 29559 Next

Translate a net-cdf file with different years to polygon regions.

On Fri, 29 Apr 2016 at 22:23 Janka VANSCHOENWINKEL <
janka.vanschoenwinkel at uhasselt.be> wrote:

            
Something like this will do it:

library(raster)
require(rgdal)
require(ncdf4)

st <- stack("thencfile.nc")  ## might need varname = "sst" or similar

poly <- shapefile("theshpfile.shp")

extract(st, poly, fun = "mean")  ## and maybe na.rm = TRUE

If you don't want the mean, you can just leave out the fun argument and
you'll get all the pixel values for every time step in a big list, which
may not be obviously helpful but it's all useable with generic R.

I can't quite bring myself to get your files and try it, so please try and
report details.

Cheers, Mike.