[英]How do I stack raster files in R?
I am trying to perform a raster stack using three spatial raster that are in .grd format, in R using the dismo package.The three grid files are in the path "D:~" . 我正在尝试使用dismo包在R中使用三个.grd格式的空间栅格来执行栅格堆栈。这三个栅格文件位于路径“ D:〜”中。 I am using this code, 我正在使用此代码,
files= list.files(path = "D:~",pattern = 'grd',full.names = TRUE)
the error output am getting is files= list.files(path = "D:~",pattern = 'grd',full.names = TRUE)
输出的错误是
Error in x[[1]] : subscript out of bounds
Can anyone help? 有人可以帮忙吗? thanks in advance 提前致谢
If the files are in sub-directories then you can use recursive=TRUE
: 如果文件位于子目录中,则可以使用recursive=TRUE
:
files <- list.files(path="D:", pattern="grd", all.files=FALSE, full.names=TRUE,recursive=TRUE)
s <- stack(files)
Simply use the stack function from the raster package: 只需使用光栅包中的堆栈功能:
files=c("layer1.grd", "layer2.grd", "layer3.grd")
library(raster)
raster_stack=stack(files)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.