Beispiel #1
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)
Beispiel #2
0
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)
Beispiel #3
0
 def test_load_s3(self):
     from tilecloud.store.s3 import S3TileStore
     self.assertTrue(isinstance(TileStore.load('s3://bucket/template'), S3TileStore))
Beispiel #4
0
 def test_load_https(self):
     from tilecloud.store.url import URLTileStore
     self.assertTrue(isinstance(TileStore.load('https://'), URLTileStore))
Beispiel #5
0
 def test_load_null(self):
     self.assertTrue(isinstance(TileStore.load('null://'), NullTileStore))
Beispiel #6
0
    def get(self, request, userid=None, mapname=None):
        z = int(request.GET.get('l'))
        x = int(request.GET.get('x'))
        y = int(request.GET.get('y'))
        token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNTk1MjkyMzk5LCJleHAiOjE1OTc4ODQzOTksInVzZXJfaWQiOjF9.IulCkLFv4GtBf6BXfRozgyMHbA0GEEUhx5br-5qDtVo'#request.GET.get('access_token')
        if token:
            user = check_user(check_payload(token))
            if user.id == userid:
                maps = Map.objects.filter(name=mapname, creator_id=userid)
                mapdatastr = maps[0].map_data
                mapdataids = [int(v) for v in mapdatastr.split(',')]
                for mapdataid in mapdataids:
                    # , author=request.user
                    mapdata = MapData.objects.filter(id=mapdataid, author_id=userid)
                    dbfile = mapdata[0].save_path
                    content_type_adder = ContentTypeAdder()
                    # tilestore = TileStore.load(dbfile)
                    tilestore = TileStore.load('/work/cstd/rong/cstddataplatform/media/upload/202006/1/chn16y20191591065855765.mbtiles')
                    if tilestore is None:
                        HttpResponse(404)
                    else:
                        tilecoord = TileCoord(z, x, y)
                        tile = Tile(tilecoord)
                        tile = tilestore.get_one(tile)
                        if tile is None:
                            HttpResponse(404)
                        if tile.data is None:
                            HttpResponse(404)

                        tile = content_type_adder(tile)

                        # if tile.content_type is not None:
                        #     response = HttpResponse(tile.data, content_type=tile.content_type)
                        #     response['Access-Control-Allow-Origin'] = "*"
                        # if tile.content_encoding is not None:
                        #     bottle.response.set_header('Content-Encoding', tile.content_encoding)
                        response = HttpResponse(tile.data, content_type=tile.content_type)
                        response['Access-Control-Allow-Origin'] = "*"
                        return response
        elif request.user.id == userid:
            maps = Map.objects.filter(name=mapname, creator_id=userid)
            mapdatastr = maps[0].map_data
            mapdataids = [int(v) for v in mapdatastr.split(',')]
            for mapdataid in mapdataids:
                # , author=request.user
                mapdata = MapData.objects.filter(id=mapdataid, author_id=userid)
                dbfile = mapdata[0].save_path
                content_type_adder = ContentTypeAdder()
                tilestore = TileStore.load(dbfile)
                if tilestore is None:
                    HttpResponse(404)
                else:
                    tilecoord = TileCoord(z, x, y)
                    tile = Tile(tilecoord)
                    tile = tilestore.get_one(tile)
                    if tile is None:
                        HttpResponse(404)
                    if tile.data is None:
                        HttpResponse(404)

                    tile = content_type_adder(tile)

                    # if tile.content_type is not None:
                    #     response = HttpResponse(tile.data, content_type=tile.content_type)
                    #     response['Access-Control-Allow-Origin'] = "*"
                    # if tile.content_encoding is not None:
                    #     bottle.response.set_header('Content-Encoding', tile.content_encoding)
                    response = HttpResponse(tile.data, content_type=tile.content_type)
                    response['Access-Control-Allow-Origin'] = "*"
                    return response
        elif request.auth:
            user = check_user(check_payload(request.auth))
            if user.id == userid:
                maps = Map.objects.filter(name=mapname, creator_id=userid)
                mapdatastr = maps[0].map_data
                mapdataids = [int(v) for v in mapdatastr.split(',')]
                for mapdataid in mapdataids:
                    # , author=request.user
                    mapdata = MapData.objects.filter(id=mapdataid, author_id=userid)
                    dbfile = mapdata[0].save_path
                    content_type_adder = ContentTypeAdder()
                    tilestore = TileStore.load(dbfile)
                    if tilestore is None:
                        HttpResponse(404)
                    else:
                        tilecoord = TileCoord(z, x, y)
                        tile = Tile(tilecoord)
                        tile = tilestore.get_one(tile)
                        if tile is None:
                            HttpResponse(404)
                        if tile.data is None:
                            HttpResponse(404)

                        tile = content_type_adder(tile)

                        # if tile.content_type is not None:
                        #     response = HttpResponse(tile.data, content_type=tile.content_type)
                        #     response['Access-Control-Allow-Origin'] = "*"
                        # if tile.content_encoding is not None:
                        #     bottle.response.set_header('Content-Encoding', tile.content_encoding)
                        response = HttpResponse(tile.data, content_type=tile.content_type)
                        response['Access-Control-Allow-Origin'] = "*"
                        return response
        else:
            return JsonResponse({'error': 'no authority'}, status=400)
Beispiel #7
0
 def test_load_s3(self):
     from tilecloud.store.s3 import S3TileStore
     self.assertTrue(
         isinstance(TileStore.load('s3://bucket/template'), S3TileStore))
Beispiel #8
0
 def test_load_https(self):
     from tilecloud.store.url import URLTileStore
     self.assertTrue(isinstance(TileStore.load('https://'), URLTileStore))
Beispiel #9
0
 def test_load_null(self):
     self.assertTrue(isinstance(TileStore.load('null://'), NullTileStore))
Beispiel #10
0
    def test_load_http(self) -> None:
        from tilecloud.store.url import URLTileStore

        self.assertTrue(isinstance(TileStore.load("http://"), URLTileStore))
Beispiel #11
0
 def test_load_null(self) -> None:
     self.assertTrue(isinstance(TileStore.load("null://"), NullTileStore))
Beispiel #12
0
import os
import sqlite3

from tilecloud import Tile, TileCoord, consume, TileStore
from tilecloud.filter.contenttype import ContentTypeAdder
from tilecloud.store.mbtiles import MBTilesTileStore

args = ['/work/data/mbtiles/chn16y2019.mbtiles']

tilestores = [(os.path.basename(arg), TileStore.load(arg)) for arg in args]
tile = Tile(TileCoord(11, 1439, 794))
# lengths = len(tilestores[0][1])
# print(lengths)
tile = tilestores[0][1].get_one(tile)
print(tile)
with open('ssss.png', 'wb') as file:
    file.write(tile.data)

aa = '6/10/40'
bb = (aa, )
print(bb)
# tilestore = MBTilesTileStore(sqlite3.connect('/work/data/mbtiles/road-trip-wilderness.mbtiles'))
# lengths = len(tilestore)
# print(lengths)
# # 13/3104/6747
# # tilestream = [Tile(TileCoord(1, 0, 0), data=b'data'), None, Tile(TileCoord(1, 0, 1), error=True)]
# # tilestream = [Tile(TileCoord(13, 3104, 6747)), Tile(TileCoord(13, 3104, 6748))]
# # tilestore = MBTilesTileStore(sqlite3.connect(':memory:'), content_type='image/png')
# # , Tile(TileCoord(11, 1439, 795))
# tile = Tile(TileCoord(6, 10, 40))
# tile = tilestore.get_one(tile)