Search code examples
djangogispolygonareageodjango

GeoDjango: Determine the area of a polygon


In my model I have a polygon field defined via

polygon = models.PolygonField(srid=4326, geography=True, null=True, blank=True)

When I want to determine the area of the polygon, I call

area_square_degrees = object.polygon.area

But how can I convert the result in square degrees into m2 with GeoDjango? This answer does not work, since area does not have a method sq_m. Is there any built-in conversion?


Solution

  • You need to transform your data to the correct spatial reference system.

    area_square_local_units = object.polygon.transform(srid, clone=False).area
    

    In the UK you might use the British National Grid SRID of 27700 which uses meters.

    area_square_meters = object.polygon.transform(27700, clone=False).area
    

    You may or may not want to clone the geometry depending on whether or not you need to do anything else with it in its untransformed state.

    Docs are here https://docs.djangoproject.com/en/1.8/ref/contrib/gis/geos/