Example #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)
Example #2
0
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)
Example #3
0
 def test_arcgiscache_path(self):
     template = TileURLTemplate(TESTSERVER_URL + '/%(arcgiscache_path)s.png')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/L09/R0000000d/C00000005.png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
Example #4
0
 def test_xyz(self):
     template = TileURLTemplate(TESTSERVER_URL + '/x=%(x)s&y=%(y)s&z=%(z)s&format=%(format)s')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/x=5&y=13&z=9&format=png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
Example #5
0
 def test_arcgiscache_path(self):
     template = TileURLTemplate(TESTSERVER_URL + '/%(arcgiscache_path)s.png')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/L09/R0000000d/C00000005.png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         assert resp == b'tile'
Example #6
0
 def test_xyz(self):
     template = TileURLTemplate(TESTSERVER_URL + '/x=%(x)s&y=%(y)s&z=%(z)s&format=%(format)s')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/x=5&y=13&z=9&format=png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         assert resp == b'tile'
Example #7
0
 def test_bbox(self):
     grid = tile_grid(4326)
     template = TileURLTemplate(TESTSERVER_URL + '/service?BBOX=%(bbox)s')
     client = TileClient(template, grid=grid)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?BBOX=-180.00000000,0.00000000,-90.00000000,90.00000000'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((0, 1, 2)).source.read()
         eq_(resp, b'tile')
Example #8
0
 def test_bbox(self):
     grid = tile_grid(4326)
     template = TileURLTemplate(TESTSERVER_URL + '/service?BBOX=%(bbox)s')
     client = TileClient(template, grid=grid)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?BBOX=-180.00000000,0.00000000,-90.00000000,90.00000000'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((0, 1, 2)).source.read()
         assert resp == b'tile'
Example #9
0
 def test_tc_path(self):
     template = TileURLTemplate(TESTSERVER_URL + '/%(tc_path)s.png')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS,
                     [({
                         'path': '/09/000/000/005/000/000/013.png'
                     }, {
                         'body': b'tile',
                         'headers': {
                             'content-type': 'image/png'
                         }
                     })]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
Example #10
0
 def test_quadkey(self):
     template = TileURLTemplate(TESTSERVER_URL +
                                '/key=%(quadkey)s&format=%(format)s')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS,
                     [({
                         'path': '/key=000002303&format=png'
                     }, {
                         'body': b'tile',
                         'headers': {
                             'content-type': 'image/png'
                         }
                     })]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
Example #11
0
 def setup(self):
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = TileClient(TileURLTemplate(TESTSERVER_URL))