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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
demirev
  • 175
  • 1
  • 8

1 Answers1

0

Plot them both and you can see why:

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

enter image description here

They are quite different polygons.

Community
  • 1
  • 1
user2554330
  • 37,248
  • 4
  • 43
  • 90