Exemple #1
0
 def test_union_empty_normal(self):
     bounds1 = Bounds()
     bounds2 = Bounds(3, 5)
     bounds3 = bounds1.union(bounds2)
     self.assertTrue(bounds3 is not bounds1)
     self.assertTrue(bounds3 is not bounds2)
     self.assertEquals(list(bounds3), [3, 4])
Exemple #2
0
 def test_union_normal_empty(self):
     bounds1 = Bounds(1, 3)
     bounds2 = Bounds()
     bounds3 = bounds1.union(bounds2)
     self.assertTrue(bounds3 is not bounds1)
     self.assertTrue(bounds3 is not bounds2)
     self.assertEquals(list(bounds3), [1, 2])
Exemple #3
0
 def test_union_empty_empty(self):
     bounds1 = Bounds()
     bounds2 = Bounds()
     bounds3 = bounds1.union(bounds2)
     self.assertTrue(bounds3 is not bounds1)
     self.assertTrue(bounds3 is not bounds2)
     self.assertEquals(len(bounds3), 0)
Exemple #4
0
 def test_union_normal_normal(self):
     bounds1 = Bounds(1, 3)
     bounds2 = Bounds(3, 5)
     bounds3 = bounds1.union(bounds2)
     self.assertTrue(bounds3 is not bounds1)
     self.assertTrue(bounds3 is not bounds2)
     self.assertEquals(list(bounds3), [1, 2, 3, 4])
Exemple #5
0
 def test_add(self):
     bounds = Bounds()
     self.assertEquals(len(bounds), 0)
     bounds.add(1)
     self.assertTrue(1 in bounds)
     self.assertFalse(2 in bounds)
     self.assertEquals(len(bounds), 1)
     self.assertEquals(list(bounds), [1])
     bounds.add(1)
     self.assertTrue(1 in bounds)
     self.assertFalse(2 in bounds)
     self.assertEquals(len(bounds), 1)
     self.assertEquals(list(bounds), [1])
     bounds.add(2)
     self.assertTrue(1 in bounds)
     self.assertTrue(2 in bounds)
     self.assertEquals(len(bounds), 2)
     self.assertEquals(list(bounds), [1, 2])
Exemple #6
0
 def fill_down(z, bounds):
     xbounds, ybounds = bounds
     return (Bounds(2 * xbounds.start, 2 * xbounds.stop),
             Bounds(2 * ybounds.start, 2 * ybounds.stop))
Exemple #7
0
 def test_from_string_one_level(self) -> None:
     bp = BoundingPyramid.from_string("5/9/13:12/15")
     self.assertRaises(KeyError, bp.zget, 4)
     self.assertEqual(bp.zget(5), (Bounds(9, 12), Bounds(13, 15)))
     self.assertRaises(KeyError, bp.zget, 6)
Exemple #8
0
 def get_cheap_bounding_pyramid(self):
     bounds = {}
     for z, xstart, xstop, ystart, ystop in query(
             self.connection, self.BOUNDING_PYRAMID_SQL):
         bounds[z] = (Bounds(xstart, xstop), Bounds(ystart, ystop))
     return BoundingPyramid(bounds)
Exemple #9
0
 def test_update_empty(self):
     bounds1 = Bounds()
     bounds2 = Bounds(3, 5)
     assert bounds1.update(bounds2) is bounds1
     assert list(bounds1) == [3, 4]
Exemple #10
0
 def test_fill_down(self):
     bp = BoundingPyramid()
     bp.add(TileCoord(1, 1, 0))
     bp.fill_down(3)
     self.assertEqual(bp.zget(2), (Bounds(2, 4), Bounds(0, 2)))
     self.assertEqual(bp.zget(3), (Bounds(4, 8), Bounds(0, 4)))
Exemple #11
0
 def test_eq(self):
     self.assertEqual(BoundingPyramid(), BoundingPyramid())
     self.assertEqual(BoundingPyramid({5: (Bounds(2, 5), Bounds(6, 15))}),
                      BoundingPyramid({5: (Bounds(2, 5), Bounds(6, 15))}))
Exemple #12
0
 def test_update_empty(self):
     bounds1 = Bounds()
     bounds2 = Bounds(3, 5)
     self.assertTrue(bounds1.update(bounds2) is bounds1)
     self.assertEquals(len(bounds1), 2)
     self.assertEquals(list(bounds1), [3, 4])
Exemple #13
0
 def test_update(self):
     bounds1 = Bounds(1, 3)
     bounds2 = Bounds(3, 5)
     self.assertTrue(bounds1.update(bounds2) is bounds1)
     self.assertEquals(len(bounds1), 4)
     self.assertEquals(list(bounds1), [1, 2, 3, 4])
Exemple #14
0
 def test_init_two_arguments(self):
     bounds = Bounds(1, 3)
     self.assertEquals(len(bounds), 2)
     self.assertEquals(list(bounds), [1, 2])
Exemple #15
0
 def test_init_one_argument(self):
     bounds = Bounds(1)
     self.assertEquals(len(bounds), 1)
     self.assertEquals(list(bounds), [1])
Exemple #16
0
 def test_empty(self):
     bounds = Bounds()
     assert len(bounds) == 0
     assert 1 not in bounds
     self.assertRaises(StopIteration, next, iter(bounds))
     assert bounds == bounds
Exemple #17
0
 def fill_up(z, bounds):
     assert z > 0
     xbounds, ybounds = bounds
     return (Bounds(xbounds.start // 2, max(xbounds.stop // 2, 1)),
             Bounds(ybounds.start // 2, max(ybounds.stop // 2, 1)))
Exemple #18
0
 def test_empty(self):
     bounds = Bounds()
     self.assertEquals(len(bounds), 0)
     self.assertFalse(1 in bounds)
     self.assertRaises(StopIteration, next, iter(bounds))
     self.assertTrue(bounds == bounds)
Exemple #19
0
 def test_from_string_up(self):
     bp = BoundingPyramid.from_string('2/1/3:0/2/4')
     self.assertEqual(bp.zget(0), (Bounds(0, 1), Bounds(0, 1)))
     self.assertEqual(bp.zget(1), (Bounds(0, 1), Bounds(1, 2)))
     self.assertEqual(bp.zget(2), (Bounds(1, 2), Bounds(3, 4)))
     self.assertRaises(KeyError, bp.zget, 3)
Exemple #20
0
 def test_from_string_star(self):
     bp = BoundingPyramid.from_string('0/0/0:2/*/*')
     self.assertEqual(bp.zget(0), (Bounds(0, 1), Bounds(0, 1)))
     self.assertEqual(bp.zget(1), (Bounds(0, 2), Bounds(0, 2)))
     self.assertEqual(bp.zget(2), (Bounds(0, 4), Bounds(0, 4)))
     self.assertRaises(KeyError, bp.zget, 3)
Exemple #21
0
 def test_fill(self):
     bp = BoundingPyramid()
     bp.fill(xrange(0, 8), (572215.4395248143, 5684416.95917649,
                            1277662.36597472, 6145307.39552287))
     self.assertEqual(bp.zget(0), (Bounds(0, 1), Bounds(0, 1)))
     self.assertEqual(bp.zget(1), (Bounds(1, 2), Bounds(0, 1)))
     self.assertEqual(bp.zget(2), (Bounds(2, 3), Bounds(1, 2)))
     self.assertEqual(bp.zget(3), (Bounds(4, 5), Bounds(2, 3)))
     self.assertEqual(bp.zget(4), (Bounds(8, 9), Bounds(5, 6)))
     self.assertEqual(bp.zget(5), (Bounds(16, 18), Bounds(11, 12)))
     self.assertEqual(bp.zget(6), (Bounds(32, 35), Bounds(22, 23)))
     self.assertEqual(bp.zget(7), (Bounds(65, 69), Bounds(44, 46)))
Exemple #22
0
 def test_init_one_argument(self):
     bounds = Bounds(1)
     assert list(bounds) == [1]
Exemple #23
0
 def test_fill_up2(self):
     bp = BoundingPyramid({1: (Bounds(0, 2), Bounds(1, 2))})
     bp.add(TileCoord(2, 1, 3))
     bp.fill_up(0)
     self.assertEqual(bp.zget(1), (Bounds(0, 2), Bounds(1, 2)))
     self.assertEqual(bp.zget(0), (Bounds(0, 1), Bounds(0, 1)))
Exemple #24
0
 def test_init_two_arguments(self):
     bounds = Bounds(1, 3)
     assert list(bounds) == [1, 2]
Exemple #25
0
 def test_from_string_relative(self):
     bp = BoundingPyramid.from_string('2/1/3:+1/+1/+1')
     self.assertRaises(KeyError, bp.zget, 1)
     self.assertEqual(bp.zget(2), (Bounds(1, 2), Bounds(3, 4)))
     self.assertEqual(bp.zget(3), (Bounds(2, 4), Bounds(6, 8)))
     self.assertRaises(KeyError, bp.zget, 4)
 def test_hash_metatile(self):
     bp = BoundingPyramid({4: (Bounds(0, 16), Bounds(0, 16))})
     metatilecoords = list(bp.metatilecoords(2))
     hashes = map(hash, metatilecoords)
     self.assertEqual(len(metatilecoords), len(set(hashes)))