terra::rasterize 包含多个属性的点
我有一个具有 10 个点和 2 个属性 (i_1, i_2) 的 SpatVector。我需要在一个网格单元上总结我的 SpatVector 覆盖这 10 个点,并认为 terra::rasterize 是最合适的函数来做到这一点。 rasterize 的输出需要考虑 SpatVector 的两个属性。但是,我只是不知道如何将属性传递给函数。例如,使用这个奇怪的函数:
fn <- function(i_1, i_2,...) {
out <- mean(i_1*i_2, na.rm = T)
return(out)
}
terra::rasterize(points, raster, fun = fn(i_1, i_2))
返回一个具有 1 行和 1 列(我想要的)但值为 1 的栅格,而如果我这样做:
fn(points$i_1, points$i_2)
我得到了我应该得到的东西。
要么我缺少如何将 SpatVector 的属性传递给 terra::rasterize 中的函数,要么该函数无法处理此分析。
I have a SpatVector with 10 points and 2 attributes (i_1, i_2). I need to summarise my SpatVector over one grid cell covering those 10 points and thought terra::rasterize was the most appropriate function to do just that. The output of rasterize needs to take into account both attributes of the SpatVector. However, I just can't figure it out how to pass the attributes to the function. E.g., using this odd function :
fn <- function(i_1, i_2,...) {
out <- mean(i_1*i_2, na.rm = T)
return(out)
}
terra::rasterize(points, raster, fun = fn(i_1, i_2))
returns a raster with 1 line and 1 column (what I wanted) but with value 1, whereas if I do:
fn(points$i_1, points$i_2)
I get what I'm supposed to be getting.
Either I'm missing how to pass the attributes of the SpatVector to the function in terra::rasterize or this function can't handle this analysis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您可以在使用
rasterize
之前组合这两个字段。同样的原则适用于更复杂的函数。首先应用函数,然后光栅化。除非该函数很复杂,例如,它取每个变量的平均值并将它们相加。在这种情况下,您需要逐步进行栅格化。
It would seem to me that you can combine the two fields prior to using
rasterize
The same principle applies for more complex functions. First apply the function, then rasterize. Unless the function is complex in the sense that it, for example, takes the mean of each variable and adds these. In that case, you need to rasterize in steps.