邮政编码半径搜索
我想知道是否可以通过经度和纬度找到一个点的X半径内的所有点?
那么,如果我提供 -76.0000, 38.0000 的纬度/经度,是否可以简单地找到(例如)10 英里半径内的所有可能坐标?
我知道有一种方法可以计算两点之间的距离,这就是为什么我不清楚这是否可能。因为,您似乎需要知道中心坐标(在本例中为 -76 和 38)以及每个其他点的坐标,以便确定它是否落在指定的半径内。是这样吗?
I'm wondering if it's possible to find all points by longitude and latitude within X radius of one point?
So, if I provide a latitude/longitude of -76.0000, 38.0000, is it possible to simply find all the possible coordinates within (for example) a 10 mile radius of that?
I know that there's a way to calculate the distance between two points, which is why I'm not clear as to whether this is possible. Because, it seems like you need to know the center coordinates (-76 and 38 in this case) as well as the coordinates of every other point in order to determine whether it falls within the specified radius. Is that right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
@David 的策略是正确的,但他的实施存在严重缺陷。我建议在执行计算之前,将经纬度对转换为 UTM 坐标,并使用距离(而不是角度)测量值进行工作。如果您不熟悉通用横轴墨卡托,请点击谷歌或维基百科。
我认为你的点(-76,38)位于UTM 37C 472995(东)1564346(北)。所以你想要计算距该点的距离。您会发现使用 UTM 以米为单位更容易,因此您的距离(如果您使用的是 5280 英尺的法定英里)为 16040 米。
顺便说一句,(-76,38) 远远超出了美国大陆——美国邮局是否定义了南极洲的邮政编码?
@David's strategy is correct, his implementation is seriously flawed. I suggest that before you perform the calculations you transform your lat,long pair to UTM coordinates and work in distance, not angular, measurements. If you are not familiar with Universal Transverse Mercator, hit Google or Wikipedia.
I reckon that your point (-76,38) is at UTM 37C 472995 (Easting) 1564346 (Northing). So you want to do your calculations of distance from that point. You'll find it easier, working with UTM, to work in metres, so your distance is (if you are using statute miles of 5280 feet) 16040 metres.
Incidentally, (-76,38) is well outside the contintental US -- does the US Post Office define zip codes for Antarctica ?
如果你接受地球是一个完美的球体,你可以通过
现在获得一个点的空间坐标,取两个点并计算它们与地球中心形成的角度(使用点积):(
R的值得到简化)。
在您的情况下,角距离 Phi 等于 2Pi.D/R。 (R=6 378.1 公里)。
当点积大于 cos(Phi) 时,点 P" 位于 P' 的地面距离 (D) 内。
注意:所有角度必须以弧度为单位。
If you accept that the Earth is a perfect sphere, you can obtain the spatial coordinates of a point by
Now, take two points and compute the angle they form with the center of the Earth (using a dot product):
(the value of R gets simplified).
In your case, the angular distance, Phi, equals 2Pi.D/R. (R=6 378.1 km).
A point P" is inside the ground distance (D) of P' when the dot product is larger than cos(Phi).
CAUTION: all angles must be in radians.
根据精度的不同,一定距离内的点的数据集可能非常大,甚至无限(不可能)。在半径为正的圆的给定区域中,您将有无穷多个点。因此,确定一个点是否落在圆内很简单,但枚举所有点是不可能的。
如果您确实设置了固定精度(例如单个数字),则可以循环所有可能的纬度和经度组合并执行距离测试。
Depending on the precision, the data set of points within a certain distance may be extremely large or even infinite (impossible). In a given area of a circle with a positive radius you will have infinitely many points. Thus, it is trivial to determine if a point falls within a circle, however to enumerate over all the points is impossible.
If you do set a fixed precision (such as a single digit), you can loop over all possible latitude and longitude combinations and perform the distance test.
凯文是对的。没有理由计算半径中每个可能的坐标对。
如果您从中心点 pC = Point(-76.0000, 38.0000) 开始,并测试任意点 pA = Point(Ax, Ay) 是否在 10 英里半径内...使用毕达哥拉斯定理:
合理的近似为 的点。
仅查询然后执行上面更密集的计算
Kevin is correct. There is no reason to calculate every possible coordinate-pair in the radius.
If you start at the centerpoint pC = Point(-76.0000, 38.0000) and are testing to find out if arbitrary point pA = Point(Ax, Ay) is within a 10 mile radius... use the Pythagorean theorem:
A reasonable approximation is to only query the points where
then perform the more intensive calculation above.