TransWikia.com

PostGIS ST_Area unexpectedly returns 0

Geographic Information Systems Asked by strixcuriosus on November 26, 2020

Can someone help me understand why the following ST_Area query returns 0:

SELECT ST_Area(ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-180.0,0],[180,0],[180,80],[-180,80],[-180,0]]]}'), 4326)::geography);
 st_area
---------
       0
(1 row)

but changing the coordinates slightly gives a reasonably large looking value for area.

af=> SELECT ST_Area(ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-179.99,0.01],[179.99,0.01],[179.99,79.99],[-179.99,79.99],[-179.99,0.01]]]}'), 4326)::geography);
     st_area
------------------
 13948451441.7438

For reference, this is my PostGIS version

SELECT PostGIS_Version();
            postgis_version
---------------------------------------
 2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

Follow up question: why are these areas different than the ones I see on geojson.io? Do I have a the wrong CRS or some other problem?

The docs say "by default area is determined on a spheroid with units in square meters" https://postgis.net/docs/ST_Area.html

If I put the same coordinates into geojson.io as feature collections, I see the following areas:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[-180,0],[180,0],[180,80],[-180,80],[-180,0]]]
      }
    }
  ]
}

gives an area of 251720748408616.50 Sq. Meters

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[-179.99,0.01],[179.99,0.01],[179.99,79.99],[-179.99,79.99],[-179.99,0.01]]]
      }
    }
  ]
}

gives an area of 251654405021681.66 Sq. Meters

One Answer

You can't calculate the areas of geography polygons which wrap the whole Earth with PostGIS. Read https://postgis.net/docs/using_postgis_dbmanagement.html#PostGIS_Geography

4.2.3.3.

What is the longest arc you can process?

We use great circle arcs as the "interpolation line" between two points. That means any two points are actually joined up two ways, depending on which direction you travel along the great circle. All our code assumes that the points are joined by the shorter of the two paths along the great circle. As a consequence, shapes that have arcs of more than 180 degrees will not be correctly modelled.

The reasonable looking value 13948451441.7438 that PostGIS gives you is unfortunately wrong as you can estimate by knowing that the area of Earth is about 510 million square kilometers and your polygon covers almost half of it.

Answered by user30184 on November 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP