terra
terra copied to clipboard
Error loading multiple rasters, however single raster works
Hi,
I tried loading multiple rasters using the code below. But I got an error. The error says
"Error: [rast] cannot open this file as a SpatRaster: C:/Users/pma311/Box/Earth_Data/SO/SO_2001_02.tiff In addition: Warning message: `C:/Users/pma311/Box/Earth_Data/SO/SO_2001_02.tiff' not recognized as a supported file format. (GDAL error 4) "
library(terra)
# Set the directory path and year range
dir_path <- "C:/Users/XXX/Box/Earth_Data/SO"
SO_files <- list.files(path=dir_path, pattern="\\.tif(f)?$",full.names=TRUE)
basename(SO_files)
# Filter only files with year 1998 to 2009
selected_files <- SO_files[grepl("(200[0-2])", SO_files)]
SO_rast <- lapply(selected_files, terra::rast)
Strangely I am able to open the said file or raster using this code
SO <- rast("C:/Users/XXX/Box/Earth_Data/SO/SO_2001_02.tiff")
Any idea what could be the problem?
sessionInfo() R version 4.3.0 (2023-04-21 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22621)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C LC_TIME=English_United States.utf8
time zone: America/New_York tzcode source: internal
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] terra_1.7-29
loaded via a namespace (and not attached): [1] compiler_4.3.0 tools_4.3.0 rstudioapi_0.14 Rcpp_1.0.10 codetools_0.2-19
I wonder if this is related to this being a box folder. What happens if you copy the folder to another location?
I wonder if this is related to this being a box folder. What happens if you copy the folder to another location?
Robert, it turns out you were right. Moving some of the data to Google Drive solved the problem. However, since I have a large amount of data and limited storage space on Google Drive (only 1 TB), I'm wondering if we should explore other options. One possible solution is to use Box, which offers unlimited storage space. Do you have any suggestions for addressing this issue, or should I contact Box directly?
I do not know what causes this. There was an unresolved similarly weird issue with NetCDF files on a Google Drive: https://github.com/rspatial/terra/issues/221
Does the below work (a relatively direct call to a GDAL function; rast is much more involved)?
d <- lapply(selected_files, terra::describe)
I do not know what causes this. There was an unresolved similarly weird issue with NetCDF files on a Google Drive: #221 Does the below work (a relatively direct call to a GDAL function;
rastis much more involved)?d <- lapply(selected_files, terra::describe)
Yes, it works.