Opened 14 years ago

Closed 13 years ago

#1046 closed defect (fixed)

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., 12). 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 (7)

comment:1 by mwtoews, 14 years ago

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

comment:2 by pramsey, 14 years ago

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.

comment:3 by pramsey, 13 years ago

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…

comment:4 by pramsey, 13 years ago

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.

comment:5 by pramsey, 13 years ago

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...

comment:6 by pramsey, 13 years ago

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

comment:7 by pramsey, 13 years ago

Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.