如何快速估计两个(纬度、经度)点之间的距离? [英] How can I quickly estimate the distance between two (latitude, longitude) points?

查看:28
本文介绍了如何快速估计两个(纬度、经度)点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够估计两个(纬度、经度)点之间的距离.我想低于,因为这将用于 A* 图形搜索,并且我希望它快速.这些点最多相距 800 公里.

I want to be able to get a estimate of the distance between two (latitude, longitude) points. I want to undershoot, as this will be for A* graph search and I want it to be fast. The points will be at most 800 km apart.

推荐答案

Python 中的 Haversine 公式(两个 GPS 点之间的轴承和距离) 提供了可以回答您的问题的 Python 实现.

The answers to Haversine Formula in Python (Bearing and Distance between two GPS points) provide Python implementations that answer your question.

使用下面的实现,我在不到 1 秒的时间内在较旧的笔记本电脑上执行了 100,000 次迭代.我认为就您的目的而言,这应该足够了.但是,您应该在优化性能之前分析任何内容.

Using the implementation below I performed 100,000 iterations in less than 1 second on an older laptop. I think for your purposes this should be sufficient. However, you should profile anything before you optimize for performance.

from math import radians, cos, sin, asin, sqrt
def haversine(lon1, lat1, lon2, lat2):
    """
    Calculate the great circle distance between two points 
    on the earth (specified in decimal degrees)
    """
    # convert decimal degrees to radians 
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    # haversine formula 
    dlon = lon2 - lon1 
    dlat = lat2 - lat1 
    a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
    c = 2 * asin(sqrt(a)) 
    # Radius of earth in kilometers is 6371
    km = 6371* c
    return km

低估haversine(lat1, long1, lat2, long2) * 0.90 或任何你想要的因素.我不明白在你的低估中引入错误有什么用.

To underestimate haversine(lat1, long1, lat2, long2) * 0.90 or whatever factor you want. I don't see how introducing error to your underestimation is useful.

这篇关于如何快速估计两个(纬度、经度)点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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