Skip to content

Instantly share code, notes, and snippets.

@selimnairb
Created December 29, 2014 17:05
Show Gist options
  • Save selimnairb/1e25fee5a19ca5fe62f2 to your computer and use it in GitHub Desktop.
Save selimnairb/1e25fee5a19ca5fe62f2 to your computer and use it in GitHub Desktop.
Calculate the area of a geodesic polygon defined by WGS84 coordinates using Python version of GeographicLib
# See http://geographiclib.sourceforge.net for more information
from geographiclib.polygonarea import PolygonArea
from geographiclib.geodesic import Geodesic
coords = [(-81.684594, 35.725673),
(-80.059151, 35.725673),
(-80.059151, 36.689994),
(-81.684594, 36.689994)]
polyArea = PolygonArea(Geodesic.WGS84, False)
for coord in coords:
polyArea.AddPoint(coord[1], coord[0])
result = polyArea.Compute(False, False)
print("GeographicLib area {0:.2f}-km2".format(result[2]/1000/1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment