Monday 19 October 2015

postgis - How do I get the area of a WGS84 polygon in square meters?


The following gives me the area of the polygon in square degrees:


SELECT ST_Area(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',4326)) As sqm;

Result: 16586.2319335938



How do I get the area in square meters? I tried the following:


SELECT ST_Area(ST_Transform(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',4326)),31467) As sqm;

But it seems like ST_Transform doesn't work. I get the following error message:


ERROR:  function st_transform(geometry) does not exist
LINE 1: SELECT ST_Area(ST_Transform(ST_GeomFromText('POLYGON((871325...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function st_transform(geometry) does not exist

SQL Status:42883
Hint:No function matches the given name and argument types. You might need to add explicit type casts.

Missing Proj support shouldn't be the problem, with SELECT PostGIS_full_version() I get


"POSTGIS="1.5.3" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.8.0, 6 March 2012" LIBXML="2.8.0" USE_STATS"

Answer



You have a closing paren in the wrong place towards the end of your query. I tried this and got a NaN return,


SELECT ST_AREA(ST_Transform(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',4326),31467)) As sqm;

The NaN result is due to the polygon being outside the limits of your projection.



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...