Error using `compression` argument while writing a netCDF file (`writeRaster`)
elgabbas opened this issue · 0 comments
elgabbas commented
Hello,
I would like to export a raster object into netCDF file. However, I receive an error when using compression
argument.
# raster version: 3.6-26 # ncdf4 version: 1.22
require(raster); require(ncdf4)
Map <- raster::raster(
nrows = 404, ncols = 390, xmn = 2630000, xmx = 6530000,
ymn = 1380000, ymx = 5420000, crs = "epsg:3035", vals = 1:157560)
raster::writeRaster(Map, filename = "Map1.nc", format = "CDF")
file.size("Map1.nc") # 637396
raster::writeRaster(Map, filename = "Map2.nc", format = "CDF", compression = 5)
A smaller file was created, but with the following error:
# Error in R_nc4_open: NetCDF: Unknown file format
# Error in ncdf4::nc_open(filename, readunlim = FALSE, suppress_dimvals = TRUE) :
# Error in nc_open trying to open file D:\BioDT_IAS\Map2.nc (return_on_error= FALSE )
file.size("Map2.nc") # 201879
Setting options(HDF5_USE_FILE_LOCKING=FALSE)
, as suggested here, did not help.
I tried using terra::
but found an issue with the CRS information.
Any suggestions on how to avoid this issue?