Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point in polygon algorithm that handles polygons that straddle the antemeridian

Tags:

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.

like image 780
marxy Avatar asked Jul 24 '09 00:07

marxy


1 Answers

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.

like image 59
Reed Copsey Avatar answered Oct 05 '22 01:10

Reed Copsey