我有一个名为AOT的文件夹,其图像名称范围为1:744。我还有一个名为FOG的文件夹,其中有一个图像名称-'01DEC2016_0000_L2C_FOG_FOG.tif'。我需要使用FOG中的'01DEC2016_0000_L2C_FOG_FOG.FOF'和AOT文件夹中的所有744个文件对AOT中的1.tif进行重新采样。我正在借助循环进行重采样,但是会出现一个错误。
我尝试过:
> require(raster)
#reading files from folder AOT
> flname1 <- list.files(path = 'D:/mtech project/data/DEC
16/POLLUTANTS/OUTPUT_AOT/', pattern = '.tif')
> nfile1<- length(flname1)
#reading files from folder FOG
> flname2<- raster("D:/mtech project/data/DEC
16/FOG/EXTRACTED_IGP/01DEC2016_0000_L2C_FOG_FOG.tif")
#Resampling the data in AOT folder with the data in FOG folder.
> for (i in 1:nfile1) {
+ r1<-raster(flname1[[i]])
+ r2<-raster(flname2[[i]])
+ rs<-resample(r1,r2,method='ngb')
+ }
Error in .local(.Object, ...) :
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",
:
Cannot create a RasterLayer object from this file. (file does not exist)
答案 0 :(得分:0)
您不是在读取文件列表或一个文件,而是立即创建一个栅格对象。 如果要针对一个文件重新采样多个文件,这可能是一种解决方案:
$python-config --includes
如果要针对多个文件对多个文件重新采样,代码将是,但是必须确保library(raster)
# reading files from folder AOT
flname1 <- list.files(path = "D:/mtech project/data/DEC 16/POLLUTANTS/OUTPUT_AOT/"),
pattern = ".tif",
full.names = TRUE)
nfile1 <- length(flname1)
# reading file from folder FOG
flname2 <- "D:/mtech project/data/DEC 16/FOG/EXTRACTED_IGP/01DEC2016_0000_L2C_FOG_FOG.tif"
# create raster
r2 <- raster(flname2)
# Resampling the data in AOT folder with the data in FOG folder.
for (i in 1:nfile1) {
r1 <- raster(flname1[i])
rs <- resample(r1, r2, method = "ngb")
}
和flname1
包含相同数量的文件:
flname2