简体   繁体   中英

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

Question :

I'm working with MODIS GeoTIFFs. I want to use the sf and raster libraries. The file easily opens with rgdal::readGDAL() , which gives me an object of type Large SpatialGridDataFrame . So the file is not corrupt.

Yet, if I use raster I get the following error:

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 .

For reproduction: the file can be found in the MODIS -collection or be directly downloaded here . 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. Calling the internal .rasterFromGDAP directly reveals the error message. 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. 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) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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