Description Usage Arguments Value Note Examples
Create a new RasterLayer with values reflecting a cell property: 'x', 'y', 'col', 'row', or 'cell'. Alternatively, a function can be used. In that case, cell values are initialized without reference to pre-existing values. E.g., initialize with a random number (fun=runif
). While there are more direct ways of achieving this for small objects (see examples) for which a vector with all values can be created in memory, the init
function will also work for Raster* objects with many cells.
1 2 |
x |
Raster* object |
fun |
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, such as |
filename |
character. Optional output filename |
... |
Additional arguments as for |
RasterLayer
For backwards compatibility, the character values valid for fun
can also be passed as named argument v
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | r <- raster(ncols=36, nrows=18)
x <- init(r, fun='cell')
y <- init(r, fun=runif)
# there are different ways to set all values to 1
# for large rasters:
# set1f <- function(x){rep(1, x)}
# z1 <- init(r, fun=set1f, filename=rasterTmpFile(), overwrite=TRUE)
# This is equivalent to (but not memory safe):
z2 <- setValues(r, rep(1, ncell(r)))
# or
values(r) <- rep(1, ncell(r))
# or
values(r) <- 1
|
Loading required package: sp
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.