问题
I am getting coordinates - lat/lon and I want to check if these coordinates are in the continental United States or not. Is there a easy way to do it in C#? I can convert the coordinates into MGRS or UTM. Thanks!
回答1:
Oh wow, they have it just for you:
http://econym.org.uk/gmap/states.xml
All the coords of the US states! Build up a polygon and apply any polygon-contains-point algorithm.
The classic algorithm is ray-casting, and its even pretty simple. Let me know if you have any trouble with it.
Now, you have two options:
- Use the data to build a polygon for each state, and check a point with each one of them. If none match, it is not in the US.
However, there is a problem with that approach - I don't know how the data was gathered, but its possible that there are very little gaps between states, or even slight overlaps. So if you only care if its generally in the US or not, I suggest the second approach:
- Use the data to build a polygon for each state, and an algorithm to combine those polygons to one (like union). Save that polygon and use that as with the 1st approach.
来源:https://stackoverflow.com/questions/29465345/c-how-to-determine-if-a-coordinates-is-in-the-continental-united-states