EVOLUTION-MANAGER
Edit File: init.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Initialize a Raster object with values</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for initialize {raster}"><tr><td>initialize {raster}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Initialize a Raster object with values</h2> <h3>Description</h3> <p>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 (<code>fun=<a href="../../stats/html/Uniform.html">runif</a></code>). 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 <code>init</code> function will also work for Raster* objects with many cells. </p> <h3>Usage</h3> <pre> ## S4 method for signature 'Raster' init(x, fun, filename="", ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>Raster* object</p> </td></tr> <tr valign="top"><td><code>fun</code></td> <td> <p>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 <code>fun=runif</code>. You can also supply one of the following character values: 'x', 'y', 'row', 'col', or 'cell' to get the x or coordinate, row, col or cell number; you can also use 'chess', to get a chessboard pattern</p> </td></tr> <tr valign="top"><td><code>filename</code></td> <td> <p>character. Optional output filename</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments as for <code><a href="writeRaster.html">writeRaster</a></code></p> </td></tr> </table> <h3>Value</h3> <p>RasterLayer </p> <h3>Note</h3> <p>For backwards compatibility, the character values valid for <code>fun</code> can also be passed as named argument <code>v</code> </p> <h3>Examples</h3> <pre> 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 </pre> <hr /><div style="text-align: center;">[Package <em>raster</em> version 3.3-13 <a href="00Index.html">Index</a>]</div> </body></html>