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
return km
這應該是我使用緯度和經度在紙上計算的最終結果:
Identifier num_pts latitude longitude distance
0 AL011851 3 28.0 -94.8 NaN
1 AL011851 3 28.0 -95.4 58.870532
2 AL011851 3 28.1 -96.0 58.870532
3 AL021851 2 22.2 -97.6
4 AL021851 2 12.0 -60.0
編輯:我需要計算連續點之間的距離,如0和1,以及2,它必須按標識符分組,以確保點不是來自不同的標識符所以當有一個新的標識符,如AL021851,它重置并且只計算該標識符中的點
總結
以上是生活随笔為你收集整理的java点到曲线的距离公式,使用Haversine的距离公式获取经度和纬度的距离的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网站计数器 php,网站计数器 php
- 下一篇: java 参数三点,java函数参数类型