Check if a point exists in a given area containing 4 vertices

referring to http://www.weather.gov/directives/sym/pd01008006curr.pdf , page 8, we are provided with an area with four vertices in the geographical coordinate system (lat and long system), I want to check if there is a point with specific lat and long in this area.

+5
java geometry
source share
5 answers

The way to check whether a point is inside an arbitrary polygon (any number of sides, concave is also valid) is to choose a point that, as you know, is outside the polygon; if the line segment between the test point and a point outside the polygon intersects the ODD number of the polygon segments, the point is inside the polygon.

+6
source share

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.

+3
source share

Do you mean programmatically or mathematically? Programmatically easy if you understand it mathematically. Mostly the vertices define the lines. You just need to know which side of the lines is "inside." Then return your vertices to the equations, but use them less or more than equal.

Id est, suppose you have a rectangle defined by the following equations: x = 1, x = 3, y = 1, y = 3

If you want to know if (2,2) is inside this area, simply evaluate each equation: x> 1, x <3, y> 1, y <3.

If all four are true, the point is inside the area.

+1
source share

The method proposed by D. Patrick only works for rectangles (obviously)
In special circumstances:
The line segment intersection method is good if you donโ€™t need to worry about the computation time that is actually detected inside or outside. If you need quick searches and you have enough memory, you can always create a table with points inside or outside, and then perform a search that should be faster

-2
source share

All Articles