Пример #1
0
class TestTemplateTileLayout(unittest.TestCase):

    def setUp(self):
        self.tilelayout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')

    def test_filename(self):
        self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), '1/2/3')

    def test_tilecoord(self):
        self.assertEqual(self.tilelayout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
Пример #2
0
class TestTemplateTileLayout(unittest.TestCase):
    def setUp(self):
        self.tilelayout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')

    def test_filename(self):
        self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), '1/2/3')

    def test_tilecoord(self):
        self.assertEqual(self.tilelayout.tilecoord('1/2/3'),
                         TileCoord(1, 2, 3))
Пример #3
0
 def setUp(self):
     self.tilelayout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')
Пример #4
0
    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')
Пример #5
0
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')
Пример #6
0
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')
Пример #7
0
from tilebox.layout.template import TemplateTileLayout
from tilebox.store.url import URLTileStore

tilestore = URLTileStore(
    (TemplateTileLayout(
        'http://%s.tile.stamen.com/toner/%%(z)d/%%(x)d/%%(y)d.png' % 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/png')
Пример #8
0
 def setUp(self):
     self.tilelayout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')
Пример #9
0
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='&copy; OpenStreetMap contributors, CC-BY-SA',
    content_type='image/png')
Пример #10
0
from tilebox.layout.template import TemplateTileLayout
from tilebox.store.url import URLTileStore

tilestore = URLTileStore(
    (TemplateTileLayout(
        'http://%s.tile.stamen.com/watercolor/%%(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')