Point in polygon algorithm that handles polygons that straddle the antemeridian

geospatial

I have a database of polygon points as latitude, longitude pairs and I need to test if a given lat,lng point is inside any of the polygons.

There are several algorithms around including these but they don't work if the polygon straddles the antemeridian (off the coast of New Zealand, where longitude flips from +180 degrees East to -180 degrees West).

One solution I see is to detect if the polygon straddles the antemeridian and if so split it into two polygons, one on each side, then check each of them.

Best Answer

The other (simpler) option, IMO, is to just test for that special case, and if it exists, apply a transform to your query point and the polygon. For example, if it spans the anti-meridian, just translate everything by a specific longitude amount to make it not span the meridian, and do your standard test.

Related Topic