Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The terra::update method does not update raster names. #1588

Open
shawcmat opened this issue Aug 21, 2024 · 0 comments
Open

The terra::update method does not update raster names. #1588

shawcmat opened this issue Aug 21, 2024 · 0 comments

Comments

@shawcmat
Copy link

The update() method of spatraster is supposed to be used to write new names or a new extent or crs to an existing raster file. However, this functionality is not working as intended. When running the provided example code, the names are not updated.

Example code (Pulled from the documentation):

s <- rast(system.file("ex/logo.tif", package="terra"))   
fname <- paste0(tempfile(), ".tif")
x <- writeRaster(s, fname)
names(x) # Original names are red, green, blue
names(x) <- c("A", "B", "C")  # names are changed to A, B, C
ext(x) <- ext(x) + 1
crs(x) <- "+proj=utm +zone=1
update(x, names=TRUE, crs=TRUE, extent=TRUE) # update method is called
rast(fname) # Should now be "A,B,C", but is instead still "red, green, blue"

Raster summary before the operation:

class       : SpatRaster 
dimensions  : 77, 101, 3  (nrow, ncol, nlyr)
resolution  : 1, 1  (x, y)
extent      : 0, 101, 0, 77  (xmin, xmax, ymin, ymax)
coord. ref. : Cartesian (Meter) 
source      : logo.tif 
colors RGB  : 1, 2, 3 
names       : red, green, blue 
min values  :   0,     0,    0 
max values  : 255,   255,  255

raster summary after the operation:

class       : SpatRaster 
dimensions  : 77, 101, 3  (nrow, ncol, nlyr)
resolution  : 1.019802, 1.025974  (x, y)
extent      : -1, 102, -1, 78  (xmin, xmax, ymin, ymax)
coord. ref. : WGS 84 / UTM zone 1N (EPSG:32601) 
source      : file8485403367c.tif 
colors RGB  : 1, 2, 3 
names       : red, green, blue 
min values  :   0,     0,    0 
max values  : 255,   255,  255

The CRS is updated, but the layer names remain unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant