0

I have 2 raster images of different spatial resolution and projection.

I want to resample multiple coarser images (0.25 degrees) to finer resolution(4 km) based on one finer resolution image which is of 4 km. Both are in different folders. I am not getting how to do that.

I had written the code in R but I am getting an error.

library(resample)
>setwd("D:/mtech project/data/DEC 16/RH/1-DEC-16/extracted/")
>inFiles1 <- list.files(pattern="*.tif")
> nFiles1 <-  length(inFiles1)
> setwd("D:/mtech project/data/extracted/")
> inFiles2 <- raster("3DIMG_01DEC2016_0000_L2C_FOG_FOG.tif")
> for (i in 1:nFiles1) {
+     r1<-raster(inFiles1[[i]])    
+     r2<-inFiles2    
+     rs<-resample(r1,r2,method="bilinear")
+     write.Raster(rs, paste0('D:/mtech project/data/DEC 16/RH/RESAMPLED/rs_',i,'.img'), overwrite=T)
+   }

Error in .local(.Object, ...) : 

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

`

  • Does your file exist? Perhaps it needs to be "D://mtech/..." ? – Richard Law Nov 24 '18 at 3:37
1

You changed your working directory, after creating the list of inputfiles inFiles1. As a result, the relative path to the files is not valid anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.