I'm relatively new to python so I'm sorry in advance if I'm asking too dumb questions
I have CSV file with following columns: 'CarNumber','DateTime', 'GPS', 'Speed'. GPS column contains information in the form of: 'Latitude : Longitude'
I want to:
1) Load CSV file
2) Split GPS column to Latitude and Longitude columns
3) Apply Haversine formula in order to calculate distance between two points with known Latitude and Longitude. So far I've come up with following function:
def distRad(glat1, glng1, glat2, glng2):
from math import sin, cos, sqrt, atan2, radians, asin
# approximate radius of earth in km
R = 6371.0
lat1 = radians(glat1)
lng1 = radians(glng1)
lat2 = radians(glat2)
lng2 = radians(glng2)
dlng = lng2 - lng1
dlat = lat2 - lat1
#a = 2 * asin((sin(dlng/2)**2+cos(lng1)*cos(lng2)*sin(dlat/2)**2)**0.5)
#c = a
a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlng / 2)**2
c = 2 * atan2(sqrt(a), sqrt(1 - a))
return R * c
4) Upload results to new csv file with Columns: 'CarNumber', 'DateTime', 'Latitude', 'Longitude', 'Distance' I know that might sound really simple and trivial but I still need guidance
Portion of my CSV file:
CarNumber;DateTime;GPS;Speed
230;04.06.2019 0:00:12;87,96978 : 159,588606;20
Thank you!