C#: How to determine if a coordinates is in the continental United States?

回眸只為那壹抹淺笑 提交于 2021-02-07 14:25:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!