作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
来自 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/
来自 this Question我获得了很棒的函数 areaPolygon(),它给出了坐标多边形内的面积。然而,当我试验该函数时,计算结果似乎很奇怪: 我首先创建一组两点 require(fiel
我是一名优秀的程序员,十分优秀!