I have some polygons which can be anywhere in the world. I would like to compute their areas.

The GeoDjango docs for GEOSGeometry.area don't specify whether it is geometric or geodesic area, but given that GEOSGeometry.distance() says that "GEOS does not perform a spherical calculation even if the SRID specifies a geographic coordinate system", I suspect that it is a simple geometric area.

I'm willing to write a little code, but the shorter the better, of course.

4 Answers
4

if you use PostGIS Geography Type for your table, you can calculate your area as you calculate on the plane surface.

The geography type provides native support for spatial features
represented on "geographic" coordinates (sometimes called "geodetic"
coordinates, or "lat/lon", or "lon/lat"). Geographic coordinates are
spherical coordinates expressed in angular units (degrees).

Sadly, there's no PostGIS in the system. The polygons are computed in Python and we need the areas without a database roundtrip.
–
ReidNov 14 '12 at 16:11

check out my answer, i have updated it with a javascript code.
–
AragonNov 14 '12 at 16:16

Can you summarize the algorithm that JavaScript code is using? For example is it doing the standard area-of-a-polygon computation with (non-ellipsoidal) geodetic distances between the points? Concise explanations of the principles are a lot more helpful to me than lengthy code to wade through....
–
ReidNov 14 '12 at 16:25

it calculates the approximate area of the polygon were it projected onto the earth. it is referenced here and more information about Some Algorithms for Polygons on a Sphere here...
–
AragonNov 14 '12 at 16:28