Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

update

Update raster cells of files (on disk)


Description

Update cell values of a file (i.e., cell values on disk) associated with a RasterLayer or RasterBrick.

User beware: this function _will_ make changes to your file (first make a copy if you are not sure what you are doing).

Writing starts at a cell number cell. You can write a vector of values (in cell order), or a matrix. You can also provide a vector of cell numbers (of the same length as vector v) to update individual cells.

See writeFormats for supported formats.

Usage

## S4 method for signature 'RasterLayer'
update(object, v, cell, ...)
## S4 method for signature 'RasterBrick'
update(object, v, cell, band, ...)

Arguments

object

RasterLayer or RasterBrick that is associated with a file

v

vector or matrix with new values

cell

cell from where to start writing. Or a vector of cell numbers if v is a vector of the same length

.

band

band (layer) to update (for RasterBrick objects)

.

...

additional arguments. None implemented

Value

RasterLayer or RasterBrick

Examples

## Not run: 
# setting up an example RasterLayer with file
r <- raster(nrow=5, ncol=10, vals=0)
r <- writeRaster(r, rasterTmpFile(), overwrite=TRUE, datatype='INT2S')
as.matrix(r)

# update with a vector starting a cell
r <- update(r, v=rep(1, 5), cell=6)
# 99.99 gets rounded because this is an integer file
r <- update(r, v=9.99, cell=50)
as.matrix(r)

# update with a vector of values and matching vector of cell numbers
r <- update(r, v=5:1, cell=c(5,15,25,35,45))
as.matrix(r)

# updating with a marix, anchored at a cell number
m <- matrix(1:10, ncol=2)
r <- update(r, v=m, cell=2)
as.matrix(r)

## End(Not run)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.