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 using compression argument while writing a netCDF file (writeRaster) #332

Open
elgabbas opened this issue Mar 14, 2024 · 0 comments
Open

Comments

@elgabbas
Copy link

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?

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

1 participant