def test_init_boundingpyramid(self): ts = TileStore( bounding_pyramid=BoundingPyramid.from_string('1/0/0:1/1')) self.assertTrue(Tile(TileCoord(1, 0, 0)) in ts) tiles = list(ts.list()) self.assertEqual(len(tiles), 1) self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
def main(): # Create our input and output TileStores input_tilestore = TileStore.load('tiles.openstreetmap_org') output_tilestore = TileStore.load('local.mbtiles') # 1. Generate a list of tiles to download from a BoundingPyramid # 4/8/5 is the root tile, corresponding to Central Europe # +3/+1/+1 specifies up to zoom level 4 + 3 = 7 and an extent of one tile in the X and Y directions bounding_pyramid = BoundingPyramid.from_string('4/8/5:+3/+1/+1') bounding_pyramid_tilestore = BoundingPyramidTileStore(bounding_pyramid) tilestream = bounding_pyramid_tilestore.list() # 2. Filter out tiles that already downloaded tilestream = (tile for tile in tilestream if tile not in output_tilestore) # 3. Get the tile from openstreetmap.org tilestream = input_tilestore.get(tilestream) # 4. Save the tile to local.mbtiles tilestream = output_tilestore.put(tilestream) # 5. Log the fact that the tile was downloaded tilestream = imap(Logger(logger, logging.INFO, 'downloaded %(tilecoord)s'), tilestream) # Go! consume(tilestream, None)
def main(argv): # Create our input and output TileStores input_tilestore = TileStore.load('tiles.openstreetmap_org') output_tilestore = TileStore.load('local.mbtiles') # 1. Generate a list of tiles to download from a BoundingPyramid # 4/8/5 is the root tile, corresponding to Central Europe # +3/+1/+1 specifies up to zoom level 4 + 3 = 7 and an extent of one tile in the X and Y directions bounding_pyramid = BoundingPyramid.from_string('4/8/5:+3/+1/+1') bounding_pyramid_tilestore = BoundingPyramidTileStore(bounding_pyramid) tilestream = bounding_pyramid_tilestore.list() # 2. Filter out tiles that already downloaded tilestream = (tile for tile in tilestream if not tile in output_tilestore) # 3. Get the tile from openstreetmap.org tilestream = input_tilestore.get(tilestream) # 4. Save the tile to local.mbtiles tilestream = output_tilestore.put(tilestream) # 5. Log the fact that the tile was downloaded tilestream = imap(Logger(logger, logging.INFO, 'downloaded %(tilecoord)s'), tilestream) # Go! consume(tilestream, None)
def test_init_boundingpyramid(self): ts = TileStore(bounding_pyramid=BoundingPyramid.from_string('1/0/0:1/1')) self.assertTrue(Tile(TileCoord(1, 0, 0)) in ts) tiles = list(ts.list()) self.assertEqual(len(tiles), 1) self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 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)
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)
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)
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)
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)
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)
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)
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)