gdistance中过渡函数的适当方法 [英] Appropriate method for transition function in gdistance

查看:154
本文介绍了gdistance中过渡函数的适当方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码是pdf手册中有关gdistance的过渡函数的示例:

The following code is an example for the transition function from the pdf manual for gdistance:

library(raster)
library(gdistance)

r <- raster(nrows=6, ncols=7, xmn=0, xmx=7, ymn=0, ymx=6, crs="+proj=utm +units=m")
r[] <- c(2, 2, 1, 1, 5, 5, 5,
         2, 2, 8, 8, 5, 2, 1,
         7, 1, 1, 8, 2, 2, 2,
         8, 7, 8, 8, 8, 8, 5,
         8, 8, 1, 1, 5, 3, 9,
         8, 1, 1, 2, 5, 3, 9)
T <- transition(r, function(x) 1/mean(x), 8)
# 1/mean: reciprocal to get permeability
T <- geoCorrection(T)
c1 <- c(5.5,1.5)
c2 <- c(1.5,5.5)
#make a SpatialLines object for visualization
sPath1 <- shortestPath(T, c1, c2, output="SpatialLines")
plot(r)
lines(sPath1)
#make a TransitionLayer for further calculations
sPath2 <- shortestPath(T, c1, c2)
plot(raster(sPath2))

我特别感兴趣的是这一行:

My specific interest is in this line:

T <- transition(r, function(x) 1/mean(x), 8)

因为我遇到了许多人在做以下事情:

Because I've come across numerous examples of people doing the following:

T <- transition(1/r, mean, 8)

据我所知,这是1/mean(x)mean(1/x)之间的区别,这是不相等的.

As far as I can tell, this is the difference between 1/mean(x) and mean(1/x), which are not equivalent.

为了验证这一点,我使用gdistance手册中的上述代码运行了两个版本的转移函数,并获得了两个截然不同的图:

To verify this, I ran both versions of the transition function using the above code from the gdistance manual, and got these two very different plots:

使用costDistance(T, c1, c2)时,第一个距离为21.1,第二个距离为13.6.

And using costDistance(T, c1, c2) I got a distance of 21.1 for the first, and 13.6 for the second.

显然,这些结果截然不同.因此,我的问题是,从成本矩阵/图层/栅格创建TransitionLayer对象的正确方法是什么?

Clearly, these are very different results. So, my question is, what is the correct method for creating a TransitionLayer object from a cost matrix/layer/raster?

推荐答案

这确实是一个重要的区别.有关更多信息,请参阅Wikipedia上有关 harmonic mean 的文章.

This is indeed an important difference. Take a look at the Wikipedia article on the harmonic mean for more info.

在此示例中,输入栅格中的值是成本.因此正确的方法是先取成本的算术平均值,然后取其倒数来获得电导.旅行者经历始发单元成本的一半,目的地单元成本的一半,(cost1 + cost2)/2.

In the example, the values in the input raster are costs. So the correct way is to take the arithmetic mean of the cost first and then take the reciprocal of that to get the conductance. The traveller experiences half of the cost of the origin cell and half of the cost of the destination cell, (cost1 + cost2)/2.

因此1/mean(x)在这种情况下是正确的.

So 1/mean(x) is correct for this case.

如果输入栅格具有电导值,则另一个函数正确:均值(1/x).

If the input raster has conductance values, the other function is correct: mean(1/x).

这篇关于gdistance中过渡函数的适当方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆