本文整理汇总了Python中tilecloud.BoundingPyramid类的典型用法代码示例。如果您正苦于以下问题:Python BoundingPyramid类的具体用法?Python BoundingPyramid怎么用?Python BoundingPyramid使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BoundingPyramid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, tile_json, urls_key='tiles', **kwargs):
# FIXME schema
# FIXME version 1.0.0 support
d = json.loads(tile_json)
assert 'tiles' in d
assert isinstance(d['tiles'], list)
assert len(d['tiles']) > 0
for key in self.KEYS:
kwargs.setdefault(key, d.get(key, None))
if 'bounding_pyramid' not in kwargs:
zmin, zmax = d.get('minzoom', 0), d.get('maxzoom', 22)
if 'bounds' in d:
lonmin, latmin, lonmax, latmax = d['bounds']
bounding_pyramid = BoundingPyramid.from_wgs84(zmin, zmax,
lonmin, lonmax,
latmin, latmax)
else:
bounding_pyramid = BoundingPyramid.full(zmin, zmax)
kwargs['bounding_pyramid'] = bounding_pyramid
urls = d[urls_key]
if 'content_type' not in kwargs:
exts = set(os.path.splitext(urlparse(url).path)[1] for url in urls)
content_types = set(mimetypes.types_map.get(ext) for ext in exts)
assert len(content_types) == 1
kwargs['content_type'] = content_types.pop()
templates = [re.sub(r'\{([xyz])\}', lambda m: '%%(%s)d' % m.group(1), url)
for url in urls]
tile_layouts = map(TemplateTileLayout, templates)
URLTileStore.__init__(self, tile_layouts, **kwargs)
示例2: test_add
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)])
示例3: test_full
def test_full(self):
bp = BoundingPyramid.full(1, 3)
self.assertRaises(KeyError, bp.zget, 0)
self.assertEqual(bp.zget(1), (Bounds(0, 2), Bounds(0, 2)))
self.assertEqual(bp.zget(2), (Bounds(0, 4), Bounds(0, 4)))
self.assertEqual(bp.zget(3), (Bounds(0, 8), Bounds(0, 8)))
self.assertRaises(KeyError, bp.zget, 4)
示例4: test_metatilecoords
def test_metatilecoords(self):
bp = BoundingPyramid.full(1, 2)
metatilecoords = bp.metatilecoords(2)
self.assertEqual(TileCoord(1, 0, 0, 2), next(metatilecoords))
self.assertEqual(TileCoord(2, 0, 0, 2), next(metatilecoords))
self.assertEqual(TileCoord(2, 0, 2, 2), next(metatilecoords))
self.assertEqual(TileCoord(2, 2, 0, 2), next(metatilecoords))
self.assertEqual(TileCoord(2, 2, 2, 2), next(metatilecoords))
self.assertRaises(StopIteration, next, metatilecoords)
示例5: test_fill
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)))
示例6: main
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)
示例7: test_fillup
def test_fillup(self):
bp = BoundingPyramid()
bp.add(TileCoord(2, 1, 3))
bp.fillup(0)
self.assertEqual(bp.zget(1), (Bounds(0, 1), Bounds(1, 2)))
self.assertEqual(bp.zget(0), (Bounds(0, 1), Bounds(0, 1)))
示例8: test_from_string_up
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)
示例9: test_from_string_one_level
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)
示例10: test_from_string_relative
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)
示例11: test_from_string_star
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)
示例12: test_zs
def test_zs(self):
bp = BoundingPyramid()
bp.add(TileCoord(2, 1, 3))
bp.fillup(0)
self.assertEqual(sorted(bp.zs()), [0, 1, 2])
示例13: test_ziter
def test_ziter(self):
bp = BoundingPyramid()
bp.add(TileCoord(2, 1, 3))
bp.fillup(0)
self.assertEqual(list(bp.ziter(1)), [TileCoord(1, 0, 1)])
示例14: test_init_boundingpyramid
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))
示例15: test_filldown
def test_filldown(self):
bp = BoundingPyramid()
bp.add(TileCoord(1, 1, 0))
bp.filldown(3)
self.assertEqual(bp.zget(2), (Bounds(2, 4), Bounds(0, 2)))
self.assertEqual(bp.zget(3), (Bounds(4, 8), Bounds(0, 4)))