Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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"
share|improve this question

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
That's it! Thank you! Apart from that the projections have to be 900913 and 31467: 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))',900913),31467)) As sqm; –  Mark Dec 29 '12 at 21:06
ST_Transform(geometry,target_CRS) 

is the correct syntax. You seem to have mixed up some commas.

share|improve this answer

Both queries define the SRID for the polygon as 4326, but based on the data this is surely not the case. SRID 4326 (WGS84) is limited to the range [-90,90] for latitude and [-180,180] for longitude.

If you have polygon data in 4326, then using the ST_GeogFromText may be a better approach. This assumes that your data are in 4326, and measurements on geography features will be in meters.

A working query follows:

SELECT
ST_Area(
ST_Transform(
ST_SetSRID(
ST_GeomFromText(
'POLYGON((-98.4854749658124 29.3495134003054,-97.4374094977531 29.4150174920591,-97.2408972224919 28.4979602075071,-98.354466782305 28.4324561157534,-98.4854749658124 29.3495134003054))'
)
, 4326)
, 900913)
)

I transformed to 900913 instead of 31467 because that SRID doesn't cover my example data's area.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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