Search code examples
rterra

Error: [rast] cannot open this file as a SpatRaster,


> for(nc_file in pkulist){
+      nc_date <- rast(nc_file, lyrs = 1)
+      raster_list[[length(raster_list) + 1]]<- nc_date
+  }
Error: [rast] cannot open this file as a SpatRaster: ./PKU_GIMMS_NDVI_AVHRR_MODIS_consolidated_1991_2000/PKU_GIMMS_NDVI_V1.2_20000801.tif.aux.xml
In addition: Warning message:
`./PKU_GIMMS_NDVI_AVHRR_MODIS_consolidated_1991_2000/PKU_GIMMS_NDVI_V1.2_20000801.tif.aux.xml' not recognized as a supported file format. (GDAL error 4) 
Error in .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: (nil)>,  : 
  NULL value passed as symbol address

How to resolve this problem?


Solution

  • The error messages seems very clear. You are trying to create a raster from a file that does not represent raster data (it is a "sidecar" file to a proper raster file).

    As Chris points out, you could do something like

    ff <- list.files(pattern = '.tif$') 
    

    Followed by

    x <- rast(ff)
    

    or perhaps

    x <- rast(lapply(ff, \(f) rast(f, lyrs=1)))