Detect if geolocation is in complex polygon or not

Spheric coordinate system has it quirks

To avoid them use 3D orthogonal/orthonormal cartesian coordinate system instead

  1. convert your polygon vertexes and geolocation

    so (long,lat,alt) -> (x,y,z). here you find how to do it. You do not need to apply local transform just the first spheric to 3D cartesian transformation (bullet #1.)

  2. use any inside polygon test …

    I usually count the number of intersections between line cast from your geolocation to any direction and polygon boundary lines.

    • if it is odd then point is inside
    • if it is even then the point is outside
    • if point lies on any line of polygon then it is inside
    • if your casted line hits any vertex then either take in mind (do not count multiple hits at this vertex) or change the direction a bit and try again

    is point inside polygon?

[Notes]

Do not forget to handle all as 3D vectors not 2D !!!

Leave a Comment