Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 568
CMPE Avatar asked Apr 06 '15 04:04

CMPE


1 Answers

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.
like image 150
SimpleVar Avatar answered Oct 18 '22 04:10

SimpleVar