Saturday, 9 July 2016

postgis - Calculating area of an EPSG:4326 Polygon




Possible Duplicate:

What is the most accurate coordinate system for calculating areas of polygons?



In our Postgres/Postgis database we store polygons in a column defined as lonlat/EPSG:4326, as it may contain data from anywhere in the world.


We have a requirement to calculate the surface area (i.e. in square meters or hectares). The method ST_Area can perform the calculation but returns the answer in the used coordinate systems units. That is, it returns the area as what I believe is "square degrees". As the size of a degree is variable depending on the location in the world, this does not make much sense.


One solution is to transform (ST_Transform) the polygon to another crs before calculating the area, perhaps the appropriate UTM32 zone, but that will require us to dynamically determine the zone first. Alternatively we could always transform to the Google Mercator (EPSG:900913), but we fear for the precision.


Any inputs?



Answer



I found a function to return the UTM zone for any point on the PostGIS wiki: utmzone()


Using that you could do:


SELECT

ST_Area(
ST_Transform(the_geom, utmzone(ST_Centroid(the_geom))
))
FROM polygons
WHERE...

HTH, Micha


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...