How can I measure area from geographic coordinates?

Here's a link to some code that'll yield the area of a simple polygon (originally from the World Wind Forum): http://forum.worldwindcentral.com/showthread.php?t=20724. This solves the problem on a sphere, roughly based on the relationship:

alt text

S = area of polygon; theta is the sum of interior angles in radians; n is the number of vertices; r is the radius of the sphere.

See also (source of formula image): http://www.geom.uiuc.edu/docs/reference/CRC-formulas/node59.html

I would be delighted to see links and/or code for polygon area on an oblate spheroid.


PostGIS 1.5 introduced a new GEOGRAPHY type. The GEOGRAPHY type allows for unprojected coordinates on a spheroid to be stored in a PostGIS table, and some analysis functions to be performed upon them.

ST_Area queries can be performed upon GEOGRAPHY type polygons in order to calculate their area in square meters.

The following query outputs the area of all polygons using the spheroid (currently only the WGS-84 spheroid is supported), assuming they are stored using the GEOGRAPHY type:

SELECT ST_Area(the_geom) FROM table_of_polygons;

The algorithm used to calculate area on a spheroid can be derived from the source-code.


Here's the source for the simplified calculation that we make in OpenLayers. This method comes from "Some Algorithms for Polygons on a Sphere" (Robert. G. Chamberlain and William H. Duquette, NASA JPL Publication 07-03). The code linked to above is for determining the area of a linear ring (with geographic coordinates). Areas for Polygons and MultiPolygons are summed up from the rings.

var area = 0.0;
var len = ring.components && ring.components.length;
if (len > 2) {
    var p1, p2;
    for (var i=0; i<len-1; i++) {
        p1 = ring.components[i];
        p2 = ring.components[i+1];
        area += OpenLayers.Util.rad(p2.x - p1.x) *
            (2 + Math.sin(OpenLayers.Util.rad(p1.y)) +
            Math.sin(OpenLayers.Util.rad(p2.y)));
    }
    area = area * 6378137.0 * 6378137.0 / 2.0;
}

Ring components are two element arrays of x, y (lon, lat) coords in the above code. The OpenLayers.Util.rad method just converts degrees to radians (deg * PI / 180).