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

Error: [*] cannot write values (err: 3) #1502

Closed
hzambran opened this issue May 9, 2024 · 1 comment
Closed

Error: [*] cannot write values (err: 3) #1502

hzambran opened this issue May 9, 2024 · 1 comment

Comments

@hzambran
Copy link

hzambran commented May 9, 2024

Unfortunately, I can not provide a minimal, self-contained, reproducible example that illustrates the Error: [*] cannot write values (err: 3), because very likely this error is related to the 17520 files that I read in into a single SpatRaster object.

Just after loading the terra package, I modified its options with:

terraOptions(memfrac=0.9, progress=10, verbose=FALSE, filetype="NetCDF")

then, I read all my 17520 GeoTIFF files into an x object and multiplied it by a single real number:

y <- 0.05*x
and just before finishing, that operation raised the following error message:

Error: [*] cannot write values (err: 3)
In addition: There were 50 or more warnings (use warnings() to see the first 50)

when I looked up into the warnings, I got (only the first 2 warnings are shown):

> warnings()
Warning messages:
1: netcdf error #-62 : NetCDF: One or more variable sizes violate format constraints .
at (netcdfdataset.cpp,SetDefineMode,2367)
 (GDAL error 1)
2: netcdf error #-39 : NetCDF: Operation not allowed in define mode .
at (netcdfdataset.cpp,IWriteBlock,2196)

I would be very grateful for any hint about how to solve this error.

My details about terra and GDAL are:

> packageVersion("terra")
[1] ‘1.7.71’
> terra::gdal(lib="all")
    gdal     proj     geos 
 "3.4.3"  "8.2.0" "3.10.2"
@rhijmans
Copy link
Member

I think I would write a loop like this to find the offending file(s):

terraOptions(todisk=TRUE)
for (i in 1:n) {
     x <- try(writeRaster(rast(files[i]), "test.tif", overwrite=TRUE)
     if (inherits(x, "try-error")) print(files[i])
}

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

2 participants