0

I am trying to calculate the area of a polygon defined in terms of latitude and longitude:

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

using the function areaPolygon from the geosphere package:

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

However, I have noticed that if I reorder the points in the polygon I get a different result:

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

My question is what is the reason for this disparity in the results (the function documentation does not mention that ordering matters)? Is there a correct way to order the points in a polygon, and what is it?

4

1 回答 1

0

把它们都画出来,你就会明白为什么:

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

在此处输入图像描述

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

于 2019-11-10T13:45:45.387 回答