my geom has //

When I am trying to get the area of the polygon

 geom.area   //7.27640644096346e-08

How to get these value in feets. I don't know what is the units of these value

I am trying to get these value in meters by geom.area.sq_m but it throws the error "'float' object has no attribute 'sq_m'"

Can any help me to get it done


In this case the best is use annotations. If your model looks similar to:

class Country(gismodels.Model):
    name = models.TextField()
    geom = gismodels.PolygonField(srid=4326, geography=True)

Then when you get your models you can use Area function to get it annotated to your model like that:

from django.contrib.gis.db.models.functions import Area


spain = Country.objects.filter(name='Spain').annotate(area=Area('geom'))

And you will get a model with an extra area property of Area type that you can convert to any unit (even for your not metric units) by typing:

# But better use metric system :D

The area value returned when using the geom.area function depends on the spatial reference that your geometry is in.

From the output you show, my guess is that your geometry could be in WGS84 (SRID 4326). In that case the area does not make much sense, as its not a projected coordinate system.

Ideally you would use a coordinate system that is adequate for your area. For instance, you could use the India NSF LCC projection (srid 7755). It has the units of metre, so the area returned would be in square meters.

Here is an example that illustrates the dependency of the are from the coordinate system:

>>> from django.contrib.gis.gdal import OGRGeometry
>>> geom = OGRGeometry('SRID=4326;POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')
>>> geom.area
... 550.0
>>> geom.transform(7755)  # Projection adequate for India region
>>> geom.area
... 5771201025097.617
>>> geom.transform(3857)  # Mercator projection used by most web-maps
>>> geom.area
... 7700007175103.774

A great webiste to explore or find projections is http://epsg.io .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.