[Answered ]-Geodjango + PostGIS. Aggregate polygon area in square meters

0👍

This worked for me:

City.objects.annotate(area=RawSQL("ST_AREA(geom, true)", []))

1👍

Note that if you store your geom field as a geography type, the Area function should return square meters instead of degrees.

from django.contrib.gis.db import models as gis_models

class City(gis_models.Model):
    geom = gis_models.PolygonField(geography=True)

…
cities = City.objects.annotate(area=Area('geom'))
cities[0].area.sq_m  # square meters

Leave a comment