Class based weighted raster aggregation

女生的网名这么多〃 提交于 2019-12-11 07:05:46

问题


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)

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?

Thanks for any help?


回答1:


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)


来源:https://stackoverflow.com/questions/56989358/class-based-weighted-raster-aggregation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!