C#:如何确定坐标是否在美国大陆上? [英] C#: How to determine if a coordinates is in the continental United States?

查看:41
本文介绍了C#:如何确定坐标是否在美国大陆上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取坐标-纬度/经度,我想检查这些坐标是否在美国大陆上.有没有一种简单的方法可以在C#中做到这一点?我可以将坐标转换为MGRS或UTM.谢谢!

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!

推荐答案

哦,他们为您准备了它:

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.

现在,您有两个选择:

  • 使用数据为每个状态构建一个多边形,并与每个状态一起检查一个点.如果没有匹配项,则不在美国.

但是,这种方法存在问题-我不知道数据是如何收集的,但是状态之间的缝隙很小,甚至有很小的重叠都是有可能的.因此,如果您只关心它是否普遍在美国使用,我建议使用第二种方法:

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:

  • 使用数据为每个状态构建一个多边形,并使用一种算法将这些多边形组合为一个(例如并集).保存该多边形,然后将其与第一种方法一样使用.

这篇关于C#:如何确定坐标是否在美国大陆上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆