rst <- raster(system.file("external/test.grd", package="raster"))
# take a small part
rst <- crop(rst, extent(179880, 180800, 329880, 330840) )
# write to an integer binary file
r <- writeRaster(rst, filename="allint.grd", datatype='INT4S', overwrite=TRUE)
# write to a new geotiff file (depends on rgdal)
if (require(rgdal)) {
r <- writeRaster(rst, filename="test.tif", format="GTiff", overwrite=TRUE)
}
# make a brick and save multi-band file
b <- brick(rst, sqrt(rst))
b <- writeRaster(b, filename="mutli.grd", bandorder='BIL', overwrite=TRUE)
# write to netcdf
if (require(ncdf)) {
rnc <- writeRaster(rst, filename='netCDF.nc', format="CDF", overwrite=TRUE)
}
Run the code above in your browser using DataLab