根据 GPS 数据计算距离 [经度和纬度]
Posted
技术标签:
【中文标题】根据 GPS 数据计算距离 [经度和纬度]【英文标题】:Calculate distance from GPS data [longitude and latitude] 【发布时间】:2015-04-14 11:02:55 【问题描述】:我是熊猫数据挖掘的新手。我有由时间戳、经度和纬度值组成的 GPS 数据集。我的数据集看起来像 this。
In [3]:
import pandas as pd
import numpy as np
df = pd.read_csv('D:GPS.csv', index_col=None)
df
Out[3]:
time mLongitude mLongitude
0 2014-06-30 00:00:00 94.500000 126.998428
1 2014-06-30 00:00:00 94.500000 126.998428
2 2014-06-30 00:00:00 94.500000 126.998428
3 2014-06-30 00:00:00 94.500000 126.998428
4 2014-06-30 00:00:00 94.500000 126.998428
5 2014-06-30 00:00:00 94.500000 126.998428
6 2014-06-30 00:00:00 94.500000 126.998428
7 2014-06-30 00:00:00 94.500000 126.998428
8 2014-06-30 00:00:00 94.500000 126.998428
9 2014-06-30 00:00:00 94.500000 126.998428
10 2014-06-30 00:00:00 94.500000 126.998428
11 2014-06-30 00:00:00 94.500000 126.998428
12 2014-06-30 00:00:00 94.500000 126.998428
13 2014-06-30 00:00:00 94.500000 126.998428
14 2014-06-30 00:00:00 94.500000 126.998428
15 2014-06-30 00:00:00 94.500000 126.998428
... ... ... ...
9467 2014-08-02 00:00:00 44.299999 126.902259
9468 2014-08-02 00:00:00 44.299999 126.902259
9469 2014-08-02 00:00:00 44.299999 126.902259
9470 2014-08-02 00:00:00 44.299999 126.902259
9471 2014-08-02 00:00:00 44.299999 126.902259
9472 2014-08-02 00:00:00 44.299999 126.902259
在这里,我想计算每天的行驶距离。然后输出的例子是这样的:
time distance (meter)
2014-06-30 1000
2014-07-01 500
.... ...
2014-08-02 1500
【问题讨论】:
你是如何计算距离的? 地面还是海拔距离?直线/great circle distance? @SylvainLeroux 实际上,我不是这种情况的专家,但在阅读了一些参考资料后,我想我正在寻找地面距离。 @EdChum 我已经阅读了this 的代码,但我不知道如何修改代码以便在我的情况下实现它。 查看相关:***.com/questions/25767596/… 【参考方案1】:以下内容改编自我的answer:
In [133]:
import math
df['distance'] = 6367 * 2 * np.arcsin(np.sqrt(np.sin(np.radians(df['mLatitude']) - math.radians(37.2175900)/2)**2 + math.cos(math.radians(37.2175900)) * np.cos(np.radians(df['mLatitude']) * np.sin(np.radians(df['mLongitude']) - math.radians(-56.7213600)/2)**2)))
df
Out[133]:
time mLongitude mLatitude distance
index
0 2014-06-30 94.500000 126.998428 16032.604625
1 2014-06-30 94.500000 126.998428 16032.604625
2 2014-06-30 94.500000 126.998428 16032.604625
3 2014-06-30 94.500000 126.998428 16032.604625
4 2014-06-30 94.500000 126.998428 16032.604625
5 2014-06-30 94.500000 126.998428 16032.604625
6 2014-06-30 94.500000 126.998428 16032.604625
7 2014-06-30 94.500000 126.998428 16032.604625
8 2014-06-30 94.500000 126.998428 16032.604625
9 2014-06-30 94.500000 126.998428 16032.604625
10 2014-06-30 94.500000 126.998428 16032.604625
11 2014-06-30 94.500000 126.998428 16032.604625
12 2014-06-30 94.500000 126.998428 16032.604625
13 2014-06-30 94.500000 126.998428 16032.604625
14 2014-06-30 94.500000 126.998428 16032.604625
15 2014-06-30 94.500000 126.998428 16032.604625
9467 2014-08-02 44.299999 126.902259 10728.740464
9468 2014-08-02 44.299999 126.902259 10728.740464
9469 2014-08-02 44.299999 126.902259 10728.740464
9470 2014-08-02 44.299999 126.902259 10728.740464
9471 2014-08-02 44.299999 126.902259 10728.740464
9472 2014-08-02 44.299999 126.902259 10728.740464
In [137]:
df.set_index('time').resample('D', how='mean')
Out[137]:
mLongitude mLatitude distance
time
2014-06-30 94.500000 126.998428 16032.604625
2014-08-02 44.299999 126.902259 10728.740464
不清楚您的时间是否已经是日期时间,但如果不是,您可以转换它:df['time'] = pd.to_datetime(df['time'])
,我还重新标记了列,因为您有 2 个mLongitude
,我假设第二个应该是纬度
【讨论】:
太好了...,是的,我了解日期时间。感谢您的解决方案以上是关于根据 GPS 数据计算距离 [经度和纬度]的主要内容,如果未能解决你的问题,请参考以下文章