Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save multi layer RasterBrick to harddisk

Tags:

r

tiff

raster

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 

enter image description here

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.

like image 792
Mario Avatar asked Apr 29 '16 10:04

Mario


1 Answers

Try this:

outfile <- writeRaster(brick, filename='grid.tif', format="GTiff", overwrite=TRUE,options=c("INTERLEAVE=BAND","COMPRESS=LZW"))
like image 186
Geo-sp Avatar answered Nov 11 '22 07:11

Geo-sp