library(terra)
r <- rast(ncols=36, nrows=18)
r[500] <- 1
b <- buffer(r, width=5000000)
plot(b)
s <- rast(ncols=36, nrows=18)
values(s) <- runif(ncell(s))
tst <- mask(s, b)
plot(tst)
有谁知道为什么这里的 tst 和 s 完全一样吗?我可以使用缓冲区的输出作为掩码吗?
被屏蔽的内容由
maskvalues
配置,默认情况下是 NA
。b
缓冲区之外的值更改为 NA
,要么使用 mask(s, b, maskvalues = FALSE)
:
library(terra)
#> terra 1.7.39
par(mfrow = c(2, 1))
r <- rast(ncols=36, nrows=18)
r[500] <- 1
b <- buffer(r, width=5000000)
plot(b)
s <- rast(ncols=36, nrows=18)
values(s) <- runif(ncell(s))
# set FALSE values to NA
# b[!b] <- NA
# or change maskvalues arg to match the mask raster:
tst <- mask(s, b, maskvalues = FALSE)
plot(tst)
创建于 2023-08-03,使用 reprex v2.0.2