Esempio n. 1
0
class TestFreeQuadTileStructureEquivalence(unittest.TestCase):

    def setUp(self):
        self.fts = FreeTileStructure([8, 4, 2, 1], tile_size=0.125)
        self.qts = QuadTileStructure(max_zoom=3)

    def test_children(self):
        tc = TileCoord(2, 2, 3)
        self.assertEqual(sorted(self.fts.children(tc)), sorted(self.qts.children(tc)))

    def test_children_root(self):
        tc = TileCoord(0, 0, 0)
        self.assertEqual(sorted(self.fts.children(tc)), sorted(self.qts.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.fts.extent(tilecoord), self.qts.extent(tilecoord))

    def test_parent(self):
        tc = TileCoord(3, 3, 5)
        self.assertEqual(self.fts.parent(tc), self.qts.parent(tc))

    def test_roots(self):
        self.assertEqual(list(self.fts.roots()), list(self.qts.roots()))
Esempio n. 2
0
class TestQuadTileStructureFlipY(unittest.TestCase):

    def setUp(self):
        self.qtsn = QuadTileStructure()
        self.qtsf = QuadTileStructure(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)))
Esempio n. 3
0
class RenderingTheWorldTileStore(TileStore):
    """http://mapbox.com/blog/rendering-the-world/"""

    def __init__(self, subdivide, tilestructure=None, queue=None, seeds=()):
        self.subdivide = subdivide
        self.tilestructure = tilestructure
        if self.tilestructure is None:
            self.tilestructure = QuadTileStructure()
        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.tilestructure.children(tile.tilecoord):
                self.queue.append(Tile(tilecoord))
        return tile
Esempio n. 4
0
 def __init__(self, subdivide, tilestructure=None, queue=None, seeds=()):
     self.subdivide = subdivide
     self.tilestructure = tilestructure
     if self.tilestructure is None:
         self.tilestructure = QuadTileStructure()
     self.queue = queue
     if self.queue is None:
         self.queue = deque()
     for seed in seeds:
         self.queue.append(seed)
Esempio n. 5
0
 def setUp(self):
     self.qtsn = QuadTileStructure()
     self.qtsf = QuadTileStructure(flip_y=True)
Esempio n. 6
0
 def setUp(self):
     self.qts = QuadTileStructure(max_extent=(0.0, 1.0, 2.0, 3.0))
Esempio n. 7
0
class TestQuadTileStructure(unittest.TestCase):

    def setUp(self):
        self.qts = QuadTileStructure(max_extent=(0.0, 1.0, 2.0, 3.0))

    def test_children(self):
        self.assertEqual(sorted(self.qts.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.qts.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.qts.extent(TileCoord(0, 0, 0)), (0.0, 1.0, 2.0, 3.0))

    def test_extent_z1(self):
        self.assertEqual(self.qts.extent(TileCoord(1, 0, 0)), (0.0, 1.0, 1.0, 2.0))
        self.assertEqual(self.qts.extent(TileCoord(1, 0, 1)), (0.0, 2.0, 1.0, 3.0))
        self.assertEqual(self.qts.extent(TileCoord(1, 1, 0)), (1.0, 1.0, 2.0, 2.0))
        self.assertEqual(self.qts.extent(TileCoord(1, 1, 1)), (1.0, 2.0, 2.0, 3.0))

    def test_extent_z2(self):
        self.assertEqual(self.qts.extent(TileCoord(2, 0, 0)), (0.0, 1.0, 0.5, 1.5))
        self.assertEqual(self.qts.extent(TileCoord(2, 1, 1)), (0.5, 1.5, 1.0, 2.0))
        self.assertEqual(self.qts.extent(TileCoord(2, 2, 2)), (1.0, 2.0, 1.5, 2.5))
        self.assertEqual(self.qts.extent(TileCoord(2, 3, 3)), (1.5, 2.5, 2.0, 3.0))

    def test_parent(self):
        self.assertEqual(self.qts.parent(TileCoord(5, 11, 21)), TileCoord(4, 5, 10))

    def test_parent_root(self):
        self.assertEqual(self.qts.parent(TileCoord(0, 0, 0)), None)

    def test_roots(self):
        self.assertEqual(list(self.qts.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.qts.extent(tilecoord)
                    self.assertEqual(self.qts.tilecoord(z, minx, miny), tilecoord)
Esempio n. 8
0
 def setUp(self):
     self.fts = FreeTileStructure([8, 4, 2, 1], tile_size=0.125)
     self.qts = QuadTileStructure(max_zoom=3)