Open dfriend21 opened 1 year ago
I do not get a crash with the large raster on windows with GDAL 3.5.2 nor on Ubuntu with GDAL 3.4.0 or GDAL 2.2.3. I do not have access to a Mac right now.
What is the version of GDAL you are using (as returned by terra::gdal()
)? And how did you install it terra? That is, do you use a binary install from CRAN or did you install from source?
I can confirm that this causes the crash. Large raster probably means that needs to be processed in blocks. I tested this example with 8 GB RAM, so maybe you should increase the number of pixels to reproduce it. I installed {terra}
from CRAN.
I installed terra
from CRAN, and running terra::gdal()
outputs "3.5.3"
.
Maybe I can add to this? I experience the same problem with very large datasets. I can create these objects in memory, but cannot read or write them using terra.
I tested this using the CRAN version, as well as binary and source versions of 1.7.30.
Here is a reprex:
Sys.info()
#> sysname release version nodename
#> "Windows" "10 x64" "build 19045" "MN030124-C0014"
#> machine login user effective_user
#> "x86-64" "Valentin" "Valentin" "Valentin"
packageVersion("terra")
#> [1] '1.7.30'
terra::gdal()
#> [1] "3.5.2"
r <- terra::rast(system.file("external/test.grd", package="raster"))
tfile <- tempfile(fileext = ".grd")
# stacking to make a large raster
# this works
terra::rast(lapply(1:100, function(i) r))
#> class : SpatRaster
#> dimensions : 115, 80, 100 (nrow, ncol, nlyr)
#> resolution : 40, 40 (x, y)
#> extent : 178400, 181600, 329400, 334000 (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +datum=WGS84 +units=m +no_defs
#> Warning in (grepl("Windows", osVersion)) && (nchar(x) > 256): 'length(x) = 100
#> > 1' in coercion to 'logical(1)'
#> sources : test.grd
#> test.grd
#> test.grd
#> ... and 97 more source(s)
#> names : test, test, test, test, test, test, ...
#> min values : 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, ...
#> max values : 1736.0579, 1736.0579, 1736.0579, 1736.0579, 1736.0579, 1736.0579, ...
# this as well
terra::writeRaster(terra::rast(lapply(1:50, function(i) r)),
filename = tfile,
overwrite = TRUE)
# but not this
terra::writeRaster(terra::rast(lapply(1:100, function(i) r)),
filename = tfile,
overwrite = TRUE)
#> Warning: `C:/Users/Valentin/AppData/Local/Temp/RtmpiuIm9J/file10383cc1aeb.grd'
#> not recognized as a supported file format. (GDAL error 4)
#> Error: [rast] cannot open this file as a SpatRaster: C:/Users/Valentin/AppData/Local/Temp/RtmpiuIm9J/file10383cc1aeb.grd
# Using raster package to write:
r <- raster::raster(system.file("external/test.grd", package="raster"))
raster::writeRaster(raster::stack(lapply(1:100, function(i) r)),
filename = tfile,
overwrite = TRUE)
raster::stack(tfile)
#> class : RasterStack
#> dimensions : 115, 80, 9200, 100 (nrow, ncol, ncell, nlayers)
#> resolution : 40, 40 (x, y)
#> extent : 178400, 181600, 329400, 334000 (xmin, xmax, ymin, ymax)
#> crs : +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +datum=WGS84 +units=m +no_defs
#> names : test.1, test.2, test.3, test.4, test.5, test.6, test.7, test.8, test.9, test.10, test.11, test.12, test.13, test.14, test.15, ...
#> min values : 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, 138.7071, ...
#> max values : 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, 1736.058, ...
# but reading still does not work
terra::rast(tfile)
#> Warning: `C:/Users/Valentin/AppData/Local/Temp/RtmpiuIm9J/file10383cc1aeb.grd'
#> not recognized as a supported file format. (GDAL error 4)
#> Error: [rast] cannot open this file as a SpatRaster: C:/Users/Valentin/AppData/Local/Temp/RtmpiuIm9J/file10383cc1aeb.grd
Created on 2023-04-26 with reprex v2.0.2
I've been playing around with setting GDAL options when using
writeRaster
. When using invalid GDAL settings with a relatively small raster,terra
outputs a warning that prints out the GDAL error(s) that occurred, which is as expected. However, when doing the same thing with a larger raster, R aborts. I've run across this a couple times, with different GDAL options. Here's some reproducible code demonstrating the problem.Note that this also occurred with different GDAL options (for example, setting the
gdal
parameter toCOMPRESS=JPEG
in the above code produced the same result).Here is the output of
sessioninfo::session_info()
: