Learn R Programming

terra (version 1.7-83)

update: Change values in a file

Description

Change the contents of a file that is the data source of a SpatRaster. BE CAREFUL as you are overwriting values in an existing file.

Usage

# S4 method for SpatRaster
update(object, names=FALSE, crs=FALSE, extent=FALSE)

Value

SpatRaster (invisibly)

Arguments

object

SpatRaster

names

logical. Should the names be updated?

crs

logical. Should the coordinate reference system be updated?

extent

logical. Should the extent be updated?

Examples

Run this code
s <- rast(system.file("ex/logo.tif", package="terra"))   
fname <- paste0(tempfile(), ".tif")
x <- writeRaster(s, fname)
names(x) <- c("A", "B", "C")
ext(x) <- ext(x) + 1
crs(x) <- "+proj=utm +zone=1"

update(x, names=TRUE, crs=TRUE, extent=TRUE)

rast(fname)

Run the code above in your browser using DataLab