问题
I have a multilayer RasterBrick representing a topographic map that I want to save to the harddisk as grd or tif format, so that others can work with later.
This is the RasterBrick:
class       : RasterBrick 
dimensions  : 2400, 4200, 10080000, 3  (nrow, ncol, ncell, nlayers)
resolution  : 100, 100  (x, y)
extent      : 480000, 9e+05, 62000, 302000  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       :  layer.1,  layer.2,  layer.3 
min values  :   2.8725,   2.8725,   2.8725 
max values  : 254.5175, 254.5175, 254.5175 
I tried to save it with this command:
outfile <- writeRaster(brick, filename='grid.tif', format="GTiff", overwrite=TRUE)  
and this:
outfile <- writeRaster(m, filename='grid.grd', format="raster", overwrite=TRUE)  
But the tif file is corrupt and the grd object only contains one layer and is not recognized as multi layer RasterBrick when I read it back in using raster().
The aim is to use the topographic map as background for thematic maps.
回答1:
Try this:
outfile <- writeRaster(brick, filename='grid.tif', format="GTiff", overwrite=TRUE,options=c("INTERLEAVE=BAND","COMPRESS=LZW"))
来源:https://stackoverflow.com/questions/36936547/save-multi-layer-rasterbrick-to-harddisk