raster (version 1.1.7)

writeRaster: Write raster data to a file

Description

Write an entire Raster* object to a file, using one of the many supported formats. See writeValues for writing in chunks (e.g. by row). When writing a file to disk, the file format is determined by the 'format=' argument if supplied, or else by the file extension (if the extension is known). If other cases the default format is used. The 'factory-fresh' default format is 'raster', but this can be changed using setOptions.

Usage

writeRaster(x, filename, ...)

Arguments

x
Raster* object
filename
Output filename
...
Additional arguments. See below, under Methods

Value

  • This function is used for the side-effect of writing values to a file.

Methods

Full function call when x is a RasterLayer object writeRaster(x, filename='', ...) rll{ x RasterLayer object filename Output filename ... Additional arguments. See below } Full function call when x is a RasterBrick or RasterStack object writeRaster(x, filename='', bandorder='BIL', ...) rll{ x RasterLayer object filename Output filename bandorder Character. 'BIL', 'BIP', or 'BSQ' .. Additional arguments. See below } Additional arguments rll{ format Character. Output file type. See writeFormats datatype Character. Output data type. See dataType overwrite Logical. If TRUE, "filename" will be overwritten if it exists }

Details

See writeFormats for supported file types ("formats", "drivers"). The rgdal package is needed for this most formats. Except for the 'raster', 'BIL', 'BIP', 'BSQ', 'SAGA', 'ascii', 'IDRISI', and 'CDF' formats. Some of these formats can be used with or without rgdal (idrisi, SAGA, ascii). In multi-band files (i.e. files saved from RasterStack or RasterBrick objects), in the native 'raster' format, the bandorder can be set to BIL ('Bands Interleaved by Line'), BIP ('Bands Interleaved by Pixels') or BSQ ('Bands SeQuential'). Note that bandorder is not the same as filetype here. Supported file types include: llllr{ File type Long name default extension Multiband support raster 'Native' raster package format .grd Yes ascii ESRI Ascii .asc No SAGA SAGA GIS .sdat No IDRISI IDRISI .rst No CDF netCDF (requires RNetCDF) .nc pending GTiff GeoTiff (requires rgdal) .tif Yes ENVI ENVI .hdr Labelled .envi Yes EHdr ESRI .hdr Labelled .bil Yes HFA Erdas Imagine Images (.img) .img Yes }

See Also

writeFormats, and for faster writing: writeValues

Examples

Run this code
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(RNetCDF)) {	
    writeRaster(rst, filename='netCDF.nc', format="CDF", overwrite=TRUE)   
}

Run the code above in your browser using DataLab