This is a point-in-polygon problem in a sphere with a coordinate system, which has several subtleties that make it more difficult than the "regular" point-in-polygon task in the XY plane:
1) what is inside and out? (for example, if I have a small "square" 1 mile on the side, does it cover 1 square mile or the rest of the earth? This is a trivial example, but for very large polygons it may not be clear what should be inside and which should be outside, unless stated explicitly)
2) - segments of polyhedral segments of polygons? If so, then they do not represent straight lines in a coordinate system with a long length, unless they are meridional lines or the equator - and you need to deal with curves, not with lines in your geometry. Spherical geometry is the way to go.
3) "edges" of the coordinate system (international date and pole line) - a "square" limited by longitudes + 179.9 degrees, -179.9 degrees, and latitudes + 0.1 ยฐ, -0.1 ยฐ not usually considered, that it contains the point 0 N, 0 W and it is believed that it contains the point 0 N, 180 W. But if you naively check inequalities with lat / long points, you will get the opposite answer.
So, I have no answer, but these are subtle issues to consider. (read this as โmake sure you include them as test casesโ!)
edit: I found a spheres package that has the SphericalPolygon.contains method that can do what you are looking for. However, I personally did not use this package, but the GPL , not the LGPL, so it will "pollute" the rest of your source if you want to use it in a proprietary product.
Jason s
source share