I have a pretty simple issue: I need to convert the file with geographical coordinates like
Lat Long
50 0 50 35 1 40
50 2 50 35 10 20
50 3 1 35 13 22
50 2 38 35 14 40
49 59 6 35 13 22
49 57 14 35 13 21
49 57 10 35 13 0
49 57 0 35 6 20
to the
Lat Long
50.01389,35.02778
50.04722,35.17222
etc.
Math is as simple as a pie: we have to devide minutes (0 and 1 in this particular case) by 60 and seconds (50 and 40) by 3600, then add these numbers and we will get the remainder of the degree (50 and 35).
Here is my script with numpy. I suppose, it looks to big for such a simple conversion, however I don't know how to do this simpler. Also I don't know how to end this script, so it could do what it should. Now it ends with adding minutes and seconds.
import sys
import numpy as np
filename = input('Please enter the file\'s name: ')
with open(filename, "r") as f:
sys.stdout = open('%s (converted).txt' % f.name, 'a')
data = np.loadtxt(f)
degree_lat, degree_long = data[:, 0], data[:, 3]
min_lat, sec_lat, min_long, sec_long = \
(data[:, 1] / 60), (data[:, 2] / 3600), (data[:, 4] / 60), (data[:, 5] / 3600)
remainder_lat, remainder_long = min_lat + sec_lat, min_long + sec_long
degree_result_lat = degree_lat + remainder_lat
degree_result_long = degree_long + remainder_long
Any suggestions would be greatly appreciated! Thanks and sorry for the amateur questions.
sys.stdout = open...?ValueError: could not convert string to float: Lat.