Example #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])
Example #2
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])
Example #3
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])
Example #4
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])
Example #5
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])
Example #6
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)
Example #7
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)
Example #8
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])
Example #9
0
 def test_one(self):
     tilestore = MBTilesTileStore(sqlite3.connect(':memory:'),
                                  content_type='image/png')
     self.assertEqual(len(tilestore), 0)
     tilestream = [
         Tile(TileCoord(1, 0, 0), data='data'), None,
         Tile(TileCoord(1, 0, 1), error=True)
     ]
     tilestream = tilestore.put(tilestream)
     tiles = list(tilestream)
     self.assertEqual(len(tilestore), 2)
     self.assertEqual(len(tiles), 2)
     self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
     self.assertEqual(tiles[0].data, 'data')
     self.assertEqual(tiles[1].tilecoord, TileCoord(1, 0, 1))
     self.assertEqual(tiles[1].error, True)
     self.assertTrue(Tile(TileCoord(1, 0, 0)) in tilestore)
     self.assertTrue(Tile(TileCoord(1, 0, 1)) in tilestore)
     tilestream = [Tile(TileCoord(1, 0, 0)), Tile(TileCoord(1, 0, 1))]
     tilestream = tilestore.get(tilestream)
     consume(tilestream, None)
     self.assertEqual(tilestore.get_cheap_bounding_pyramid(),
                      BoundingPyramid({1: (Bounds(0, 1), Bounds(0, 2))}))
     self.assertEqual(len(tilestore), 2)
     tiles = list(tilestore.list())
     self.assertEqual(len(tiles), 2)
     tiles = sorted(tilestore.get_all())
     self.assertEqual(len(tiles), 2)
     self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
     self.assertEqual(str(tiles[0].data), 'data')
     self.assertEqual(tiles[1].tilecoord, TileCoord(1, 0, 1))
     self.assertEqual(tiles[1].data, None)
     tilestream = [Tile(TileCoord(1, 0, 0))]
     tilestream = tilestore.delete(tilestream)
     consume(tilestream, None)
     self.assertEqual(len(tilestore), 1)
     tiles = list(tilestore.get_all())
     self.assertEqual(len(tiles), 1)
     self.assertFalse(Tile(TileCoord(1, 0, 0)) in tilestore)
     self.assertTrue(Tile(TileCoord(1, 0, 1)) in tilestore)
Example #10
0
 def test_full(self):
     bp = BoundingPyramid.full(1, 3)
     self.assertRaises(KeyError, bp.zget, 0)
     self.assertEqual(bp.zget(1), (Bounds(0, 2), Bounds(0, 2)))
     self.assertEqual(bp.zget(2), (Bounds(0, 4), Bounds(0, 4)))
     self.assertEqual(bp.zget(3), (Bounds(0, 8), Bounds(0, 8)))
     self.assertRaises(KeyError, bp.zget, 4)
Example #11
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])
Example #12
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])
Example #13
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])
Example #14
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])
Example #15
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)
Example #16
0
 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)))
Example #17
0
 def test_from_string_one_level(self):
     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)
Example #18
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])
Example #19
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)
Example #20
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)
Example #21
0
 def test_init_two_arguments(self):
     bounds = Bounds(1, 3)
     self.assertEquals(len(bounds), 2)
     self.assertEquals(list(bounds), [1, 2])
Example #22
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])
Example #23
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)
Example #24
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))}))
Example #25
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)
Example #26
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)))
Example #27
0
 def fill_down(self, z, bounds):
     xbounds, ybounds = bounds
     return (Bounds(2 * xbounds.start, 2 * xbounds.stop),
             Bounds(2 * ybounds.start, 2 * ybounds.stop))
Example #28
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)))
Example #29
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)))
Example #30
0
 def fill_up(self, 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)))
Example #31
0
 def test_init_one_argument(self):
     bounds = Bounds(1)
     self.assertEquals(len(bounds), 1)
     self.assertEquals(list(bounds), [1])