java点到曲线的距离公式,使用Haversine的距离公式获取经度和纬度的距离

我在大熊猫数据框架中工作,我试图获得每个标识符的每个点的经度和纬度的距离 .

这是目前的数据框:

Identifier num_pts latitude longitude

0 AL011851 3 28.0 -94.8

1 AL011851 3 28.0 -95.4

2 AL011851 3 28.1 -96.0

3 AL021851 2 22.2 -97.6

4 AL021851 2 12.0 -60.0

我知道我必须使用Haversine的距离公式,但我不确定如何使用我的数据合并它 .

import numpy as np

def haversine(lon1, lat1, lon2, lat2, earth_radius=6367):

"""

Calculate the great circle distance between two points

on the earth (specified in decimal degrees)

All args must be of equal length.

"""

lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])

dlon = lon2 - lon1

dlat = lat2 - lat1

a = np.sin(dlat/2.0)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2.0)**2

c = 2 * np.arcsin(np.sqrt(a))

km = earth_radius * c

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值