0

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

  • 2
    The area is really zero in your first case, because (180, 0) and (-180, 0) are the same points! Your polygon is a line with no area! – Zoltan Sep 16 at 6:17
  • I think that 180 E and -180 E are not the same points when used as vertices of a polygon because that is the only way to cover the whole Earth. However, PostGIS geography does not support area calculations with such geographies. – user30184 Sep 16 at 8:36
2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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