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(url1).path)[1] for url1 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), url2) for url2 in urls] tilelayouts = map(TemplateTileLayout, templates) URLTileStore.__init__(self, tilelayouts, **kwargs)
def __init__(self, url=None, layer=None, style=None, format=None, tile_matrix_set=None, tile_matrix=None, **kwargs): layout = WMTSTileLayout(url, layer, style, format, tile_matrix_set, tile_matrix) URLTileStore.__init__(self, (layout, ), **kwargs)
def load(cls, name): # pragma: no cover """ Construct a :class:`TileStore` from a name. :param name: Name :type name: string :rtype: :class:`TileStore` The following shortcuts are available: bounds://<bounding-pyramid> file://<template> http://<template> and https://<template> memcached://<server>:<port>/<template> s3://<bucket>/<template> sqs://<region>/<queue> mongodb://<connection>/<collection> <filename>.bsddb <filename>.mbtiles <filename>.zip <module> """ if name == 'null://': from tilebox.store.null import NullTileStore return NullTileStore() if name.startswith('bounds://'): from tilebox.store.boundingpyramid import BoundingPyramidTileStore return BoundingPyramidTileStore( BoundingPyramid.from_string(name[9:])) if name.startswith('file://'): from tilebox.layout.template import TemplateTileLayout from tilebox.store.filesystem import FilesystemTileStore return FilesystemTileStore(TemplateTileLayout(name[7:]), ) if name.startswith('http://') or name.startswith('https://'): from tilebox.layout.template import TemplateTileLayout from tilebox.store.url import URLTileStore return URLTileStore((TemplateTileLayout(name), )) if name.startswith('memcached://'): from tilebox.layout.template import TemplateTileLayout from tilebox.store.memcached import MemcachedTileStore from tilebox.lib.memcached import MemcachedClient server, template = name[12:].split('/', 1) host, port = server.split(':', 1) client = MemcachedClient(host, int(port)) return MemcachedTileStore(client, TemplateTileLayout(template)) if name.startswith('s3://'): from tilebox.layout.template import TemplateTileLayout from tilebox.store.s3 import S3TileStore bucket, template = name[5:].split('/', 1) return S3TileStore(bucket, TemplateTileLayout(template)) if name.startswith('mongodb://'): from tilebox.store.mongodb import MongoDbTileStore connection, database, collection = name[10:].split('/', 2) return MongoDbTileStore(connection, database, collection) if name.startswith('sqs://'): from tilebox.store.sqs import SQSTileStore import boto.sqs from boto.sqs.jsonmessage import JSONMessage region_name, queue_name = name[6:].split('/', 1) connection = boto.sqs.connect_to_region(region_name) queue = connection.create_queue(queue_name) queue.set_message_class(JSONMessage) return SQSTileStore(queue) root, ext = os.path.splitext(name) if ext == '.bsddb': import bsddb from tilebox.store.bsddb import BSDDBTileStore return BSDDBTileStore(bsddb.hashopen(name)) if ext == '.mbtiles': import sqlite3 from tilebox.store.mbtiles import MBTilesTileStore return MBTilesTileStore(sqlite3.connect(name)) if ext == '.tilelite': import sqlite3 from tilebox.store.tilelite import TileliteTileStore return TileliteTileStore(sqlite3.connect(name)) if ext == '.zip': import zipfile from tilebox.store.zip import ZipTileStore return ZipTileStore(zipfile.ZipFile(name, 'a')) module = __import__(name) components = name.split('.') module = reduce(lambda module, attr: getattr(module, attr), components[1:], module) return getattr(module, 'tilestore')
from tilebox.layout.template import TemplateTileLayout from tilebox.store.url import URLTileStore tilestore = URLTileStore( (TemplateTileLayout( 'http://%s.tile.stamen.com/terrain/%%(z)d/%%(x)d/%%(y)d.jpg' % server) for server in 'abcd'), attribution= 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.', content_type='image/jpg')
from tilebox.layout.template import TemplateTileLayout from tilebox.store.url import URLTileStore tilestore = URLTileStore( (TemplateTileLayout( 'http://otile%d.mqcdn.com/tiles/1.0.0/osm/%%(z)d/%%(x)d/%%(y)d.png' % i) for i in xrange(1, 5)), attribution= 'Data, imagery and map information provided by MapQuest, <a href="http://www.openstreetmap.org/">Open Street Map</a> and contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>.', content_type='image/png')
def __init__(self, url=None, layer=None, style=None, format=None, tile_matrix_set=None, tile_matrix=None, **kwargs): layout = WMTSTileLayout(url, layer, style, format, tile_matrix_set, tile_matrix) URLTileStore.__init__(self, (layout,), **kwargs)
from tilebox.layout.template import TemplateTileLayout from tilebox.store.url import URLTileStore tilestore = URLTileStore( (TemplateTileLayout( 'http://%s.tile.openstreetmap.org/%%(z)d/%%(x)d/%%(y)d.png' % server) for server in 'abc'), attribution='© OpenStreetMap contributors, CC-BY-SA', content_type='image/png')