1

I imported raster files into R (Landsat TM-5 surface reflectance products). Now I want to crop these rasters using boundaries of my test region (also raster file). Importing went well without any mistakes. But when I tried to use crop function I've got an error message: Error in .local(.Object, ...) :

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file. (file does not exist).

I cannot figure out what the problem is. I have tried, but the code run unsuccessfully. The code and the error are these:

red0610=raster("LT51710242010172MOR00_sr_band3.tif")
nir0610=raster("LT51710242010172MOR00_sr_band4.tif")
red0910=raster("LT51720242010259MOR00_sr_band3.tif")
nir0910=raster("LT51720242010259MOR00_sr_band4.tif")
testfields=raster("testfields.tif")
red0610=crop(testfields,red0610)
Error in .local(.Object, ...) : 
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
Cannot create a RasterLayer object from this file. (file does not exist)

Imported files located in working directory. I would be very greatful for any help.

Eriawan Kusumawardhono
  • 4,796
  • 4
  • 46
  • 49
Elena
  • 13
  • 7
  • 1
    Impossible to reproduce but the error message states `file does not exist` so you might want to make sure you're reading in the correct folder. – HubertL Dec 09 '16 at 08:38
  • Looks like your file path is wrong. – maRtin Dec 09 '16 at 13:18
  • I wonder why my path is wrong. All files are located in one folder which I set as working directory. I imported them without problem, but I can't work with them. When I type the name of the imported file, R shows the information (coordinate system, resolutiuon, etc.). But when I am trying to cut or resample, I've got an error message. In R-studio Environmet they are shown as Formal Class Rasterlayer. I am frustrated. – Elena Dec 12 '16 at 08:21
  • I am still confused by the error message. At what line does the error occur? This error message usually points to the functions `raster()` or `stack()`, more precisely when the filepath is wrong. Can you please double check if both rasters `red0610` and `testfields` are properly loaded into R (maybe show the output when you call these objects). – maRtin Dec 12 '16 at 19:03
  • It should not be a problem, but you are using the same name in your crop function. Try `red0610_temp <- crop(testfields,red0610)` sometimes the raster packages has weird behaviour with is temporary files. Also, stop working with `setwd()` and write the full path instead. – Bastien Dec 13 '16 at 16:17
  • Other option: what is your working directory? Can you do `red0610+nir0610`? What is your `rasterOptions` tmpdir? Do you have writing rights? – Bastien Dec 13 '16 at 17:42
  • Actually, all perfectly worked on my laptop at home. I saved all I did as Workspace and when I opened it on my computer at work everything was fine. – Elena May 16 '17 at 11:40

0 Answers0