class TestQuadTileGridFlipY(unittest.TestCase): def setUp(self): self.qtsn = QuadTileGrid() self.qtsf = QuadTileGrid(flip_y=True) def test_flip_y(self): self.assertEqual(self.qtsn.extent(TileCoord(2, 0, 0)), self.qtsf.extent(TileCoord(2, 0, 3))) self.assertEqual(self.qtsn.extent(TileCoord(2, 1, 1)), self.qtsf.extent(TileCoord(2, 1, 2))) self.assertEqual(self.qtsn.extent(TileCoord(2, 2, 2)), self.qtsf.extent(TileCoord(2, 2, 1))) self.assertEqual(self.qtsn.extent(TileCoord(2, 3, 3)), self.qtsf.extent(TileCoord(2, 3, 0)))
class TestFreeQuadTileGridEquivalence(unittest.TestCase): def setUp(self): self.ftg = FreeTileGrid([8, 4, 2, 1], tile_size=0.125) self.qtg = QuadTileGrid(max_zoom=3) def test_children(self): tc = TileCoord(2, 2, 3) self.assertEqual(sorted(self.ftg.children(tc)), sorted(self.qtg.children(tc))) def test_children_root(self): tc = TileCoord(0, 0, 0) self.assertEqual(sorted(self.ftg.children(tc)), sorted(self.qtg.children(tc))) def test_extent(self): for z in xrange(0, 4): for x in xrange(0, 1 << z): for y in xrange(0, 1 << z): tilecoord = TileCoord(z, x, y) self.assertEqual(self.ftg.extent(tilecoord), self.qtg.extent(tilecoord)) def test_parent(self): tc = TileCoord(3, 3, 5) self.assertEqual(self.ftg.parent(tc), self.qtg.parent(tc)) def test_roots(self): self.assertEqual(list(self.ftg.roots()), list(self.qtg.roots())) def test_zs(self): self.assertEqual(list(self.ftg.zs()), list(self.qtg.zs()))
class TestQuadTileGrid(unittest.TestCase): def setUp(self): self.qtg = QuadTileGrid(max_extent=(0.0, 1.0, 2.0, 3.0)) def test_children(self): self.assertEqual(sorted(self.qtg.children(TileCoord(1, 2, 3))), [TileCoord(2, 4, 6), TileCoord(2, 4, 7), TileCoord(2, 5, 6), TileCoord(2, 5, 7)]) def test_children_root(self): self.assertEqual(sorted(self.qtg.children(TileCoord(0, 0, 0))), [TileCoord(1, 0, 0), TileCoord(1, 0, 1), TileCoord(1, 1, 0), TileCoord(1, 1, 1)]) def test_extent_z0(self): self.assertEqual(self.qtg.extent(TileCoord(0, 0, 0)), (0.0, 1.0, 2.0, 3.0)) def test_extent_z1(self): self.assertEqual(self.qtg.extent(TileCoord(1, 0, 0)), (0.0, 2.0, 1.0, 3.0)) self.assertEqual(self.qtg.extent(TileCoord(1, 0, 1)), (0.0, 1.0, 1.0, 2.0)) self.assertEqual(self.qtg.extent(TileCoord(1, 1, 0)), (1.0, 2.0, 2.0, 3.0)) self.assertEqual(self.qtg.extent(TileCoord(1, 1, 1)), (1.0, 1.0, 2.0, 2.0)) def test_extent_z2(self): self.assertEqual(self.qtg.extent(TileCoord(2, 0, 0)), (0.0, 2.5, 0.5, 3.0)) self.assertEqual(self.qtg.extent(TileCoord(2, 1, 1)), (0.5, 2.0, 1.0, 2.5)) self.assertEqual(self.qtg.extent(TileCoord(2, 2, 2)), (1.0, 1.5, 1.5, 2.0)) self.assertEqual(self.qtg.extent(TileCoord(2, 3, 3)), (1.5, 1.0, 2.0, 1.5)) def test_parent(self): self.assertEqual(self.qtg.parent(TileCoord(5, 11, 21)), TileCoord(4, 5, 10)) def test_parent_root(self): self.assertEqual(self.qtg.parent(TileCoord(0, 0, 0)), None) def test_roots(self): self.assertEqual(list(self.qtg.roots()), [TileCoord(0, 0, 0)]) def test_tilecoord(self): for z in xrange(0, 4): for x in xrange(0, 1 << z): for y in xrange(0, 1 << z): tilecoord = TileCoord(z, x, y) minx, miny, maxx, maxy = self.qtg.extent(tilecoord) self.assertEqual(self.qtg.tilecoord(z, minx, miny), tilecoord) def test_zs(self): self.assertEqual(list(islice(self.qtg.zs(), 50)), range(50))
class TestQuadTileGrid(unittest.TestCase): def setUp(self): self.qtg = QuadTileGrid(max_extent=(0.0, 1.0, 2.0, 3.0)) def test_children(self): self.assertEqual(sorted(self.qtg.children(TileCoord(1, 2, 3))), [ TileCoord(2, 4, 6), TileCoord(2, 4, 7), TileCoord(2, 5, 6), TileCoord(2, 5, 7) ]) def test_children_root(self): self.assertEqual(sorted(self.qtg.children(TileCoord(0, 0, 0))), [ TileCoord(1, 0, 0), TileCoord(1, 0, 1), TileCoord(1, 1, 0), TileCoord(1, 1, 1) ]) def test_extent_z0(self): self.assertEqual(self.qtg.extent(TileCoord(0, 0, 0)), (0.0, 1.0, 2.0, 3.0)) def test_extent_z1(self): self.assertEqual(self.qtg.extent(TileCoord(1, 0, 0)), (0.0, 2.0, 1.0, 3.0)) self.assertEqual(self.qtg.extent(TileCoord(1, 0, 1)), (0.0, 1.0, 1.0, 2.0)) self.assertEqual(self.qtg.extent(TileCoord(1, 1, 0)), (1.0, 2.0, 2.0, 3.0)) self.assertEqual(self.qtg.extent(TileCoord(1, 1, 1)), (1.0, 1.0, 2.0, 2.0)) def test_extent_z2(self): self.assertEqual(self.qtg.extent(TileCoord(2, 0, 0)), (0.0, 2.5, 0.5, 3.0)) self.assertEqual(self.qtg.extent(TileCoord(2, 1, 1)), (0.5, 2.0, 1.0, 2.5)) self.assertEqual(self.qtg.extent(TileCoord(2, 2, 2)), (1.0, 1.5, 1.5, 2.0)) self.assertEqual(self.qtg.extent(TileCoord(2, 3, 3)), (1.5, 1.0, 2.0, 1.5)) def test_parent(self): self.assertEqual(self.qtg.parent(TileCoord(5, 11, 21)), TileCoord(4, 5, 10)) def test_parent_root(self): self.assertEqual(self.qtg.parent(TileCoord(0, 0, 0)), None) def test_roots(self): self.assertEqual(list(self.qtg.roots()), [TileCoord(0, 0, 0)]) def test_tilecoord(self): for z in xrange(0, 4): for x in xrange(0, 1 << z): for y in xrange(0, 1 << z): tilecoord = TileCoord(z, x, y) minx, miny, maxx, maxy = self.qtg.extent(tilecoord) self.assertEqual(self.qtg.tilecoord(z, minx, miny), tilecoord) def test_zs(self): self.assertEqual(list(islice(self.qtg.zs(), 50)), range(50))