我试图用terra打开一个.nc文件,但是我得到了以下错误:
'' not recognised as a supported file format. (GDAL error 4)此处可重复的示例(16 nc文件):
if (!file.exists("HadISST_ice.nc")) {
download.file("https://www.metoffice.gov.uk/hadobs/hadisst/data/HadISST_ice.nc.gz","HadISST_ice.nc.gz")
R.utils:::gunzip("HadISST_ice.nc.gz")
}
library(terra)
hadISST <- rast('HadISST_ice.nc') 该文件以raster::brick打开,但不使用terra:rast,如果我从@robert-hijmnan answer中正确理解,这是因为raster使用ncdf4,而terra使用GDAL。
在GDAL中,.nc文件通过终端打开,没有任何问题:
% gdalinfo HadISST_ice.nc
Driver: netCDF/Network Common Data Format
Files: HadISST_ice.nc
Size is 512, 512但是,如果不抛出GDAL错误4,则无法使用terra读取文件。
print(sessionInfo())
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.4
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] terra_1.5-34
loaded via a namespace (and not attached):
[1] compiler_4.2.0 tools_4.2.0 Rcpp_1.0.8.3 codetools_0.2-18和GDAL:
% gdal-config --version
GDAL 3.5.0, released 2022/05/10发布于 2022-06-24 23:16:02
编辑:问题似乎与MacOS特定的问题有关,因为netCDF驱动程序没有安装terra:
R terra gdal version incorrect, cannot read .nc (GDAL error 4)
安装terra的开发版本解决了这个问题:
install.packages('terra', repos='https://rspatial.r-universe.dev’)
https://stackoverflow.com/questions/72750110
复制相似问题