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).
creating geography(not geometry) table:
CREATE TABLE mypoly (
id SERIAL PRIMARY KEY,
name VARCHAR(64),
the_geom GEOGRAPHY(POINT,4326)
);
hereafter is that using psycopg2 for reaching postgis table and querying some sql with ST_Area.
ST_Area — Returns the area of the surface if it is a polygon or
multi-polygon. For "geometry" type area is in SRID units. For
"geography" area is in square meters.
in your view.py, write this code:
import psycopg2
def getGeodesicArea:
res = []
con = psycopg2.connect("dbname='mydb' user='reid' host='127.0.0.1' password='reid'")
cur = con.cursor()
cur.execute("SELECT ST_Area(the_geom) FROM mypoly")
rows = cur.fetchall()
for row in rows:
respre = row[2] # find your result.
res.append(respre)
con.commit()
cur.close()
con.close()
if you are searching a pythonic way for fetching your result as json, check out this SO answer.
UPDATE
There is a javascript code in openlayers api for calculating geodetic areas. i think you can convert it to python for django application.
getGeodesicArea: function(projection) {
var ring = this; // so we can work with a clone if needed
if(projection) {
var gg = new OpenLayers.Projection("EPSG:4326");
if(!gg.equals(projection)) {
ring = this.clone().transform(projection, gg);
}
}
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;
}
return area;
}
i hope it helps you...