Hi,

I have a problem with writeRaster when writing a brick to NetCDF - the
names of the layers are not preserved. Here is a minimum example to
demonstrate the point:

#Create an arbitrary brick and write it out
b <- brick(system.file("external/rlogo.grd", package="raster"))
fname <- file.path( tempdir(),"test.nc")
dmp <- writeRaster(b,file=fname)

#Now read it back in
a <- brick(fname)

#However, names are not preserved
> names(b)
[1] "red"   "green" "blue"
> names(a)
[1] "X1" "X2" "X3"
>

I realise this is a touch tricky, as NetCDF isn't exactly made for storing
character strings, which is how raster stores the layer names. However,
there are many cases where the string is just a representation of a number
anyway.... e.g. when working with time or depth levels as the layers in the
brick. One solution could therefore be to allow the writeRaster function to
take an argument "zvals", in the same way that it takes "zname" and "zunit"
when working with netcdf files - this argument would let you specify the
numeric values of the z-axis. Everything else would then work ok I think,
as brick() picks up the values of the z-axis, converts them to strings and
assigns them to layer names.

Cheers,

Mark

raster version: 2.2-31
R version 3.0.3
ncdf4 version: 1.10
Platform: Linux Mint 16, 64 bit

	[[alternative HTML version deleted]]

