Ticket #1046 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Invalid geography polygons: BOOM! Could not generate outside point!

Reported by: mwtoews Owned by: pramsey
Priority: medium Milestone: PostGIS 2.0.0
Component: postgis Version: 1.5.X
Keywords: geography boom Cc:

Description

I've seen a few "BOOM" errors over the past few months (e.g.,  1 2). For example, with PostGIS SVN r7443:

SELECT ST_Intersects('POINT(160 43)'::geography, 'POLYGON((0 0, 0 90, 180 90, 180 0, 0 0))'::geography);

SELECT ST_Area('POLYGON((0 0, 0 90, 180 90, 180 0, 0 0))'::geography);

The error comes from liblwgeom/lwgeodetic.c, with the famous last words [comments] "This should never happen".

Note, the above geography polygon does not make any sense to the  Great Circle Mapper. I can think up many more invalid geography polygons that produce the same "BOOM" error.

Change History

Changed 3 years ago by mwtoews

Probably related to #799 (I can't figure out how to apply that patch test if it resolves this issue)

Changed 3 years ago by pramsey

No, it is a different issue. The point-in-polygon test in geography involves generating a point that is definitively outside the area, then counting the number of times the boundary intersects with the maybe-inside point. As you can imagine, the weakness is being to generate a point that is definitively outside of an arbitrary area on the sphere.

This is more computational geometry and the work of ages.

Changed 3 years ago by pramsey

Actually as a general rule and 180 degree edge is going to be pointless in geography... maybe we should just outlaw those to start with? See, funny story, you looked at your polygon and said "that's meaningless" and I looked at it and said "that's an orange wedge". But really since a 180 degree edge can traverse any path at all from start to end it's not really descriptive and should be banned...

Changed 3 years ago by pramsey

And looking at the code we get the usual validity conundrum... checking for validity costs CPU time, how often do we want to do it... we'd have to convert each vertex pair to geocentrics (expensive), then calculate the dot product (cheap) to see if they were antipodal.

Changed 3 years ago by pramsey

What would you think of these results?

postgis20=# SELECT ST_Area('POLYGON((0 0, 0 90, 180 90, 180 0, 0 0))'::geography);
ERROR:  Invalid geography. Antipodal edge (180 degrees long) detected. (180 0,0 0)
LINE 1: SELECT ST_Area('POLYGON((0 0, 0 90, 180 90, 180 0, 0 0))'::g...
                       ^
postgis20=# SELECT ST_Intersects('POINT(160 43)'::geography, 'POLYGON((0 0, 0 90, 180 90, 180 0, 0 0))'::geography);
ERROR:  Invalid geography. Antipodal edge (180 degrees long) detected. (180 0,0 0)
LINE 1: SELECT ST_Intersects('POINT(160 43)'::geography, 'POLYGON((0...

Changed 3 years ago by pramsey

Further data point, SQL Server does not allow antipodal edges.

Changed 3 years ago by pramsey

  • status changed from new to closed
  • resolution set to fixed

The still go Boom, just with a more useful error message. Trunk at r9127.

Note: See TracTickets for help on using tickets.