I am new to python for a month and doing an assignment with geopy.
I am asked to define a function named Cal_Distance(self) , which returns the distance of the whole trajectory in meter. Use a for loop to traverse all trajectory points to calculate the great-circle distance between each two consecutive points, then sum them up and return total distance of the whole trajectory.
Here is a part of my code.
def Cal_Distance(self):
import geopy.distance as geo
for x in self.data:
for y in x:
self.data.append(y)
z1 = int(y)
z2 = int(y+1)
point1_lat = self.data[z1][0]
point2_lat = self.data[z2][0]
point1_lon = self.data[z1][1]
point2_lon = self.data[z2][1]
point_start = (point1_lat, point1_lon)
point_end = (point2_lat, point2_lon)
dis = geo.great_circle(point_start, point_end).meters
return dis
The self.data list is similar to the following one.
[[39.99473, 116.3075133, 236.2, ‘2009-04-14’, ‘07:33:07’], [39.9947383, 116.3075199, 246.1, ‘2009-04-14’, ‘07:33:08’], [39.9947099, 116.3074466, 328.1, ‘2009-04-14’, ‘07:33:11’], [39.9947116, 116.3074633, 347.8, ‘2009-04-14’, ‘07:33:13’]]
The error shows up like this
ValueError: invalid literal for int() with base 10: ‘2009-04-14’
How can I solve it? Thanks a lot!!