I have a csv file with the following format
Tampa Florida, Aarhus Denmark, Tampa Florida
Tampa Florida, Aarhus Denmark, London England, Tampa Florida
Each row is a trip and I need to calculate the total distance traveled from each trip. I figured I could geocode each location for lat/long coordinates then use those coordinate to calculate distance using vincenty in geopy. I need the distance in both miles and kilometers and I need it to write to the csv file with miles in 1 column and kilometers in a separate column.
Tampa Florida, Aarhus Denmark, Tampa Florida, XXX miles, XXX kilometers
I have the following code so far and have spent two days researching for a solution and I guess I am just not a very good programmer so please help:
from geopy.geocoders import ArcGIS
geolocator = ArcGIS()
import csv
with open('ttest.csv', "rb") as infile:
reader = csv.reader(infile, delimiter=",")
for row in reader:
a=",".join(row)
address, (latitude, longitude)=geolocator.geocode(a, timeout=10)
print (address, latitude, longitude)
Example of what I am trying to eventually accomplish though it doesn't work.
list1 = ["Tampa, Florida", "Aarhus, Denmark"]
locations = list1
location = geolocator.geocode("locations", timeout=10)
print((location.latitude, location.longitude))
from geopy.distance import vincenty
x = list1[0]
y = list1[1]
Sum all distances in a row
print(vincenty(sum).miles)
print(vicenty(sum).kilometers)
I appreciate any and all help.