R에서 여러 .tif 파일로 작업하려고했습니다 .tif 파일을 다시 투영하려고했습니다. 작업하면서 다음 코드를 실행했습니다. 루프 함수를 사용하여 여러 래스터 파일을 다시 투영하는 방법
#convert into raster and reproject
mylist <- list.files(path='mydir', pattern = "*.tif$")
fname <- substr(mylist, 1,20)
fn <- paste0('prj',fname, '.tif')
newproj <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
for (i in 1:4){
temprast <- raster(mylist[i])
prj<-projectRaster(temprast, crs=newproj, method = 'bilinear')
writeRaster(prj, filename = fn, format='GTiff', overwrite=T)
}
코드를 실행 한 후 나는
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file.
In addition: There were 20 warnings (use warnings() to see them)
Warning messages:
1: In if (filename == "") { ... :
the condition has length > 1 and only the first element will be used
2: In if (!file.exists(dirname(filename))) { ... :
the condition has length > 1 and only the first element will be used
3: In if (toupper([email protected]@name) == toupper(filename)) { ... :
the condition has length > 1 and only the first element will be used
4: In if (trim(filename) == "") { ... :
the condition has length > 1 and only the first element will be used
5: In if (!file.exists(dirname(filename))) { ... :
the condition has length > 1 and only the first element will be used
6: In if (filename == "") { ... :
the condition has length > 1 and only the first element will be used
7: In if (file.exists(filename)) { ... :
the condition has length > 1 and only the first element will be used
8: In if (nchar(filename) == 0) stop("empty file name") :
the condition has length > 1 and only the first element will be used
9: In if (x == "" | x == ".") { ... :
the condition has length > 1 and only the first element will be used
10: In if (!start %in% c("http", "ftp")) { ... :
the condition has length > 1 and only the first element will be used
11: In if (fileext %in% c(".GRD", ".GRI")) { ... :
the condition has length > 1 and only the first element will be used
12: In if (!file.exists(x)) { ... :
the condition has length > 1 and only the first element will be used
13: In if ((fileext %in% c(".HE5", ".NC", ".NCF", ".NC4", ... :
the condition has length > 1 and only the first element will be used
14: In if (fileext == ".GRD") { ... :
the condition has length > 1 and only the first element will be used
15: In if (fileext == ".BIG" | fileext == ".BRD") { ... :
the condition has length > 1 and only the first element will be used
16: In if (fileext %in% c(".BIN")) { ... :
the condition has length > 1 and only the first element will be used
17: In if (fileext == ".DOC") { ... :
the condition has length > 1 and only the first element will be used
18: In if (fileext %in% c(".SGRD", ".SDAT")) { ... :
the condition has length > 1 and only the first element will be used
19: In if (nchar(filename) == 0) stop("empty file name") :
the condition has length > 1 and only the first element will be used
20: In if (!file.exists(x)) { ... :
the condition has length > 1 and only the first element will be used
이 사람이 나를이 점에서 도울 수
다음과 같은 오류가있어? 감사합니다
가'raster'를 호출하기 전에 파일 이름을 인쇄 해보십시오. 'full = TRUE'를'list.files'에 추가하여 이름 만이 아닌 * 전체 경로 *를 반환하십시오. '1 : 4'를 하드 코딩하는 대신'mylist'의 길이를 반복 해보십시오. 여기서 물어보기 전에 기본 디버깅을 시도해보십시오. – Spacedman
제안 해 주셔서 감사합니다. 그러나, 나는이 아이디어를 시도한 후에 같은 오류가 발생했습니다. 전체 경로 이름을 추가하고 파일 길이에 걸쳐 루프를 시도했습니다. 같은 오류가 나타납니다. – user2968058
'mylist [i]'를 루프에서 인쇄하기 전에 인쇄하십시오. 내용을 확인하십시오. 그것이 실패한 파일을 확인하십시오 - 첫 번째? 두번째? 그런 다음 명령 줄에서'raster ("/ whatever/is/printed/out.tif")'를 실행 해보십시오. 파일이 손상되었을 수 있습니까? – Spacedman