Determining the area in m2 of a polygon

1,018 views
Skip to first unread message

Hannes

unread,
Nov 11, 2013, 7:49:33 AM11/11/13
to geod...@googlegroups.com

Hi GeoDjango, 

I am struggling with a simple problem, but I can't find a solution (via google or stackoverflow). I am hoping someone of the GeoDjango group knows the answer.

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, sincearea does not have a method sq_m. Is there any built-in conversion available in GeoDjango?

Thank your for your reply!

Best regards, 
Hannes

jabrane

unread,
Nov 11, 2013, 1:44:25 PM11/11/13
to geod...@googlegroups.com
why do you choose the wgs84?
instead you could try with a metric srid then the aerea would be in m2 


--
You received this message because you are subscribed to the Google Groups "geodjango" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geodjango+...@googlegroups.com.
To post to this group, send email to geod...@googlegroups.com.
Visit this group at http://groups.google.com/group/geodjango.
For more options, visit https://groups.google.com/groups/opt_out.



--
jabrane%

jabrane

unread,
Nov 11, 2013, 1:47:29 PM11/11/13
to geod...@googlegroups.com

Hannes

unread,
Nov 11, 2013, 6:26:46 PM11/11/13
to geod...@googlegroups.com
Do you know an appropriate srid for the metric system?

Thank you for your reply!

Max Demars

unread,
Nov 12, 2013, 8:38:18 AM11/12/13
to geod...@googlegroups.com
3857 is the most common. Web Mercator.

Hannes

unread,
Nov 13, 2013, 5:30:36 AM11/13/13
to geod...@googlegroups.com
Hi Max, 

Thank you for your reply.

I have implemented the conversion to 3857, save the area size and convert back to 4326, since the coordinates are stored in degrees.

        object.polygon.transform(3857)
        object.polygon_size = object.polygon.area
        object.polygon.transform(4326)

It seems non-pythonic to convert twice but it works for now.
Do you know how resource intense the conversion is?

Max Demars

unread,
Nov 13, 2013, 8:19:40 AM11/13/13
to geod...@googlegroups.com
Hi Hannes,

It's true that transforming data twice is not ideal. What is your database backend? If you use PostGIS 1.5 or newer, with geography=True it should return distance in meters. Perhaps you can try spheroid=True instead of geography=True. see: https://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/#geography


--
You received this message because you are subscribed to a topic in the Google Groups "geodjango" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/geodjango/6NkzCV5bZrc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to geodjango+...@googlegroups.com.

Max Demars

unread,
Nov 13, 2013, 8:44:43 AM11/13/13
to geod...@googlegroups.com
Other solution would be to translate degree to meters, with a custom python method instead of transforming the data.

jabrane

unread,
Nov 13, 2013, 2:43:52 PM11/13/13
to geod...@googlegroups.com
I can suggest google epsg 90013
as I know geodjango works with openlayers so you can calculate aerea
with srid 90013 ( use on-the-fly reproection or coordinate conversion)

good luck
>>>>>>> degrees<http://en.wikipedia.org/wiki/Square_degree> into
>>>>>>> m2 with GeoDjango? This
>>>>>>> answer<http://gis.stackexchange.com/questions/9673/area-units-for-geos-area-property>
Reply all
Reply to author
Forward
0 new messages