簡體   English   中英

計算GPS數據的距離[經度和緯度]

[英]Calculate distance from GPS data [longitude and latitude]

我是pandas datamining的新手。 我有GPS數據集,包括時間戳,經度和緯度值。 我的數據集看起來像這樣

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

以下是根據我的回答改編的:

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 ,I假設第二個應該是緯度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM