r - 如何有效地将多个光栅(.tif)文件导入 R
问题描述
我是 R 新手,尤其是在空间数据方面。我正在尝试找到一种方法将多个(~600)单波段光栅(.tif)文件有效地导入 R,所有文件都存储在同一个文件夹中。不确定这是否重要,但请注意,在我的 Mac 和 Windows Parallel VM 上的文件夹中查看时,每个 .tif = .TIF 有以下五 (5) 种文件格式;.tfw; .TIF.aux.xml;.TIF.ovr; .TIF.xml。无论如何,以下代码(以及我尝试过的其他类似变体)似乎不起作用:
library(sp)
library(rgdal)
library(raster)
#path to where all .tif files are located
setwd("/path/to/workingdirectory")
#my attempt to create a list of my .tif files for lapply
temp = list.files(pattern="*.tif")
temp #returns 'character(0)'
#trying to use the raster function to read all .tif files
myfiles = lapply(temp, raster)
myfiles #returns 'list()'
有没有办法使用某种形式的循环来有效地导入所有光栅文件?
解决方案
如果栅格具有相同的范围,您可以简单地将它们加载到堆栈中
#first import all files in a single folder as a list
rastlist <- list.files(path = "/path/to/wd", pattern='.TIF$', all.files=TRUE, full.names=FALSE)
library(raster)
allrasters <- stack(rastlist)
推荐阅读
- google-cloud-platform - 是否可以在 Google Cloud 平台中隐藏 BigQuery 查询执行日志?
- firebase - Firebase 函数返回未定义的、预期的 Promise 或值,但该函数有效
- android - 如何使用 Firebase SDK 向 Google Analytics 报告在移动应用中进行但离线支付的购买
- reactjs - Web-worker 问题:未捕获的 DOMException:无法在“Worker”上执行“postMessage”
- github-actions - github操作,构建docker镜像,根据分支名称设置名称
- c - fprintf 和 stdout 的整体效率
- amazon-web-services - aws 胶水`ImportError:无法导入名称'S3ArnParamHandler'`
- react-native - React Native - ExpoPixi:非法调用
- php - 使用 symfony 命令发送邮件时嵌入图像不可读
- typescript - TypeScript:将输入类型 T 映射到树状类型