gpt4 book ai didi

r - 了解包 geosphere 中 `areaPolygon()` 的输出

转载 作者:行者123 更新时间:2023-12-04 11:17:16 25 4
gpt4 key购买 nike

来自 this Question我获得了很棒的函数 areaPolygon(),它给出了坐标多边形内的面积。然而,当我试验该函数时,计算结果似乎很奇怪:

我首先创建一组两点

 require(fields)
coords <- c(11.3697193956209, 47.233380520521, 11.3723606043791,
47.235179479479)
coords <- matrix(coords, nrow=2, ncol=2, byrow=TRUE)

然后我检查这两者之间的距离:

 rdist.earth(coords,coords,miles=FALSE)[1,2]

得到:0.2827821公里(这将是矩形的对角线)

我继续创建一个矩形

 polygon <- matrix(coords, nrow=2, ncol=2)
polygon <- rbind(polygon, polygon)
polygon[4,2] <- polygon[1,2]
polygon[4,1] <- polygon[2,1]
polygon[3,2] <- polygon[2,2]
polygon[3,1] <- polygon[1,1]
polygon <- rbind(polygon, polygon[1,])

看看这看起来是否不错:plot(polygon)

第四步:我计算多边形内的面积。

geosphere::areaPolygon(polygon)
[1] 31.99288 #from the help file I know this ought to be square metres.

但是,我预计 200*200=40000 m²,因为我的 recangle 的边长是 200 x 200 米。这可以通过检查

rdist.earth(polygon,coords,miles=FALSE)

[,1] [,2]
[1,] 0.0000000 2.827821e-01
[2,] 0.2827821 9.504539e-05
[3,] 0.2002671 1.996434e-01
[4,] 0.1996501 2.002671e-01

所以现在(终于)我的问题来了,我做错了什么?非常感谢您的帮助!

最佳答案

您创建了一个无效的多边形!如果你用 type="l" 绘制它,你会看到一个领结:

> plot(polygon,type="l")

领结的一半面积为负,另一半面积为正,因此您的结果是两半面积的差异。它们不会完全相同,因为地球是球形的...

您只需要在polygon 中重新排序您的点。

关于r - 了解包 geosphere 中 `areaPolygon()` 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12635761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com