Unable to create a rasterlayer while attempting to read in spectral bands

41 Views Asked by At

I am loading the bands of Landsat8 to plot my vegetation indices but getting this error -

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file. (file does not exist)
In addition: Warning message:
LC08_L1TP_205021_20190628_20200827_02_T1_B2: No such file or directory (GDAL error 4) 

I have checked to be sure the downloaded images are in my working directory as set on the worksheet.

1

There are 1 best solutions below

0
Robert Hijmans On

Clearly, the file does not exist in your working directory. At least you are not providing any evidence to the contrary.

What you could do with the filename you want to use is

f <- "LC08_L1TP_205021_20190628_20200827_02_T1_B2"
file.exists(f)

If that returns FALSE the file is not there.

It is strange that your filename does not have an extension. It should probably be

f <- "LC08_L1TP_205021_20190628_20200827_02_T1_B2.tif"
file.exists(f)

A good way to get filenames can be

ff <- list.files(pattern="LC08_L1TP_205021_20190628_20200827")