Search code examples
pythondjangogispostgisgeodjango

Geodjango + PostGIS. Aggregate polygon area in square meters


I am using geodjango(3.1) + postgis and I want to receive the area of a polygon in square meteres. Therefore, I am using the Geographic Database Functions of Django.

My code looks the following:

City.objects.annotate(area=Area('geom'))

I think the result I am reciving is in degree. When I use the distance function the same way, I get the right result in square meters.

When I am executing ST_Area(geom, use_spheroid=true) as RawSQL, the result also fits and is in square meteres but I would like the avoid RawSQL.

Thanks for any help =)


Solution

  • This worked for me:

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