【发布时间】:2021-08-10 18:31:24
【问题描述】:
我有 90 个栅格需要裁剪和重新采样以匹配我的模板栅格。有没有办法让我“自动化”? (即,只需要运行一次该过程,例如,我可以让它运行一夜)
我知道答案可能是“循环”,但我不知道该怎么做,因为每个原始文件都有不同的名称,最终产品需要具有相同的名称,但以“_final.升序”
这是我一直在使用的代码:
library(raster)
#load original world raster (the one to be processed)
mau <- raster("PATH/name_of_the_raster.asc")
#load bounding box raster made by me (to clip the original and therefore make the next steps easier)
rastergrande <- raster("PATH")
#clip original raster by bounding box raster
intermedio <- crop(mau, rastergrande)
#load my template raster (the one that has the extent and cell size I want)
template <- raster("PATH")
#resample raster to template parameters
novoraster <- resample(intermedio, template, "bilinear")
#assign NA's to where template is NA
values(novoraster)[is.na(values(template))] <- NA
#Export to ascii
writeRaster(novoraster, "PATH/name_of_the_raster_final.asc", overwrite=TRUE)
【问题讨论】: