I don't know what the hell is wrong with that, but I can't figure it out at all ...
So, I have this code:
from model.Formulas import Formulas
f = open("coords_data.txt", "r")
line1 = f.readline()
line2 = f.readline()
orig = line1.split(';')
dest = line2.split(';')
origin = (orig[0] + ", " + orig[1].strip("\n"))
destination = (dest[0] + ", " + dest[1].strip("\n"))
print("Orig: " + str(origin))
print("Dest: " + str(destination))
total_dist = Formulas.calculateDistance(str(origin), str(destination))
And then the import code:
import math
class Formulas:
@staticmethod
def calculateDistance(origin, destination, rounding=0):
lat1, lon1 = origin
lat2, lon2 = destination
radius = 6371 # km
dlat = math.radians(lat2 - lat1)
dlon = math.radians(lon2 - lon1)
a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
d = radius * c
return round(d, rounding)
So, now I want to get from a large list (5057 lines) of coordinates in order to have an exact total distance. Therefore, you need to take into account all the differences between the distances and return one large amount (for example, 150 km).
The error I get is:
ValueError: Too many values to unpack (2 expected)
The coordinates in the file are as follows:
5114.8268;00457.9847
5114.8271;00457.9845
5114.8271;00457.9845
5114.8271;00457.9845
5114.8270;00457.9846
5114.8271;00457.9846
5114.8272;00457.9847
5114.8272;00457.9847
5114.8274;00457.9843
5114.8272;00457.9846
5114.8274;00457.9843
5114.8277;00457.9837
5114.8287;00457.9835
5114.8274;00457.9843
5114.8288;00457.9831
5114.8287;00457.9835
5114.8286;00457.9813
5114.8274;00457.9843
5114.8287;00457.9815
5114.8286;00457.9813
5114.8270;00457.9846
5114.8286;00457.9813
5114.8355;00457.9784
5114.8292;00457.9814
5114.8274;00457.9843
5114.8376;00457.9776
5114.8395;00457.9769
Now it is in the file, but this data will be stored in the database.
How can i fix this? And how do I get rid of an error?