def testDistances(self, a1, b1, a2, b2, x): k = x * 0.003 # allow 0.3% margin d = haversine(a1, b1, a2, b2) self.test('haversine', d, x, fmt='%.3f', known=abs(d - x) < k) d = vincentys(a1, b1, a2, b2) self.test('vincentys', d, x, fmt='%.3f', known=abs(d - x) < k) k = x * 0.02 # allow 2% margin d = equirectangular(a1, b1, a2, b2, limit=90) self.test('equirectangular', d, x, fmt='%.3f', known=abs(d - x) < k) k = x * 0.11 # allow 11% margin d = euclidean(a1, b1, a2, b2) self.test('euclidean', d, x, fmt='%.3f', known=abs(d - x) < k)
def testDms(self): # dms module tests self.test('parseDMS', parseDMS('0.0°'), '0.0') self.test('parseDMS', parseDMS('0°'), '0.0') self.test('parseDMS', parseDMS('''000°00'00"'''), '0.0') self.test('parseDMS', parseDMS('''000°00'00.0"'''), '0.0') self.test('parseDMS', parseDMS('''000° 00'00"'''), '0.0') self.test('parseDMS', parseDMS('''000°00 ' 00.0"'''), '0.0') r = rangerrors(True) try: self.test('parseDMS', parseDMS(181, clip=180), 'ValueError') except ValueError as x: self.test('parseDMS', str(x), '181.0 beyond 180 degrees') rangerrors(False) try: self.test('parseDMS', parseDMS(-91, clip=90), -90) except ValueError as x: self.test('parseDMS', str(x), '-90') rangerrors(r) x = parse3llh('000° 00′ 05.31″W, 51° 28′ 40.12″ N') x = ', '.join('%.6f' % a for a in x) # XXX fStr self.test('parse3llh', x, '51.477811, -0.001475, 0.000000') for a, x in (((), '''45°45'45.36"'''), ((F_D, None), '45.7626°'), ((F_DM, None), "45°45.756'"), ((F_DMS, None), '''45°45'45.36"'''), ((F_DEG, None), '45.7626'), ((F_MIN, None), '4545.756'), ((F_SEC, None), '454545.36'), ((F_RAD, None), '0.79871'), ((F_D, 6), '45.7626°'), ((F_DM, -4), "45°45.7560'"), ((F_DMS, 2), '''45°45'45.36"'''), ((F_DEG, -6), '45.762600'), ((F_MIN, -5), '4545.75600'), ((F_SEC, -3), '454545.360'), ((F_RAD, -6), '0.798708')): t = 'toDMS(%s)' % (a[:1] or '') self.test(t, toDMS(45.76260, *a), x) self.test('compassAngle0', compassAngle(0, 0, 0, 0), 0.0) self.test('compassAngle1', compassAngle(0, 0, 10, 10), 45.0) self.test('compassAngle2', compassAngle(0, 0, 0, 10), 90.0) self.test('compassAngle3', compassAngle(0, 0, -1, 0), 180.0) self.test('compassAngle4', compassAngle(0, 0, -1, -1), 225.0) self.test('compassAngle5', compassAngle(0, 0, 0, -1), 270.0) self.test('compassAngle6', compassAngle(0, 0, 1, -1), 315.0) self.test('compassAngle7', compassAngle(0, 0, 99, -1), 359.4, fmt='%.1f') for a, x in (((1, ), 'N'), ((0, ), 'N'), ((-1, ), 'N'), ((359, ), 'N'), ((24, ), 'NNE'), ((24, 1), 'N'), ((24, 2), 'NE'), ((24, 3), 'NNE'), ((226, ), 'SW'), ((226, 1), 'W'), ((226, 2), 'SW'), ((226, 3), 'SW'), ((237, ), 'WSW'), ((237, 1), 'W'), ((237, 2), 'SW'), ((237, 3), 'WSW')): self.test('compassPoint', compassPoint(*a), x) for a, x in enumerate( ('NbE', 'NEbN', 'NEbE', 'EbN', 'EbS', 'SEbE', 'SEbS', 'SbE', 'SbW', 'SWbS', 'SWbW', 'WbS', 'WbN', 'NWbW', 'NWbN', 'NbW')): a = 11.25 + a * 22.5 self.test('compassPoint', compassPoint(a, 4), x) a = compassAngle(_LHR.lat, _LHR.lon, _FRA.lat, _FRA.lon) self.test('compassAngle', a, 100.016848, fmt='%.6f') b = _LHR.initialBearingTo(_FRA) self.test('initialBearingTo', b, 102.432182, fmt='%.6f') d = equirectangular(_LHR.lat, _LHR.lon, _FRA.lat, _FRA.lon) self.test('equirectangular', m2km(d), 592.185, fmt='%.3f') d = _LHR.distanceTo(_FRA) self.test('distanceTo', m2km(d), 591.831, fmt='%.3f')
def testFormy(self): self.test('antipode1', antipode(89, 179), (-89.0, -1.0)) self.test('antipode2', antipode(-89, -179), (89.0, 1.0)) # roughly, Newport to New York self.test('bearing1', bearing(41.49, -71.31, 40.78, -73.97), 251.364, fmt='%.3f') self.test('bearing2', bearing(41.49, -71.31, 40.78, -73.97, final=False), 251.364, fmt='%.3f') self.test('bearing3', bearing(41.49, -71.31, 40.78, -73.97, final=True), 249.614, fmt='%.3f') self.test('isantipode1', isantipode(89, 179, -89, -1), True) self.test('isantipode2', isantipode(-89, -179, 89, 1), True) self.test('isantipode3', isantipode(-89, -179, -89, -1), False) self.test('isantipode4', isantipode_(*map1(radians, 89, 179, -89, -1)), True) self.test('isantipode5', isantipode_(*map1(radians, -89, -179, 89, 1)), True) self.test('isantipode6', isantipode_(*map1(radians, -89, -179, -89, -1)), False) self.test('heightOf0', heightOf(0, R_M), 2638958.23912, fmt='%.5f') self.test('heightOf45', heightOf(45, R_M), 5401080.43931, fmt='%.5f') self.test('heightOf90', heightOf(90, R_M), R_M, fmt='%.5f') # Height self.test('heightOf135', heightOf(135, R_M), 5401080.43931, fmt='%.5f') self.test('horizon0', horizon(0), 0.0) self.test('horizon10Km', horizon(10000), '357099.672', fmt='%.3f') self.test('horizon30Kft', horizon(10000, refraction=True), '392310.704', fmt='%.3f') self.test('horizon10Kft', horizon(3000, refraction=True), '214877.422', fmt='%.3f') # lat lon Auckland = -36.8485, 174.7633 Boston = 42.3541165, -71.0693514 Cleveland = 41.499498, -81.695391 LosAngeles = 34.0522, -118.2437 MtDiablo = 37.8816, -121.9142 Newport = 41.49008, -71.312796 NewYork = 40.7791472, -73.9680804 Santiago = -33.4489, -70.6693 X = 25.2522, 55.28 Y = 14.6042, 120.982 # <https://GeographicLib.SourceForge.io/cgi-bin/GeodSolve>, <https://www.Distance.to> for i, (ll1, ll2, expected) in enumerate(( (Boston, NewYork, 298009.404), # ..328,722.580 370 km (Boston, Newport, 98164.988), # ..106,147.318 99 km (Cleveland, NewYork, 651816.987), # ..736,534.840 536 km (NewYork, MtDiablo, 4084985.780), # ..4,587,896.452 3,952 km (Auckland, Santiago, 9670051.606), # ..15,045,906.074 9,665 km (Auckland, LosAngeles, 10496496.577), # ..13,002,288.857 10,940 km (LosAngeles, Santiago, 8998396.669), # ..10,578,638.162 8,993 km (X, Y, 6906867.946))): # ..6916,085.326 6,907 km self.testDistances(str(i + 1), *(ll1 + ll2), x=expected) # Thomas' S2, page 153 <https://apps.DTIC.mil/dtic/tr/fulltext/u2/703541.pdf> self.testDistances2('9', parseDMS('75 57 42.053'), 0, parseDMS('17 5 21.296'), parseDMS('85 31 54.631'), x=8044806.076, datum=Datums.NAD27) # Clarke1866 ellipsoid self.test(intersections2.__name__, intersections2.__module__, formy.__name__, nl=1) for datum in (None, R_M, Datums.WGS84): self.testIntersections2(datum) n = radical2.__name__ self.test(n, radical2(10, 4, 8), '(0.26, 2.6)', nl=1) self.test(n, radical2(10, 8, 4), '(0.74, 7.4)') self.test(n, radical2(10, 5, 5), '(0.5, 5.0)') try: # coverage self.test(n, radical2(10, 5, 4), IntersectionError.__name__, nt=1) except Exception as x: self.test(IntersectionError.__name__, str(x), 'distance (10.0), ...', known=True, nt=1) n = LimitError.__name__ t = limiterrors(True) try: # coverage self.test(n, equirectangular(0, 0, 60, 120), n) except Exception as x: self.test(n, str(x), 'delta exceeds ...', known=True) limiterrors(t)