Description Usage Arguments Value Author(s) Examples
nc2raster
converts a netcdf-file ('.nc'-file) or ncdf4
-object to a Raster* object, setting the time variable as layer name.
1 2 |
nc |
character string indicating the filepath to a netcdf-file ('.nc'-file), or a |
varname |
character string indicating the name of the netcdf-variable to be selected. |
lonname |
character string indicating the name of the longitude-variable of |
latname |
character string indicating the name of the latitude-variable of |
layer, t |
layer/time stemp to select in multi-layer files. |
date |
whether the layer names should be set to the date of the ncdf-file layer (default is |
RasterLayer or RasterStack
Robert K. Bauer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | path <- system.file("test_files", package="oceanmap")
nfiles <- Sys.glob(paste0(path,'/*.nc'))[1] # load sample-'.nc'-files
nc2raster(nfiles[1],"Conc",layer=1) # RasterLayer
nc2raster(nfiles[1],"Conc",layer=1:4) # RasterStack
library('ncdf4')
nc <- nc_open(nfiles[1])
nc2raster(nc,"Conc",layer=1:4) # RasterStack
###### load & plot sample netcdf-file ('.nc'-file)
### option a) load netcdf-file with ncdf4-package and plot it
library('ncdf4')
ncdf <- nc_open(nfiles[1])
print(ncdf)
v(obj = ncdf, cbpos="r")
### option b) load and plot netcdf-file as RasterStack object
nc <- nc2raster(nfiles[1])
v(nc,cbpos="r") # plot RasterStack object
v(nfiles[1], cbpos="r",replace.na=TRUE) # plot directly netcdf-file
### option c) plot netcdf-file directly
v(nfiles[1], cbpos="r") # plot RasterStack object
###### plot multiple layers:
par(mfrow=c(2,2))
v(nfiles[1], t=1:4, cbpos="r", replace.na=TRUE, subplot = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.