Skip to content
Prev 22015 / 29559 Next

[EXTERNAL] Re: Maintaining band names in multiband raster objects

Thanks Mike,

As far as I can tell, the time variable is being stripped out also, so it is not available when the netCDF file is exported. For example, this code

clim.brick = brick(?Path to netCDF file?) ## get data
getZ(clim.brick)

yields the appropriate times, But when I export clim.brick using

writeRasterc(clim.brick,?Path to exported file.nc?)

and then attempt to reimport as above, getZ(clim.brick) yields

1,2,3,4 . . . 1104

Obviously the Z values are not being exported with writeRaster.

Wade


From: Michael Sumner [mailto:mdsumner at gmail.com]
Sent: Thursday, November 20, 2014 2:15 PM
To: Wall, Wade A ERDC-RDE-CERL-IL; r-sig-geo at r-project.org
Subject: [EXTERNAL] Re: [R-sig-Geo] Maintaining band names in multiband raster objects

There's just no model for the names in NetCDF, since it *really* stores a 3D array. The analogue in R would be the array's "dimnames", but with NetCDF you'd have to store these names as another variable (sharing the third dimension of your data), and restore them from there.



Do the end user's of the NetCDF really expect these character names, or do they expect a "time" variable on one of the available dimensions? I would just ensure that the "Z dimension" of the object is properly set before writing (see setZ and getZ), and that this round-trips in the expected way. The names can be easily added in R from getZ(x).


Cheers, Mike.
On Fri Nov 21 2014 at 03:34:24 Dutrieux, Loic <loic.dutrieux at wur.nl<mailto:loic.dutrieux at wur.nl>> wrote:
If you create a header for the file, using hrd(), with e.g. format='ENVI', then you should be able to open it in pretty much any GIS software. You have to point to the .gri file.
That will preserve band names for when you re-import in R, and make the file possible to import in ArcGIS. I'm afraid you won't be able to get the band names outside of R though.

Best regards,
Lo?c