【发布时间】:2023-02-04 03:26:58
【问题描述】:
在下面的代码中,我尝试使用 resample(x, y, method = "sum") 将高分辨率栅格重新采样为低分辨率栅格。但是,重采样栅格在某些边缘显示 NA。
library(terra)
set.seed(42)
low_res <- rast(xmin = -1.05, xmax = 1.05, ymin = -0.05, ymax = 2.05, res = 0.5)
high_res <- rast(xmin = -1, xmax = 1, ymin = 0, ymax = 2, res = 0.01)
high_res[] <- runif(ncell(high_res))
plot(high_res, colNA = "darkblue")
resampled <- resample(high_res, low_res, method = "sum")
plot(resampled, colNA = "darkblue")
plot(as.polygons(low_res), add=TRUE, border='black', lwd=1)
高分辨率栅格:
重采样栅格(深蓝色像元为 NA):
但是,如果将低分辨率栅格的范围四舍五入(即删除 _.05),一切看起来都不错:
library(terra)
set.seed(42)
##################################
# only changed extent here
low_res <- rast(xmin = -1, xmax = 1, ymin = -0, ymax = 2, res = 0.5)
##################################
high_res <- rast(xmin = -1, xmax = 1, ymin = 0, ymax = 2, res = 0.01)
high_res[] <- runif(ncell(high_res))
plot(high_res, colNA = "darkblue")
resampled <- resample(high_res, low_res, method = "sum")
plot(resampled, colNA = "darkblue")
plot(as.polygons(low_res), add=TRUE, border='black', lwd=1)
重采样栅格:
【问题讨论】: