Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#4832 closed defect (fixed)

St_intersects on geography crossing equator

Reported by: mschott Owned by: pramsey
Priority: medium Milestone: PostGIS 3.1.2
Component: postgis Version: 3.0.x
Keywords: st_intersects, hemisphere Cc:

Description

Dear community,

checking St_intersects on a geography Polygon crossing the equator returns a false negative. Issues with geographies crossing the equator are mentioned in the FAQs: https://postgis.net/docs/manual-3.0/PostGIS_FAQ.html#idm1295 but only in reference to a different software. The linked specialised page on geography then fails to mention the topic, so I guess this is a request for a documentation update. I nevertheless include the code to reproduce the issue here:

with sa as (
    select
        'SRID=4326;POLYGON ((-53.37909456943908 -33.74067597231424, -73.29279537699995 -53.165704033999916, -77.73721269399991 8.13031647300005, -117.12512148894415 32.53166949000396, -35.403797980999904 -5.226495049999925, -53.37909456943908 -33.74067597231424))'::geometry as geom,
        'SRID=4326;POINT (-67.70339406180045 -4.483407006023738)'::geometry as point)
select
    geom,
    point,
    st_intersection(geom,
        point) as intersectionGeom,
    st_intersection(geom::geography,
        point::geography) as intersectionGeog,
    st_intersects(point,
        geom) as geomgeom,
    st_intersects(point,
        geom::geography) as geomgeog,
    st_intersects(point::geography,
        geom) as geoggeom,
    st_intersects(point::geography,
        geom::geography) as geoggeog
from
    sa;

I would expect TRUE for all four intersects-tests but three return FALSE. What puzzeled me was the fact that st_intersection works just fine.

Tanks

Mo

Change History (5)

comment:1 by mschott, 4 years ago

PS: I checked that the behaviour presented in the example is not due to greographies working on the great circle, but one might want to double check.

If st_intersects is not working with elements crossing the equator, it might be better to throw an error or return null instead of a false 'FALSE'.

comment:2 by pramsey, 4 years ago

Milestone: PostGIS 3.1.1PostGIS 3.1.2

comment:3 by pramsey, 4 years ago

So, this works in 3.1 and master, but is broken in 3.0. So easy fix is upgrade :) I'll need to figure what change fixed this by accident.

(ST_Intersection isn't a real geodetic calculation, it's just a transform to a planar approximation and then a calculation, so it "worked" only insofar as it dodged whatever geodetic bug tripped up the geodetics. The final three are actually all the same test, as it seems the default casting of st_intersects(geography, geometry) is to the geography/geography variant.)

Last edited 4 years ago by pramsey (previous) (diff)

comment:4 by pramsey, 4 years ago

Resolution: fixed
Status: newclosed

Yep, this was fixed, and you have a release of 3.0 that predates the fix, so you need up grade to 3.0.3 or to the 3.1 series. Fix was here https://github.com/postgis/postgis/commit/9a9241ce747b3ad1fbeacd899310fac91dfd418b

comment:5 by mschott, 4 years ago

great, already upgraded. thank you and keep up the good work!

Note: See TracTickets for help on using tickets.