简体   繁体   English

R:“光栅”无法读取“readGDAL”能够读取的 GeoTIFF

[英]R: "raster" cannot read a GeoTIFF that "readGDAL" is able to read

Question :问题

I'm working with MODIS GeoTIFFs.我正在使用 MODIS GeoTIFF。 I want to use the sf and raster libraries.我想使用sfraster库。 The file easily opens with rgdal::readGDAL() , which gives me an object of type Large SpatialGridDataFrame .该文件使用rgdal::readGDAL()轻松打开,它为我提供了一个Large SpatialGridDataFrame类型的对象。 So the file is not corrupt.所以文件没有损坏。

Yet, if I use raster I get the following error:但是,如果我使用raster ,则会出现以下错误:

raster::raster("../MCD64A1/TIFF/Win09/2014/MCD64monthly.A2014001.Win09.006.burndate.tif")
  Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file.

More background info :更多背景信息

The same happens if I use raster::stack .如果我使用raster::stack也会发生同样的情况。

For reproduction: the file can be found in the MODIS -collection or be directly downloaded here .复制:该文件可以在MODIS- collection 中找到或直接在此处下载。 Relevant package versions are:相关的包版本是:

 [1] raster_3.4-13 rgeos_0.5-8   sf_0.9-8      rgdal_1.5-27  sp_1.4-2      RNetCDF_2.5-2

Edit :编辑

It seems raster hides some error message. raster似乎隐藏了一些错误消息。 Calling the internal .rasterFromGDAP directly reveals the error message.调用内部.rasterFromGDAP直接显示错误信息。 Though the fix remains unclear:尽管修复尚不清楚:

> raster:::.rasterFromGDAL("../MCD64A1/TIFF/Win09/2014
/MCD64monthly.A2014001.Win09.006.burndate.tif", type = "RasterLayer",band=1)
Error in CRS(crs, TRUE) : 
  PROJ4 argument-value pairs must begin with +: GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]

I do not get this error.我没有收到这个错误。

library(raster)
Loading required package: sp
f <- "MCD64monthly.A2014001.Win09.006.burndate.tif"
b <- raster(f)
b
#class      : RasterLayer 
#dimensions : 8533, 5461, 46598713  (nrow, ncol, ncell)
#resolution : 0.004394531, 0.004394531  (x, y)
#extent     : -19, 4.998535, 0.001464844, 37.5  (xmin, xmax, ymin, ymax)
#crs        : +proj=longlat +datum=WGS84 +no_defs 
#source     : MCD64monthly.A2014001.Win09.006.burndate.tif 
#names      : MCD64monthly.A2014001.Win09.006.burndate 
#min values :                                   -32768 
#max values :                                    32767 

sessionInfo()
# ...
#other attached packages:
#[1] raster_3.4-13 sp_1.4-5     
#loaded via a namespace (and not attached):
#[1] compiler_4.1.0   rgdal_1.5-27     tools_4.1.0      Rcpp_1.0.7       codetools_0.2-18 grid_4.1.0       #lattice_0.20-44 

I think it will go away for you as well after you update the sp package.我认为在您更新sp软件包后它也会消失。 When things do not work, it is good practice to first assure you have the latest versions of the R packages (perhaps run update.packages(ask=FALSE) )当事情不起作用时,最好首先确保您拥有最新版本的 R 包(也许运行update.packages(ask=FALSE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM