geosphere::areaPolygon returns 基于顶点排序的不同结果

geosphere::areaPolygon returns different results based on ordering of vertices

我正在尝试计算根据纬度和经度定义的多边形的面积:

example_polygon <- data.frame(
  lat = c(42.7093213,42.7079761,42.7093941,42.7080938,42.7093213), 
  lon = c(23.3194939,23.3194379,23.3194379,23.3182881,23.3194939)
) # last point equals first point

使用 geosphere 包中的函数 areaPolygon

geosphere::areaPolygon(cbind(example_polygon$lon, example_polygon$lat))
[1] 350.9063

但是,我注意到如果我对多边形中的点重新排序,我会得到不同的结果:

example_scrambled <- example_polygon[c(2,1,3,4,2),]
geosphere::areaPolygon(cbind(example_scrambled$lon, example_scrambled$lat))
[1] 7780.469

我的问题是造成这种结果差异的原因是什么(函数文档没有提到排序很重要)?是否有正确的方法来对多边形中的点进行排序,它是什么?

绘制它们,你就会明白为什么:

par(mfrow=c(1,2))
plot(example_polygon, type = "l")
plot(example_scrambled, type = "l")

它们是完全不同的多边形。