Assuming I have the following:
latitude = "20-55-70.010N"
longitude = "32-11-50.000W"
What is the easiest way to convert to decimal form? Is there some library?
Would converting from this seconds form be simpler?
"149520.220N""431182.897W"
Assuming I have the following:
latitude = "20-55-70.010N"
longitude = "32-11-50.000W"
What is the easiest way to convert to decimal form? Is there some library?
Would converting from this seconds form be simpler?
"149520.220N""431182.897W"
To handle "N", "S", "W" and "E", one would tweak @wwii's solution:
def convert(tude):multiplier = 1 if tude[-1] in ['N', 'E'] else -1return multiplier * sum(float(x) / 60 ** n for n, x in enumerate(tude[:-1].split('-')))
then:
print('20-55-70.010N: ' + convert('20-55-70.010N'))
print('32-11-50.000W: ' + convert('32-11-50.000W'))
results in:
20-55-70.010N: 20.9361138889
32-11-50.000W: -32.1972222222