1 | |
---|
2 | #Test of redfearns formula. Tests can be verified at |
---|
3 | # |
---|
4 | #http://www.cellspark.com/UTM.html |
---|
5 | #http://www.ga.gov.au/nmd/geodesy/datums/redfearn_geo_to_grid.jsp |
---|
6 | |
---|
7 | |
---|
8 | import unittest |
---|
9 | from Numeric import allclose |
---|
10 | |
---|
11 | from redfearn import * |
---|
12 | from utilities.anuga_exceptions import ANUGAError |
---|
13 | |
---|
14 | #------------------------------------------------------------- |
---|
15 | |
---|
16 | class TestCase(unittest.TestCase): |
---|
17 | |
---|
18 | def test_decimal_degrees_conversion(Self): |
---|
19 | lat = degminsec2decimal_degrees(-37,39,10.15610) |
---|
20 | lon = degminsec2decimal_degrees(143,55,35.38390) |
---|
21 | assert allclose(lat, -37.65282114) |
---|
22 | assert allclose(lon, 143.9264955) |
---|
23 | |
---|
24 | dd,mm,ss = decimal_degrees2degminsec(-37.65282114) |
---|
25 | assert dd==-37 |
---|
26 | assert mm==39 |
---|
27 | assert allclose(ss, 10.15610) |
---|
28 | |
---|
29 | dd,mm,ss = decimal_degrees2degminsec(143.9264955) |
---|
30 | assert dd==143 |
---|
31 | assert mm==55 |
---|
32 | assert allclose(ss, 35.38390) |
---|
33 | |
---|
34 | |
---|
35 | def test_UTM_1(self): |
---|
36 | #latitude: -37 39' 10.15610" |
---|
37 | #Longitude: 143 55' 35.38390" |
---|
38 | #Site Name: GDA-MGA: (UTM with GRS80 ellipsoid) |
---|
39 | #Zone: 54 |
---|
40 | #Easting: 758173.797 Northing: 5828674.340 |
---|
41 | #Latitude: -37 39 ' 10.15610 '' Longitude: 143 55 ' 35.38390 '' |
---|
42 | #Grid Convergence: 1 47 ' 19.36 '' Point Scale: 1.00042107 |
---|
43 | |
---|
44 | lat = degminsec2decimal_degrees(-37,39,10.15610) |
---|
45 | lon = degminsec2decimal_degrees(143,55,35.38390) |
---|
46 | assert allclose(lat, -37.65282114) |
---|
47 | assert allclose(lon, 143.9264955) |
---|
48 | |
---|
49 | |
---|
50 | zone, easting, northing = redfearn(lat,lon) |
---|
51 | |
---|
52 | assert zone == 54 |
---|
53 | assert allclose(easting, 758173.797) |
---|
54 | assert allclose(northing, 5828674.340) |
---|
55 | |
---|
56 | |
---|
57 | def test_UTM_2(self): |
---|
58 | #TEST 2 |
---|
59 | |
---|
60 | #Latitude: -37 57 03.7203 |
---|
61 | #Longitude: 144 25 29.5244 |
---|
62 | #Zone: 55 |
---|
63 | #Easting: 273741.297 Northing: 5796489.777 |
---|
64 | #Latitude: -37 57 ' 3.72030 '' Longitude: 144 25 ' 29.52440 '' |
---|
65 | #Grid Convergence: -1 35 ' 3.65 '' Point Scale: 1.00023056 |
---|
66 | |
---|
67 | lat = degminsec2decimal_degrees(-37,57,03.7203) |
---|
68 | lon = degminsec2decimal_degrees(144,25,29.5244) |
---|
69 | #print lat, lon |
---|
70 | |
---|
71 | zone, easting, northing = redfearn(lat,lon) |
---|
72 | |
---|
73 | assert zone == 55 |
---|
74 | assert allclose(easting, 273741.297) |
---|
75 | assert allclose(northing, 5796489.777) |
---|
76 | |
---|
77 | |
---|
78 | def test_UTM_3(self): |
---|
79 | #Test 3 |
---|
80 | lat = degminsec2decimal_degrees(-60,0,0) |
---|
81 | lon = degminsec2decimal_degrees(130,0,0) |
---|
82 | |
---|
83 | zone, easting, northing = redfearn(lat,lon) |
---|
84 | #print zone, easting, northing |
---|
85 | |
---|
86 | assert zone == 52 |
---|
87 | assert allclose(easting, 555776.267) |
---|
88 | assert allclose(northing, 3348167.264) |
---|
89 | |
---|
90 | |
---|
91 | def test_UTM_4(self): |
---|
92 | #Test 4 (Kobenhavn, Northern hemisphere) |
---|
93 | lat = 55.70248 |
---|
94 | dd,mm,ss = decimal_degrees2degminsec(lat) |
---|
95 | |
---|
96 | lon = 12.58364 |
---|
97 | dd,mm,ss = decimal_degrees2degminsec(lon) |
---|
98 | |
---|
99 | zone, easting, northing = redfearn(lat,lon) |
---|
100 | |
---|
101 | |
---|
102 | assert zone == 33 |
---|
103 | assert allclose(easting, 348157.631) |
---|
104 | assert allclose(northing, 6175612.993) |
---|
105 | |
---|
106 | |
---|
107 | def test_UTM_5(self): |
---|
108 | #Test 5 (Wollongong) |
---|
109 | |
---|
110 | lat = degminsec2decimal_degrees(-34,30,0.) |
---|
111 | lon = degminsec2decimal_degrees(150,55,0.) |
---|
112 | |
---|
113 | zone, easting, northing = redfearn(lat,lon) |
---|
114 | |
---|
115 | #print zone, easting, northing |
---|
116 | |
---|
117 | assert zone == 56 |
---|
118 | assert allclose(easting, 308728.009) |
---|
119 | assert allclose(northing, 6180432.601) |
---|
120 | |
---|
121 | |
---|
122 | #def test_UTM_6(self): |
---|
123 | # """Test 6 (Don's Wollongong file's ref point) |
---|
124 | # """ |
---|
125 | # |
---|
126 | # lat = -34.490286785873 |
---|
127 | # lon = 150.79712139578 |
---|
128 | # |
---|
129 | # dd,mm,ss = decimal_degrees2degminsec(lat) |
---|
130 | # print dd,mm,ss |
---|
131 | # dd,mm,ss = decimal_degrees2degminsec(lon) |
---|
132 | # print dd,mm,ss |
---|
133 | # |
---|
134 | # zone, easting, northing = redfearn(lat,lon) |
---|
135 | # |
---|
136 | # print zone, easting, northing |
---|
137 | # |
---|
138 | # assert zone == 56 |
---|
139 | # #assert allclose(easting, 297717.36468927) #out by 10m |
---|
140 | # #assert allclose(northing, 6181725.1724276) |
---|
141 | |
---|
142 | def test_convert_lats_longs(self): |
---|
143 | |
---|
144 | #Site Name: GDA-MGA: (UTM with GRS80 ellipsoid) |
---|
145 | #Zone: 56 |
---|
146 | #Easting: 222908.705 Northing: 6233785.284 |
---|
147 | #Latitude: -34 0 ' 0.00000 '' Longitude: 150 0 ' 0.00000 '' |
---|
148 | #Grid Convergence: -1 40 ' 43.13 '' Point Scale: 1.00054660 |
---|
149 | |
---|
150 | lat_gong = degminsec2decimal_degrees(-34,30,0.) |
---|
151 | lon_gong = degminsec2decimal_degrees(150,55,0.) |
---|
152 | |
---|
153 | lat_2 = degminsec2decimal_degrees(-34,00,0.) |
---|
154 | lon_2 = degminsec2decimal_degrees(150,00,0.) |
---|
155 | |
---|
156 | lats = [lat_gong, lat_2] |
---|
157 | longs = [lon_gong, lon_2] |
---|
158 | zone, points = convert_lats_longs(lats, longs) |
---|
159 | |
---|
160 | assert allclose(points[0][0], 308728.009) |
---|
161 | assert allclose(points[0][1], 6180432.601) |
---|
162 | assert allclose(points[1][0], 222908.705) |
---|
163 | assert allclose(points[1][1], 6233785.284) |
---|
164 | self.failUnless(zone == 56, |
---|
165 | 'Bad zone error!') |
---|
166 | def test_convert_lats_longs2(self): |
---|
167 | |
---|
168 | #Site Name: GDA-MGA: (UTM with GRS80 ellipsoid) |
---|
169 | #Zone: 56 |
---|
170 | #Easting: 222908.705 Northing: 6233785.284 |
---|
171 | #Latitude: -34 0 ' 0.00000 '' Longitude: 150 0 ' 0.00000 '' |
---|
172 | #Grid Convergence: -1 40 ' 43.13 '' Point Scale: 1.00054660 |
---|
173 | |
---|
174 | lat_gong = degminsec2decimal_degrees(-34,30,0.) |
---|
175 | lon_gong = degminsec2decimal_degrees(150,55,0.) |
---|
176 | |
---|
177 | lat_2 = degminsec2decimal_degrees(34,00,0.) |
---|
178 | lon_2 = degminsec2decimal_degrees(100,00,0.) |
---|
179 | |
---|
180 | lats = [lat_gong, lat_2] |
---|
181 | longs = [lon_gong, lon_2] |
---|
182 | try: |
---|
183 | zone, points = convert_lats_longs(lats, longs) |
---|
184 | except ANUGAError: |
---|
185 | pass |
---|
186 | else: |
---|
187 | self.failUnless(0 ==1, |
---|
188 | 'Error not thrown error!') |
---|
189 | |
---|
190 | #------------------------------------------------------------- |
---|
191 | if __name__ == "__main__": |
---|
192 | |
---|
193 | mysuite = unittest.makeSuite(TestCase,'test') |
---|
194 | runner = unittest.TextTestRunner() |
---|
195 | runner.run(mysuite) |
---|