3

In PostGIS, I would expect ST_Geography polygons to use a clockwise winding rule, i.e. everything to the right of the edges of the polygon is inside of the polygon.

Therefore, I expected a polygon going over the equator to the west to encompass the entire northern hemisphere, and a polygon going over the equator to the east to encompass the southern hemisphere.

This is not the case, though:

select st_covers(st_geogfromtext('polygon((0 0, -90 0, -180 0, 90 0, 0 0))'),
       st_geogfromtext('point(0 -5)'))

returns true, so the polygon going to the west contains a point on the southern hemisphere.

In fact, if I change the direction of the polygon to go to the east, it also contains points on the southern hemisphere, and I can't figure out how to make a polygon that contains points on the northern hemisphere.

So where is my misunderstanding, and how do I create a polygon that contains points on the northern hemisphere?

3 Answers 3

4

Do you have a reference about the winding order and its importance for building a geography object? By a test it does not seem to be so or otherwise one of these polygons would cover almost the whole Earth and have a huge area. In reality both winding orders make the same geography.

select st_area(st_geogfromtext('POLYGON (( 20 80, 20 60, 40 60, 20 80 ))'))
"1238730788505.16"

select st_area(st_geogfromtext('POLYGON (( 20 80, 40 60, 20 60, 20 80 ))'))
"1238730788505.16"

The documentation https://postgis.net/docs/using_postgis_dbmanagement.html#PostGIS_Geography says

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.

I feel that a polygon that follows the equator is not well defined because both ways are shorter - or longer. But this is something that I suggest to ask from the PostGIS developers through their mailing list.

3

I have the impression there is something wrong with the coordinates of your nothern hemisphere polygon. Try with 'polygon((-180 0, -180 90, 180 90, 180 0, -180 0))' maybe ?

1
  • That doesn't work: select st_covers(st_geogfromtext('polygon((-180 0, -180 90, 180 90, 180 0, -180 0))'), st_geogfromtext('point(0 5)')) returns false select st_covers(st_geogfromtext('polygon((-180 0, -180 90, 180 90, 180 0, -180 0))'), st_geogfromtext('point(0 -5)')) returns false as well.
    – Jeroen
    Commented May 19, 2020 at 8:54
0

PostGIS has the functions ST_ForcePolygonCW() and ST_ForcePolygonCCW(), but those are only for geometries, and neither is preferred over the other.

There is no winding rule. The inside of a polygon is the smaller part of the sphere's surface, which is undefined when both parts have the same size. You have to construct the hemisphere from multiple, smaller parts:

'MULTIPOLYGON(((0 0, -90 0, -180 0, 0 90, 0 0)), ((0 0, 90 0, 180 0, 0 90, 0 0)))'

Your Answer

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

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