EVOLUTION-MANAGER
Edit File: writeValues.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: Write values to a file</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 writeValues {raster}"><tr><td>writeValues {raster}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Write values to a file</h2> <h3>Description</h3> <p>Functions for writing blocks (>= 1 row(s)) of values to files. Writing has to start at the first cell of a row (identified with argument <code>start</code>) and the values written must represent 1 or more entire rows. Begin by opening a file with <code>writeStart</code>, then write values to it in chunks. When writing is done close the file with <code>writeStop</code>. </p> <p>If you want to write all values of a Raster* object at once, you can also use <code><a href="writeRaster.html">writeRaster</a></code> which is easier to use but more limited. The functions described here allow writing values to file using chunks of different sizes (e.g. 1 or 10 rows). Function <code><a href="blockSize.html">blockSize</a></code> can be used to suggest a chunk size to use. </p> <h3>Usage</h3> <pre> ## S4 method for signature 'RasterLayer,character' writeStart(x, filename, options=NULL, format, prj=FALSE, ...) ## S4 method for signature 'RasterBrick,character' writeStart(x, filename, options=NULL, format, prj=FALSE, ...) ## S4 method for signature 'RasterLayer,vector' writeValues(x, v, start, ...) ## S4 method for signature 'RasterBrick,matrix' writeValues(x, v, start, ...) ## S4 method for signature 'RasterLayer' writeStop(x) ## S4 method for signature 'RasterBrick' writeStop(x) </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>filename</code></td> <td> <p>character. Output file name</p> </td></tr> <tr valign="top"><td><code>options</code></td> <td> <p>character, see <code><a href="writeRaster.html">writeRaster</a></code></p> </td></tr> <tr valign="top"><td><code>format</code></td> <td> <p>character, see <code><a href="writeRaster.html">writeRaster</a></code></p> </td></tr> <tr valign="top"><td><code>prj</code></td> <td> <p>logical. If <code>TRUE</code>, a "prj" file is written</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> <tr valign="top"><td><code>v</code></td> <td> <p>vector (RasterLayer) or matrix (RasterBrick) of values</p> </td></tr> <tr valign="top"><td><code>start</code></td> <td> <p>Integer. Row number (counting starts at 1) from where to start writing <code>v</code></p> </td></tr> </table> <h3>Value</h3> <p>RasterLayer or RasterBrick </p> <h3>See Also</h3> <p><code><a href="writeRaster.html">writeRaster</a>, <a href="blockSize.html">blockSize</a>, <a href="update.html">update</a></code> </p> <h3>Examples</h3> <pre> ## Not run: r <- raster(system.file("external/test.grd", package="raster")) # write to a new binary file in chunks s <- raster(r) # tr <- blockSize(r) tr s <- writeStart(s, filename='test.grd', overwrite=TRUE) for (i in 1:tr$n) { v <- getValuesBlock(r, row=tr$row[i], nrows=tr$nrows[i]) s <- writeValues(s, v, tr$row[i]) } s <- writeStop(s) if(require(rgdal)){ s2 <- writeStart(s, filename='test2.tif', format='GTiff', overwrite=TRUE) # writing last row first for (i in tr$n:1) { v <- getValuesBlock(r, row=tr$row[i], nrows=tr$nrows[i]) s2 <- writeValues(s2, v, tr$row[i]) } # row number 5 once more v <- getValuesBlock(r, row=5, nrows=1) writeValues(s2, v, 5) s2 <- writeStop(s2) } ## write values of a RasterStack to a RasterBrick s <- stack(system.file("external/rlogo.grd", package="raster")) # create empty brick b <- brick(s, values=FALSE) b <- writeStart(b, filename="test.grd", format="raster",overwrite=TRUE) tr <- blockSize(b) for (i in 1:tr$n) { v <- getValuesBlock(s, row=tr$row[i], nrows=tr$nrows[i]) b <- writeValues(b, v, tr$row[i]) } b <- writeStop(b) # note that the above is equivalent to # b <- writeRaster(s, filename="test.grd", format="raster",overwrite=TRUE) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>raster</em> version 3.3-13 <a href="00Index.html">Index</a>]</div> </body></html>