Ejemplo n.º 1
0
 def __init__(self,
              root_layer,
              md,
              srs,
              image_formats,
              request_parser=None,
              tile_layers=None,
              attribution=None,
              info_types=None,
              strict=False,
              on_error='raise',
              concurrent_layer_renderer=1,
              max_output_pixels=None,
              bbox_srs=None,
              max_tile_age=None):
     Server.__init__(self)
     self.request_parser = request_parser or partial(wms_request,
                                                     strict=strict)
     self.root_layer = root_layer
     self.layers = root_layer.child_layers()
     self.tile_layers = tile_layers or {}
     self.strict = strict
     self.attribution = attribution
     self.md = md
     self.on_error = on_error
     self.concurrent_layer_renderer = concurrent_layer_renderer
     self.image_formats = image_formats
     self.info_types = info_types
     self.srs = srs
     self.bbox_srs = bbox_srs
     self.max_output_pixels = max_output_pixels
     self.max_tile_age = max_tile_age
Ejemplo n.º 2
0
 def __init__(
     self,
     root_layer,
     md,
     srs,
     image_formats,
     request_parser=None,
     tile_layers=None,
     attribution=None,
     info_types=None,
     strict=False,
     on_error="raise",
     concurrent_layer_renderer=1,
     max_output_pixels=None,
     bbox_srs=None,
     max_tile_age=None,
 ):
     Server.__init__(self)
     self.request_parser = request_parser or partial(wms_request, strict=strict)
     self.root_layer = root_layer
     self.layers = root_layer.child_layers()
     self.tile_layers = tile_layers or {}
     self.strict = strict
     self.attribution = attribution
     self.md = md
     self.on_error = on_error
     self.concurrent_layer_renderer = concurrent_layer_renderer
     self.image_formats = image_formats
     self.info_types = info_types
     self.srs = srs
     self.bbox_srs = bbox_srs
     self.max_output_pixels = max_output_pixels
     self.max_tile_age = max_tile_age
Ejemplo n.º 3
0
 def __init__(self, layers, md, request_parser=None):
     Server.__init__(self)
     self.request_parser = request_parser or wmts_request
     self.md = md
     self.max_tile_age = None # TODO
     self.layers, self.matrix_sets = self._matrix_sets(layers)
     self.capabilities_class = Capabilities
Ejemplo n.º 4
0
 def __init__(self, layers, md, request_parser=None, max_tile_age=None):
     Server.__init__(self)
     self.request_parser = request_parser or wmts_request
     self.md = md
     self.max_tile_age = max_tile_age
     self.layers, self.matrix_sets = self._matrix_sets(layers)
     self.capabilities_class = Capabilities
Ejemplo n.º 5
0
 def __init__(self, layers, md, max_tile_age=None, use_dimension_layers=False, origin=None):
     Server.__init__(self)
     self.layers = layers
     self.md = md
     self.max_tile_age = max_tile_age
     self.use_dimension_layers = use_dimension_layers
     self.origin = origin
Ejemplo n.º 6
0
 def __init__(self, layers, md, max_tile_age=None, use_dimension_layers=False, origin=None):
     Server.__init__(self)
     self.layers = layers
     self.md = md
     self.max_tile_age = max_tile_age
     self.use_dimension_layers = use_dimension_layers
     self.origin = origin
Ejemplo n.º 7
0
 def __init__(self, layers, md, request_parser=None, max_tile_age=None, info_formats={}):
     Server.__init__(self)
     self.request_parser = request_parser or wmts_request
     self.md = md
     self.max_tile_age = max_tile_age
     self.layers, self.matrix_sets = self._matrix_sets(layers)
     self.capabilities_class = Capabilities
     self.fi_transformers = None
     self.info_formats = info_formats
Ejemplo n.º 8
0
 def __init__(self, layers, md, request_parser=None, tile_layers=None,
              srs=None, image_formats=None, services=None):
     Server.__init__(self)
     self.layers = layers
     self.tile_layers = tile_layers or {}
     self.md = md
     self.image_formats = image_formats
     filter_image_format = []
     for format in self.image_formats:
         if 'image/jpeg' == format or 'image/png' == format:
             filter_image_format.append(format)
     self.image_formats = filter_image_format
     self.srs = srs
     self.services = services or []
Ejemplo n.º 9
0
 def setup(self):
     # Base server
     self.server = Server()
     # WMS Server
     root_layer = WMSGroupLayer(None, 'root layer', None, [DummyLayer('wms_cache')])
     self.wms_server = WMSServer(
         md={}, root_layer=root_layer, srs=['EPSG:4326'],
         image_formats={'image/png': ImageOptions(format='image/png')}
     )
     # Tile Servers
     layers = odict()
     layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
     self.tile_server = TileServer(layers, {})
     self.wmts_server = WMTSServer(layers, {})
     # Common arguments
     self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))
Ejemplo n.º 10
0
 def setup(self):
     # Base server
     self.server = Server()
     # WMS Server
     root_layer = WMSGroupLayer(None, 'root layer', None, [DummyLayer('wms_cache')])
     self.wms_server = WMSServer(
         md={}, root_layer=root_layer, srs=['EPSG:4326'],
         image_formats={'image/png': ImageOptions(format='image/png')}
     )
     # Tile Servers
     layers = odict()
     layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
     self.tile_server = TileServer(layers, {})
     self.wmts_server = WMTSServer(layers, {})
     # Common arguments
     self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))
Ejemplo n.º 11
0
class TestDecorateImg(object):
    def setup(self):
        # Base server
        self.server = Server()
        # WMS Server
        root_layer = WMSGroupLayer(None, 'root layer', None,
                                   [DummyLayer('wms_cache')])
        self.wms_server = WMSServer(
            md={},
            root_layer=root_layer,
            srs=['EPSG:4326'],
            image_formats={'image/png': ImageOptions(format='image/png')})
        # Tile Servers
        layers = odict()
        layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
        self.tile_server = TileServer(layers, {})
        self.wmts_server = WMTSServer(layers, {})
        # Common arguments
        self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))

    def test_original_imagesource_returned_when_no_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert img_src1 == img_src2

    def test_returns_imagesource(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert isinstance(img_src2, ImageSource)

    def set_called_callback(self, img_src, service, layers, **kw):
        self.called = True
        return img_src

    def test_calls_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert self.called == True

    def return_new_imagesource_callback(self, img_src, service, layers, **kw):
        new_img_src = ImageSource(Image.new('RGBA', (100, 100)))
        self.new_img_src = new_img_src
        return new_img_src

    def test_returns_callbacks_return_value(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('',
                            extra_environ={
                                'mapproxy.decorate_img':
                                self.return_new_imagesource_callback
                            })
        self.new_img_src = None
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert img_src2 == self.new_img_src

    def test_wms_server(self):
        ''' Test that the decorate_img method is available on a WMSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wms_server.decorate_img(img_src1, 'wms.map',
                                                ['layer1'], env,
                                                self.query_extent)
        assert self.called == True

    def test_tile_server(self):
        ''' Test that the decorate_img method is available on a TileServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.tile_server.decorate_img(img_src1, 'tms', ['layer1'],
                                                 env, self.query_extent)
        assert self.called == True

    def test_wmts_server(self):
        ''' Test that the decorate_img method is available on a WMTSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wmts_server.decorate_img(img_src1, 'wmts', ['layer1'],
                                                 env, self.query_extent)
        assert self.called == True

    def test_args(self):
        def callback(img_src, service, layers, environ, query_extent, **kw):
            assert isinstance(img_src, ImageSource)
            assert 'wms.map' == service
            assert isinstance(layers, list)
            assert isinstance(environ, dict)
            assert len(query_extent) == 2
            assert len(query_extent[1]) == 4
            return img_src

        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('',
                            extra_environ={'mapproxy.decorate_img': callback})
        img_src2 = self.tile_server.decorate_img(img_src1, 'wms.map',
                                                 ['layer1'], env,
                                                 self.query_extent)
Ejemplo n.º 12
0
class TestDecorateImg(object):

    def setup(self):
        # Base server
        self.server = Server()
        # WMS Server
        root_layer = WMSGroupLayer(None, 'root layer', None, [DummyLayer('wms_cache')])
        self.wms_server = WMSServer(
            md={}, root_layer=root_layer, srs=['EPSG:4326'],
            image_formats={'image/png': ImageOptions(format='image/png')}
        )
        # Tile Servers
        layers = odict()
        layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
        self.tile_server = TileServer(layers, {})
        self.wmts_server = WMTSServer(layers, {})
        # Common arguments
        self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))

    def test_original_imagesource_returned_when_no_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(img_src1, img_src2)

    def test_returns_imagesource(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        assert isinstance(img_src2, ImageSource)

    def set_called_callback(self, img_src, service, layers, **kw):
        self.called = True
        return img_src

    def test_calls_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def return_new_imagesource_callback(self, img_src, service, layers, **kw):
        new_img_src = ImageSource(Image.new('RGBA', (100, 100)))
        self.new_img_src = new_img_src
        return new_img_src

    def test_returns_callbacks_return_value(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.return_new_imagesource_callback})
        self.new_img_src = None
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(img_src2, self.new_img_src)

    def test_wms_server(self):
        ''' Test that the decorate_img method is available on a WMSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wms_server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def test_tile_server(self):
        ''' Test that the decorate_img method is available on a TileServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.tile_server.decorate_img(
            img_src1, 'tms', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def test_wmts_server(self):
        ''' Test that the decorate_img method is available on a WMTSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wmts_server.decorate_img(
            img_src1, 'wmts', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def test_args(self):
        def callback(img_src, service, layers, environ, query_extent, **kw):
            assert isinstance(img_src, ImageSource)
            eq_('wms.map', service)
            assert isinstance(layers, list)
            assert isinstance(environ, dict)
            assert len(query_extent) == 2
            assert len(query_extent[1]) == 4
            return img_src
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': callback})
        img_src2 = self.tile_server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )