示例#1
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()))
示例#2
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()))
示例#3
0
class RenderingTheWorldTileStore(TileStore):
    """http://mapbox.com/blog/rendering-the-world/"""

    def __init__(self, subdivide, tilegrid=None, queue=None, seeds=()):
        self.subdivide = subdivide
        self.tilegrid = tilegrid
        if self.tilegrid is None:
            self.tilegrid = QuadTileGrid()
        self.queue = queue
        if self.queue is None:
            self.queue = deque()
        for seed in seeds:
            self.queue.append(seed)

    def list(self):
        try:
            while True:
                yield self.queue.popleft()
        except IndexError:
            pass

    def put_one(self, tile):
        if self.subdivide(tile):
            for tilecoord in self.tilegrid.children(tile.tilecoord):
                self.queue.append(Tile(tilecoord))
        return tile
示例#4
0
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))
示例#5
0
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))