示例#1
0
 def test_distance(self):
     """
     Distances calculated with
     http://geographiclib.sourceforge.net/cgi-bin/GeodSolve
     """
     self.assertRaises(AssertionError, distance, "", 0, 0, 0)
     self.assertRaises(AssertionError, distance, 0, "", 0, 0)
     self.assertRaises(AssertionError, distance, 0, 0, "", 0)
     self.assertRaises(AssertionError, distance, 0, 0, 0, "")
     self.assertRaises(AssertionError, distance, 0, np.array([0]), 0, 0)
     self.assertRaises(AssertionError, distance, 0, 0, 0, np.array([0]))
     self.assertRaises(AssertionError, distance, np.array([0, 1]), np.array([0]), 0, 0)
     self.assertRaises(AssertionError, distance, 0, 0, np.array([0, 1]), np.array([0]))
     lon1, lat1 = -001.8494, +53.1472
     lon2, lat2 = +000.1406, +52.2044
     lon3, lat3 = +163.4539, +78.1692
     lon4, lat4 = -050.6923, -05.2369
     tgt_d12 = 00170648.997253939
     tgt_d13 = 05397860.320859759
     tgt_d14 = 07918708.570611600
     tgt_d23 = 05492562.133558812
     tgt_d24 = 07964495.675016765
     tgt_d34 = 11668218.434849779
     cal_d12 = round(distance(lon1, lat1, lon2, lat2), 8)
     cal_d34 = round(distance(lon3, lat3, lon4, lat4), 8)
     self.assertEqual(cal_d12, round(tgt_d12, 8))
     self.assertEqual(cal_d34, round(tgt_d34, 8))
     c = distance(lon1, lat1, np.array([lon1, lon2]), np.array([lat1, lat2]))
     t = np.array([0, tgt_d12])
     self.assertTrue(np.array_equal(np.round(c, 8), np.round(t, 8)))
     c = distance(
         np.array([lon1, lon2]), np.array([lat1, lat2]), np.array([lon1, lon3, lon4]), np.array([lat1, lat3, lat4])
     )
     t = np.array([[0, tgt_d13, tgt_d14], [tgt_d12, tgt_d23, tgt_d24]])
     self.assertTrue(np.array_equal(np.round(c, 7), np.round(t, 7)))
示例#2
0
 def test_distance(self):
     """
     """
     self.assertRaises(AssertionError, distance, '', 0, 0, 0)
     self.assertRaises(AssertionError, distance, 0, '', 0, 0)
     self.assertRaises(AssertionError, distance, 0, 0, '', 0)
     self.assertRaises(AssertionError, distance, 0, 0, 0, '')
     self.assertRaises(AssertionError, distance, 0, np.array([0]), 0, 0)
     self.assertRaises(AssertionError, distance, 0, 0, 0, np.array([0]))
     self.assertRaises(
         AssertionError, distance, np.array([0, 1]), np.array([0]), 0, 0)
     self.assertRaises(
         AssertionError, distance, 0, 0, np.array([0, 1]), np.array([0]))
     self.assertEqual(
         round(distance(-1.8494, 53.1472, 0.1406, 52.2044), 4), 170.2563)
     self.assertEqual(
         round(distance(-86.67, 36.12, -118.40, 33.94, er=6372.8), 12),
         2887.259950607111
         )
     r = 111.194926645
     a = np.array([
        [[[r*(5-1),r*(6-1)],[r*(7-1),r*(8-1)]],
        [[r*(5-2),r*(6-2)],[r*(7-2),r*(8-2)]]],
        [[[r*(5-3),r*(6-3)],[r*(7-3),r*(8-3)]],
        [[r*(5-4),r*(6-4)],[r*(7-4),r*(8-4)]]],
        ])
     x = distance(
         np.zeros((2, 2)), np.array([[1, 2], [3, 4]]),
         np.zeros((2, 2)), np.array([[5, 6], [7, 8]]),
         )
     self.assertTrue(np.array_equal(np.round(x, 7), np.round(a, 7)))
示例#3
0
 def test_discretize(self):
     """
     """
     lon1, lat1 = 0, 0
     lon2, lat2 = 90, 0
     l = Line(lon1, lat1, lon2, lat2)
     s = distance(lon1, lat1, lon2, lat2)
     lons, lats = l.discretize(s / 90)
     self.assertTrue(np.array_equal(np.round(lons, 9), np.round([i for i in range(0, 91)], 9)))