raster (version 1.1.7)

initialize: Intitialize

Description

Set values for a new raster (from scratch), either using a formula or by choose a variable v from 'x', 'y', 'col', 'row', or 'cell'. When using a function, cell values are initialized without reference to pre-existing values. E.g., initialize with a random number (fun=runif). Either supply an argument to fun, or to v, but not both.

Usage

init(raster, fun, v, filename="", ...)

Arguments

raster
A RasterLayer object
fun
The function to be applied. This must be a function that can take the number of cells as a single argument to return a vector of values with a length equal to the number of cells
v
'x', 'y', 'row', 'col', or 'cell'
filename
Output filename
...
Additional arguments. See Details

Value

  • A new RasterLayer object, and, in some cases, the side effect of a new file on disk.

Details

The following additional arguments can be passed, to replace default values for this function rll{ overwrite Logical. If TRUE, "filename" will be overwritten if it exists format Character. Output file type. See writeRaster datatype Character. Output data type. See dataType progress Character. Valid values are "text", "tcltk", "windows" (on that platform only) and "" }

Examples

Run this code
r <- raster(ncols=36, nrows=18)
r <- init(r, fun=runif)
# there are different ways to set all values to 1 
set1f <- function(x){rep(1, x)}
r <- init(r, fun=set1f, filename='test.grd', overwrite=TRUE)
# easier to do "manually"
r <- setValues(r, rep(1, ncell(r)))
# or  
r[] <- rep(1, ncell(r))
r[] <- 1

Run the code above in your browser using DataCamp Workspace