## update metadata
s <- rast(system.file("ex/logo.tif", package="terra"))
fname <- paste0(tempfile(), ".tif")
x <- writeRaster(s*1, fname)
ext(x) <- ext(x) + 1
crs(x) <- "+proj=utm +zone=1"
names(x) <- LETTERS[1:3]
update(x, crs=TRUE, extent=TRUE, names=TRUE)
rast(fname)
## update cell values on disk
r <- rast(nrows=10, ncols=10, vals=1:100)
f <- paste0(tempfile(), ".tif")
x <- writeRaster(r, f)
x[c(1, 2, 50, 51, 100)]
update(x, cells=c(1, 50, 100), values=c(999, 888, 777))
rast(f)[c(1, 2, 50, 51, 100)]
## update specific layer only
r <- rast(nrows=5, ncols=5, nlyr=3, vals=1:75)
f <- paste0(tempfile(), ".tif")
x <- writeRaster(r, f, datatype="FLT4S")
x[c(1, 2, 25, 26)]
update(x, cells=c(1, 25), values=c(0, 0), layer=2)
rast(f)[c(1, 2, 25, 26)]
Run the code above in your browser using DataLab