3

I have a table with polygons in EPSG 4326. These polygons are distributed all over the world, for example:

POLYGON((10.7324632658845 59.9253049236956,10.7331908150806 59.9244876816042,10.7342435821189 59.9247242537529,10.7335237442742 59.9255414900176,10.7324632658845 59.9253049236956))

Now I'd like to get the areas of these polygons in square meters. With ST_Area(the_geom) I get the area in square degrees, right? So I have to do something with ST_Transform. I got a good result for the above mentioned polygon with the following transformation:

ST_AREA(ST_Transform(ST_GeomFromText(the_geom,4326),31467))

However, the calculation (of course) fails when calculating the area of a polygon outside of the coverage of EPSG 31467 (Fatal error...).

Is there a "universal" area accurate projection for this purpose? Or do I have to check the location of every polygon and individually apply a suitable projection to calculate its area properly?

1 Answer 1

3

As alluded to in this previous answer, the ST_GeogFromText method will create a geography data type. This method expects your input data to be in 4326 (a geographic coordinate system) and measurements on this type are in meters. This will work world-wide. Here's an example:

SELECT
ST_Area(
    ST_GeogFromText(
        'POLYGON((10.7324632658845 59.9253049236956,10.7331908150806 59.9244876816042,10.7342435821189 59.9247242537529,10.7335237442742 59.9255414900176,10.7324632658845 59.9253049236956))'
    )
)

The 31467 projection uses a projected coordinate system that is only defined for a portion of Germany (and small parts of France, Austria and Switzerland). That's why you get an error when transforming data from another region into this projection (of course!).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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