Closed Rapsodia86 closed 4 days ago
This does not work as indicated by the error message
library(terra)
ff <- c("HLS_S30_sr_evi2_doy2023347_aid0001_16N.tif", "HLS_S30_sr_evi2_doy2023342_aid0001_16N.tif")
e <- ext(c(633138, 634573, 4694581, 4697348))
rast(ff)
# Error: [rast] extents do not match
rast(ff, win=e)
# Error: [rast] extents do not match
This is a work-around if you know what you are doing
x <- rast(lapply(ff, \(f) rast(f, win=e)))
But things would go wrong if you now do
window(x) <- NULL
x * 1
# Error: [*] too few values for writing: 90288 < 180576
#In addition: Warning message:
#C:/Users/rhijm/Downloads/win_terra_rspatial_test/HLS_S30_sr_evi2_doy2023342_aid0001_16N.tif: Access window out of #range in RasterIO(). Requested (0,0) of size 304x297 on raster of 304x278. (GDAL error 5)
So to be on the safe side, I would remove your loophole --- but I won't do that for now.
Hi Robert! I am not sure if that is an issue, or the expected behavior. If the latter, then I take it back! I do have many files that I want to load as a raster stack. They have slightly different extents. To handle that, I would use the "win" argument in
rast()
, to "internally crop" the data and load up.If I do this in a loop, everything is ok. But if I use a vector of file names, then the error shows up:
Error: [rast] extents do not match
.Does that mean
rast()
first stacks all the rasters and then applies the "win"? Or it should be that it takes each object separately (like in a loop), applies the "win" and then stacks?Below is a small example with only two files: (terra dev version)
Thanks!
win_terra_rspatial_test.zip