Calculate distance from GPS data [longitude and latitude]

markov zain

I am a newbie in pandas datamining. I have GPS dataset that consists of timestamp, longitude and latitude values. My dataset looks like 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

In here, I want to calculate traveling distance for each day. And then the example of the output would be like this:

 time        distance (meter)
2014-06-30     1000 
2014-07-01     500
....           ...
2014-08-02     1500
EdChum

Thw following is adapted from my 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

It's unclear if your time is alread a datetime or not but if not you can convert it: df['time'] = pd.to_datetime(df['time']), I also relabelled the columns as you had 2 mLongitude, I'm assuming the 2nd one should be latitude

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculate distance using latitude and longitude using gps data .

From Dev

Efficient way to calculate distance matrix given latitude and longitude data in Python

From Dev

How to calculate distance using latitude and longitude?

From Dev

How to calculate distance based on Latitude and Longitude

From Dev

Convert GPS data to latitude and longitude c#

From Dev

Convert GPS data to latitude and longitude c#

From Dev

longitude and latitude format From GPS modem

From Dev

calculate nearest latitude and longitude from two latitude and longitude in php

From Dev

calculate the distance using longitude and latitude in vb using array

From Java

Calculate distance between two latitude-longitude points? (Haversine formula)

From Dev

Calculate distance between a point and a line segment in latitude and longitude

From Dev

In java, how can i calculate distance between multiple latitude and longitude?

From Dev

Calculate distance between two latitude-longitude points?

From Dev

Calculate all latitude and longitude distance in result using MySQL

From Dev

conversion latitude/longitude into distance

From Dev

What is the best way to get latitude and longitude from GPS in Android?

From Dev

How to get distance from latitude and longitude from mysql Address table which have latitude and longitude

From Dev

How to format GPS latitude and longitude?

From Dev

using Gps Getting Latitude and Longitude

From Dev

Calculating MAX and MIN Latitude and Longitude with distance from Location - Objective C

From Dev

retrieve record from database using latitude longitude distance mysql join

From Dev

Find distance longitude and latitude in array from user location

From Dev

Simulating Geographic data from Longitude & Latitude in R

From Dev

Reading the Latitude and longitude from Json and calculate driving directions

From Dev

Calculate latitude longitude for added height

From Dev

Calculate the area of a polygon with latitude and longitude

From Dev

How to get Latitude and Longitude without using GPS?

From Dev

Arduino-GPS is not giving longitude and latitude values

From Dev

How to deal with Latitude Longitude errors of gps data while plotting on google map?

Related Related

  1. 1

    Calculate distance using latitude and longitude using gps data .

  2. 2

    Efficient way to calculate distance matrix given latitude and longitude data in Python

  3. 3

    How to calculate distance using latitude and longitude?

  4. 4

    How to calculate distance based on Latitude and Longitude

  5. 5

    Convert GPS data to latitude and longitude c#

  6. 6

    Convert GPS data to latitude and longitude c#

  7. 7

    longitude and latitude format From GPS modem

  8. 8

    calculate nearest latitude and longitude from two latitude and longitude in php

  9. 9

    calculate the distance using longitude and latitude in vb using array

  10. 10

    Calculate distance between two latitude-longitude points? (Haversine formula)

  11. 11

    Calculate distance between a point and a line segment in latitude and longitude

  12. 12

    In java, how can i calculate distance between multiple latitude and longitude?

  13. 13

    Calculate distance between two latitude-longitude points?

  14. 14

    Calculate all latitude and longitude distance in result using MySQL

  15. 15

    conversion latitude/longitude into distance

  16. 16

    What is the best way to get latitude and longitude from GPS in Android?

  17. 17

    How to get distance from latitude and longitude from mysql Address table which have latitude and longitude

  18. 18

    How to format GPS latitude and longitude?

  19. 19

    using Gps Getting Latitude and Longitude

  20. 20

    Calculating MAX and MIN Latitude and Longitude with distance from Location - Objective C

  21. 21

    retrieve record from database using latitude longitude distance mysql join

  22. 22

    Find distance longitude and latitude in array from user location

  23. 23

    Simulating Geographic data from Longitude & Latitude in R

  24. 24

    Reading the Latitude and longitude from Json and calculate driving directions

  25. 25

    Calculate latitude longitude for added height

  26. 26

    Calculate the area of a polygon with latitude and longitude

  27. 27

    How to get Latitude and Longitude without using GPS?

  28. 28

    Arduino-GPS is not giving longitude and latitude values

  29. 29

    How to deal with Latitude Longitude errors of gps data while plotting on google map?

HotTag

Archive