Exemple #1
0
def create_source(raster_source, app_state):
    url = raster_source.url
    username = raster_source.username
    password = raster_source.password

    http_client = HTTPClient(url, username, password)
                            # , insecure=insecure,
                             # ssl_ca_certs=ssl_ca_certs, timeout=timeout,
                             # headers=headers)

    grid = DEFAULT_GRID
    image_opts = None
    coverage = coverage_from_geojson(raster_source.download_coverage)
    format = raster_source.format

    url_template = TileURLTemplate(
        '%s/%s/%s-%%(z)s-%%(x)s-%%(y)s/tile' % (url, raster_source.layer, raster_source.matrix_set),
        format=format)
    client = TileClient(url_template, http_client=http_client, grid=grid)

    if app_state.tilebox.is_running():
        port = app_state.config.get('tilebox', 'port')
        url_template = TileURLTemplate(
            'http://127.0.0.1:%d/%s/%s-%%(z)s-%%(x)s-%%(y)s/tile' % (port, raster_source.layer, raster_source.matrix_set),
            format=format)
        tilebox_client =  TileClient(url_template, http_client=RequestsHTTPClient(), grid=grid)
        client = FallbackTileClient(tilebox_client, client)

    return TiledSource(grid, client, coverage=coverage, image_opts=image_opts)
    def test_image_response(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=False)
        self.source = TiledSource(self.grid,
                                  self.client,
                                  error_handler=error_handler)

        with mock_httpd(
                TEST_SERVER_ADDRESS,
            [(
                {
                    "path": "/1/0/0.png"
                },
                {
                    "body": b"error",
                    "status": 500,
                    "headers": {
                        "content-type": "text/plain"
                    },
                },
            )],
        ):
            resp = self.source.get_map(
                MapQuery([-180, -90, 0, 90], (256, 256),
                         SRS(4326),
                         format="png"))
            assert not resp.cacheable
            assert resp.as_image().getcolors() == [((256 * 256), (255, 0, 0))]
Exemple #3
0
 def setup(self):
     self.cache_dir = tempfile.mkdtemp()
     self.file_cache = FileCache(cache_dir=self.cache_dir, file_ext='png')
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png')
def create_wmts_source(raster_source, app_state):
    url = raster_source.url
    username = raster_source.username
    password = raster_source.password

    http_client = create_http_client(username, password)

    grid = DEFAULT_GRID
    image_opts = None
    coverage = coverage_from_geojson(raster_source.download_coverage)
    format = raster_source.format

    tpl_url = url.replace('{TileMatrix}', '%(z)s')
    tpl_url = tpl_url.replace('{TileCol}', '%(x)s')
    tpl_url = tpl_url.replace('{TileRow}', '%(y)s')

    url_template = TileURLTemplate(tpl_url, format=format)
    client = TileClient(url_template, http_client=http_client, grid=grid)

    if app_state.tilebox.is_running():
        port = app_state.config.get('tilebox', 'port')
        url_template = TileURLTemplate(
            'http://127.0.0.1:%d/%s/%s-%%(z)s-%%(x)s-%%(y)s/tile' %
            (port, raster_source.layer, raster_source.matrix_set),
            format=format)
        tilebox_client = TileClient(url_template,
                                    http_client=RequestsHTTPClient(),
                                    grid=grid)
        client = FallbackTileClient(tilebox_client, client)

    return TiledSource(grid, client, coverage=coverage, image_opts=image_opts)
Exemple #5
0
 def tile_mgr(self, tile_locker, mock_file_cache, mock_tile_client):
     grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     source = TiledSource(grid, mock_tile_client)
     image_opts = ImageOptions(format='image/png')
     return TileManager(grid, mock_file_cache, [source], 'png',
         image_opts=image_opts,
         locker=tile_locker,
     )
Exemple #6
0
 def setup(self):
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.source = TiledSource(self.grid, None)
     self.tile_mgr = TileManager(self.grid,
                                 MockCache(), [self.source],
                                 "png",
                                 locker=DummyLocker())
     self.seed_pool = MockSeedPool()
Exemple #7
0
 def setup(self):
     self.file_cache = MockFileCache('/dev/null', 'png', lock_dir=tmp_lock_dir)
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
     self.image_opts = ImageOptions(format='image/png')
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         image_opts=self.image_opts)
Exemple #8
0
 def tile_mgr(self, file_cache, tile_locker):
     grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     client = MockTileClient()
     source = TiledSource(grid, client)
     tile_mgr = TileManager(grid,
                            file_cache, [source],
                            'png',
                            locker=tile_locker)
     return tile_mgr
Exemple #9
0
    def test_image_response(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=False)
        self.source = TiledSource(self.grid, self.client, error_handler=error_handler)

        with mock_httpd(TEST_SERVER_ADDRESS, [({'path': '/1/0/0.png'},
                                                {'body': b'error', 'status': 500, 'headers':{'content-type': 'text/plain'}})]):
            resp = self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326), format='png'))
            assert not resp.cacheable
            eq_(resp.as_image().getcolors(), [((256*256), (255, 0, 0))])
Exemple #10
0
 def setup(self):
     self.cache_dir = tempfile.mkdtemp()
     self.file_cache = FileCache(cache_dir=self.cache_dir, file_ext='png')
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
     self.image_opts = ImageOptions(format='image/png')
     self.locker = TileLocker(tmp_lock_dir, 10, "id")
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         image_opts=self.image_opts,
         locker=self.locker)
Exemple #11
0
 def setup(self):
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)