Пример #1
0
 def test_add(self):
     bp = BoundingPyramid()
     bp.add(TileCoord(1, 0, 0))
     self.assertEqual(len(bp), 1)
     self.assertTrue(TileCoord(1, 0, 0) in bp)
     self.assertFalse(TileCoord(1, 0, 1) in bp)
     self.assertFalse(TileCoord(1, 1, 0) in bp)
     self.assertFalse(TileCoord(1, 1, 1) in bp)
     self.assertEqual(list(bp), [TileCoord(1, 0, 0)])
Пример #2
0
 def test_itertopdown(self):
     bp = BoundingPyramid()
     bp.add(TileCoord(2, 1, 3))
     bp.fill_up(0)
     self.assertEqual(
         list(bp.itertopdown()),
         [TileCoord(0, 0, 0),
          TileCoord(1, 0, 1),
          TileCoord(2, 1, 3)])
Пример #3
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)))
Пример #4
0
 def __init__(self, z, bounds, file=None, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.z = z
     self.xbounds, self.ybounds = bounds
     self.width = self.xbounds.stop - self.xbounds.start
     self.height = self.ybounds.stop - self.ybounds.start
     if 'bounding_pyramid' not in kwargs:
         self.bounding_pyramid = BoundingPyramid(
             {self.z: (self.xbounds, self.ybounds)})
     if file:
         self.image = PIL.Image.open(file)
         assert self.image.mode == '1'
         assert self.image.size == (self.width, self.height)
     else:
         self.image = PIL.Image.new('1', (self.width, self.height))
     self.pixels = self.image.load()
Пример #5
0
 def test_empty(self):
     ts = TileStore()
     self.assertEqual(ts.bounding_pyramid, None)
     self.assertEqual(ts.content_type, None)
     self.assertEqual(len(ts), 0)
     self.assertRaises(NotImplementedError, next,
                       ts.delete((Tile(TileCoord(0, 0, 0)), )))
     self.assertRaises(NotImplementedError, ts.delete_one, None)
     self.assertEqual(ts.get_cheap_bounding_pyramid(), None)
     self.assertRaises(NotImplementedError, next,
                       ts.get((Tile(TileCoord(0, 0, 0)), )))
     self.assertEqual(list(ts.get_all()), [])
     self.assertRaises(NotImplementedError, ts.get_one, None)
     self.assertEqual(list(ts.list()), [])
     self.assertRaises(NotImplementedError, next,
                       ts.put((Tile(TileCoord(0, 0, 0)), )))
     self.assertRaises(NotImplementedError, ts.put_one, None)
     self.assertFalse(None in ts)
     self.assertEqual(ts.get_bounding_pyramid(), BoundingPyramid())
Пример #6
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)
Пример #7
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)))
Пример #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)
Пример #9
0
 def test_zs(self):
     bp = BoundingPyramid()
     bp.add(TileCoord(2, 1, 3))
     bp.fill_up(0)
     self.assertEqual(sorted(bp.zs()), [0, 1, 2])
Пример #10
0
 def test_ziter(self):
     bp = BoundingPyramid()
     bp.add(TileCoord(2, 1, 3))
     bp.fill_up(0)
     self.assertEqual(list(bp.ziter(1)), [TileCoord(1, 0, 1)])
Пример #11
0
 def test_empty(self):
     bp = BoundingPyramid()
     self.assertEqual(len(bp), 0)
     self.assertFalse(TileCoord(0, 0, 0) in bp)
     self.assertRaises(StopIteration, next, iter(bp))
Пример #12
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)))
Пример #13
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)))
Пример #14
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))}))
Пример #15
0
 def __init__(self, bounding_pyramid=None, **kwargs):
     TileStore.__init__(self, **kwargs)
     self.bounding_pyramid = bounding_pyramid or BoundingPyramid()