-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcoord.py
87 lines (82 loc) · 2.61 KB
/
gcoord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 19 11:16:49 2017
@author: Ionut
"""
def deg_min_str_to_dec(position):
''' Convert a coordinate from a string decimal degree.
Examples:
>>> pos = '50 05.0713061 N'
>>> deg_min_str_to_dec(pos)
50.08452177
>>> deg_min_str_to_dec('005 41.9434092 W')
-5.69905682
>>> deg_min_str_to_dec('50 05.0713061 N')
50.08452177
>>> deg_min_str_to_dec('55;18.7116860N')
55.31186143
>>> deg_min_str_to_dec('5023.1994,N')
50.38665667
>>> deg_min_str_to_dec('00408.6421,W')
-4.144035
>>> deg_min_str_to_dec('5023.1994,S')
-50.38665667
>>> deg_min_str_to_dec('00408.6421,E')
4.144035
'''
if " " in position:
l = position.split(" ")
#print the value of l and line identifier (can be anything, not just line32)
print('line32',l)
deg = int(l[0])
print('line34',deg)
minut = float(l[1])
print('line35',minut)
if l[-1] in ['S', 'W']:
sph = -1
print('line39',sph)
else:
sph = 1
elif ";" in position:
l = position.split(";")
deg = int(l[0])
minut = float(l[1][0:-1])
if l[-1] in ['S', 'W']:
sph = -1
else:
sph = 1
elif ',' in position[-2]:
if position[-1] == 'N':
deg = int(position[0:2])
minut = float(position[2:-2])
sph = 1
elif position[-1] == 'S':
deg = int(position[0:2])
minut = float(position[2:-2])
sph = -1
elif position[-1] == 'W':
deg = int(position[0:3])
minut = float(position[3:-2])
sph = -1
elif position[-1] == 'E':
deg = int(position[0:3])
minut = float(position[3:-2])
sph = 1
else:
deg = 0
minut = 0
sph = 1
coord = ((deg + minut/60)*sph)
return round(coord, 8)
# Run doctest through the top Examples, if no errors = no output, change a result to get an error
print(deg_min_str_to_dec('50 05.0713061 N'))
print(deg_min_str_to_dec('005 41.9434092 W'))
print(deg_min_str_to_dec('50 05.0713061 N'))
print(deg_min_str_to_dec('55;18.7116860N'))
print(deg_min_str_to_dec('5023.1994,N'))
print(deg_min_str_to_dec('00408.6421,W'))
print(deg_min_str_to_dec('5023.1994,S'))
print(deg_min_str_to_dec('00408.6421,E'))
#if __name__=="__main__":
# import doctest
# doctest.testmod()