Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#5238 closed defect (wontfix)

ST_Area() does not always follow the winding order of coordinates in a Geography

Reported by: eldang Owned by: pramsey
Priority: medium Milestone: PostGIS 3.2.4
Component: postgis Version: 3.2.x
Keywords: Cc: eldang

Description

The area reported by ST_Area() for a Geography created from coordinates that span > 180 degrees of longitude falls short, with a pattern that suggests the polygon may be getting interpreted as going the wrong way around the globe.

Repro steps:

  1. SELECT ST_Area(ST_GeogFromText('SRID=4326;POLYGON((10 -89.9999, 180 -89.9999, 180 89.9999, 10 89.9999, 10 -89.9999))')) / 1000000;
  2. SELECT ST_Area(ST_GeogFromText('SRID=4326;POLYGON((0 -89.9999, 180 -89.9999, 180 89.9999, 0 89.9999, 0 -89.9999))')) / 1000000;
  3. SELECT ST_Area(ST_GeogFromText('SRID=4326;POLYGON((-10 -89.9999, 180 -89.9999, 180 89.9999, -10 89.9999, -10 -89.9999))')) / 1000000;

Expected behaviour:

  1. Returns approximately 170/360 of the area of the globe in sq km
  2. Returns approximately ½ of the area of the globe in sq km
  3. Returns approximately 190/360 of the area of the globe in sq km

Actual behaviour:

  1. 240864321.36968684 (as expected)
  2. 255032810.86204427 (as expected)
  3. Returns exactly the same as the first test

I have seen this in the wild with more complex polygons, which were getting suspiciously low areas returned. The above example is the simplest case I can reproduce it with. I do get the same behaviour if I offset the polygon to avoid the antimeridian (e.g. SELECT ST_Area(ST_GeogFromText('SRID=4326;POLYGON((-80 -89.9999, 90 -89.9999, 90 89.9999, -80 89.9999, -80 -89.9999))')) / 1000000; )

This does not affect multipolygons as long as each individual Polygon component spans < 180 degrees of longitude. As a result I do have a relatively straightforward workaround for my own use, of simply splitting polygons wider than that to calculate their area. But it is a very unexpected behaviour.

Change History (3)

comment:1 by eldang, 19 months ago

Milestone: PostGIS 3.3.1PostGIS 3.2.4

comment:2 by robe, 19 months ago

Resolution: wontfix
Status: newclosed

This is by design. geography doesn't care about winding order and always computes based on short-test edge. It does not support correctly calculate measures of geometries larger than a half-hemisphere as a result.

This is written in the FAQ - https://postgis.net/docs/using_postgis_dbmanagement.html#idm1655

in reply to:  2 comment:3 by eldang, 19 months ago

Replying to robe:

This is by design. geography doesn't care about winding order and always computes based on short-test edge. It does not support correctly calculate measures of geometries larger than a half-hemisphere as a result.

This is written in the FAQ - https://postgis.net/docs/using_postgis_dbmanagement.html#idm1655

Thank you, and I'm sorry I hadn't realised that.

Note: See TracTickets for help on using tickets.