Given a series of GPS coordinate pairs, I need to calculate the area of a polygon (n-gon). This is relatively small (not larger than 50,000 sqft). The geocodes are created
Adapted RiskyPathak's snippet to Ruby
def deg2rad(input)
input * Math::PI / 180.0
end
def polygone_area(coordinates)
return 0.0 unless coordinates.size > 2
area = 0.0
coor_p = coordinates.first
coordinates[1..-1].each{ |coor|
area += deg2rad(coor[1] - coor_p[1]) * (2 + Math.sin(deg2rad(coor_p[0])) + Math.sin(deg2rad(coor[0])))
coor_p = coor
}
(area * 6378137 * 6378137 / 2.0).abs # 6378137 Earth's radius in meters
end