问题描述
假设我有一个以一定分辨率表示土地利用类别的栅格.我必须将此栅格与R汇总到一个较粗的分辨率和一个模态值方法,以便在较粗的栅格中拥有最主要的像元值.
Let's assume I have a raster representing land use classes in a certain resolution. I have to aggregate this raster with R to a coarser resolution and a modal value approach, in order to have the most dominating cell value in the coarser raster. This is easily achieved with
m <- aggregate(r, fact = 3, fun = modal, na.rm = TRUE)
但是,我想对不同的土地利用类别进行加权-例如森林等级(代码1)的权重为4,而水等级(代码2)的权重为2,而街道等级的权重为1.
However, I would like to weight the different land use classes – e.g. forest class (code 1) has a weight of 4 while water class (code 2) has a weight of 2 and street class has a weight of 1.
是否存在遍历栅格像元并为每个像元施加权重的函数?
Is there a function that iterates through raster cells and applies a weight for each cell?
感谢您的帮助吗?
推荐答案
您可以使用reclassify
来应用权重,但是那又是什么呢?之后,您仍然要计算模态值吗?
You could use reclassify
to applying weights, but then what? Do you still want to compute the modal value after that?
我认为您想要的是您提供的汇总功能.也许像这样
I think what you want is your own function that you provide to aggregate. Perhaps something like this
library(raster)
f <- function(x, ...) {
y <- c(
rep(x[x==1], 4),
rep(x[x==2], 2),
x[x==3]
)
modal(y, ...)
}
r <- raster(res=5)
values(r) <- sample(c(1:3,2,3,3), ncell(r), replace=TRUE)
a <- aggregate(r, fact=10, fun=f)
这篇关于基于类的加权栅格聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!