两个地理位置的曼哈顿距离 [英] Manhattan Distance for two geolocations

查看:48
本文介绍了两个地理位置的曼哈顿距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有两个以纬度和经度表示的位置.位置1: 37.5613 126.978 位置2: 37.5776 126.973

Let's say I have two locations represented by latitude and longitude. Location 1 : 37.5613 , 126.978 Location 2 : 37.5776 , 126.973

如何使用曼哈顿距离计算距离?

How can I calculate the distance using Manhattan distance ?

我知道计算曼哈顿距离的公式,如 | x1-x2 |上的 Emd4600 所述.-| y1-y2 | ,但我认为这是针对笛卡尔的.如果可以直接应用 | 37.5613-37.5776 |+ | 126.978-126.973 | 结果的距离单位是多少?

Edit : I know the formula for calculating Manhattan distance like stated by Emd4600 on the answer which is |x1-x2| - |y1-y2| but I think it's for Cartesian. If it is can be applied that straight forward |37.5613-37.5776| + |126.978-126.973| what is the distance unit of the result ?

推荐答案

给出一个在(x1,y1) p2 处具有 p1 的平面>在(x2,y2)处,则曼哈顿距离的计算公式为 | x1-x2 |.+ | y1-y2 | .(即纬度和经度之差).因此,在您的情况下,它将是:

Given a plane with p1 at (x1, y1) and p2 at (x2, y2), it is, the formula to calculate the Manhattan Distance is |x1 - x2| + |y1 - y2|. (that is, the difference between the latitudes and the longitudes). So, in your case, it would be:

|126.978 - 126.973| + |37.5613 - 37.5776| = 0.0213

正如您所说,这将使我们获得纬度-经度单位的差异.基于此网页,这是我认为您必须执行的操作它到公制.我没有尝试过,所以我不知道它是否正确:

As you have said, that would give us the difference in latitude-longitude units. Basing on this webpage, this is what I think you must do to convert it to the metric system. I haven't tried it, so I don't know if it's correct:

首先,我们得到纬度差异:

First, we get the latitude difference:

Δφ = |Δ2 - Δ1|
Δφ = |37.5613 - 37.5776| = 0.0163

现在,经度差:

Δλ = |λ2 - λ1|
Δλ = |126.978 - 126.973| = 0.005

现在,我们将使用 haversine 公式.在网页中,它使用 a =sin²(Δφ/2)+ cosφ1⋅cosφ2⋅sin²(Δλ/2),但这将给我们一条直线距离.因此,要使用曼哈顿距离做到这一点,我们将分开进行纬度和经度距离.

Now, we will use the haversine formula. In the webpage it uses a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2), but that would give us a straight-line distance. So to do it with Manhattan distance, we will do the latitude and longitude distances sepparatedly.

首先,我们获得纬度距离,就好像经度为0(这就是为什么公式的大部分被省略的原因):

First, we get the latitude distance, as if longitude was 0 (that's why a big part of the formula got ommited):

a = sin²(Δφ/2)
c = 2 ⋅ atan2( √a, √(1−a) )
latitudeDistance = R ⋅ c // R is the Earth's radius, 6,371km

现在是经度距离,就好像纬度是0:

Now, the longitude distance, as if the latitude was 0:

a = sin²(Δλ/2)
c = 2 ⋅ atan2( √a, √(1−a) )
longitudeDistance = R ⋅ c // R is the Earth's radius, 6,371km

最后,只需加 | latitudeDistance |+ | longitudeDistance | .

这篇关于两个地理位置的曼哈顿距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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