У меня есть файл tkpt_dict.txt это координаты формата "Широта, Долгота" для каждой точки
56.6656332229853,-4.07549094973673
56.6654706790411,-4.07715475708222
56.6658433607951,-4.0803983938441
56.6657085935658,-4.08308369800892
56.6656913596524,-4.08679545454817
56.6656592305536,-4.08871123027875
56.6654891203157,-4.08947699433228
56.6655907727544,-4.09278733564568
56.6654648415451,-4.09359632994024
56.6657530084886,-4.09516268121721
56.6661261281559,-4.09701937330206
56.666583500041,-4.09920718895852
56.6668895070955,-4.10013813805868
56.6665747421354,-4.09919364584093
56.6661293622529,-4.09704076876584
56.665744414777,-4.09513935667372
Задача состоит в том, чтобы рассчитать дистанцию между точками по формуле geopy.distance (наиболее подходит по точности)
Имеется данный кусок кода:
import geopy.distance
i = 0
y = 1
with open('obj/tkpt_dict.txt', 'r') as file:
for line in file:
with open('obj/distance.txt', 'a') as distance_file:
distance = int(round(geopy.distance.distance(float(line[i]), float(line[y])).m, 0))
distance_file.write(str(distance))
i += 1
y += 1
Но код выдает ошибку:
Traceback (most recent call last):
File "D:/Python/Project1/31-gps-m.py", line 11, in <module>
distance=int(round(geopy.distance.distance(float(line[i]),float(line[y])).m, 0))
ValueError: could not convert string to float: '.'
Нужно как-то данные из txt-файла перенести в формулу
distance = int(round(geopy.distance.distance(точка1), точка2).m, 0))
и полученные результаты внести в out-файл distance.txt