Exemplo n.º 1
0
    def _render_capture_source_errors(self, async_pool, render_layers, layer_merger):
        # call _render_layer, capture SourceError exceptions
        errors = []
        rendered = 0

        for layer_task in async_pool.imap(self._render_layer, render_layers, use_result_objects=True):
            if layer_task.exception is None:
                layer, layer_img = layer_task.result
                if layer_img is not None:
                    layer_merger.add(layer_img, layer=layer)
                rendered += 1
            else:
                layer_merger.cacheable = False
                ex = layer_task.exception
                if isinstance(ex[1], SourceError):
                    errors.append(ex[1].args[0])
                else:
                    async_pool.shutdown(True)
                    raise ex[0], ex[1], ex[2]

        if render_layers and not rendered:
            errors = "\n".join(errors)
            raise RequestError("Could not get any sources:\n" + errors, request=self.request)

        if errors:
            layer_merger.add(
                message_image("\n".join(errors), self.query.size, image_opts=ImageOptions(transparent=True))
            )
Exemplo n.º 2
0
    def _render_capture_source_errors(self, async_pool, render_layers,
                                      layer_merger):
        # call _render_layer, capture SourceError exceptions
        errors = []
        rendered = 0

        for layer_task in async_pool.imap(self._render_layer,
                                          render_layers,
                                          use_result_objects=True):
            if layer_task.exception is None:
                layer, layer_img = layer_task.result
                if layer_img is not None:
                    layer_merger.add(layer_img, layer.coverage)
                rendered += 1
            else:
                layer_merger.cacheable = False
                ex = layer_task.exception
                if isinstance(ex[1], SourceError):
                    errors.append(ex[1].args[0])
                else:
                    async_pool.shutdown(True)
                    reraise(ex)

        if render_layers and not rendered:
            errors = '\n'.join(errors)
            raise RequestError('Could not get any sources:\n' + errors,
                               request=self.request)

        if errors:
            layer_merger.add(
                message_image('\n'.join(errors),
                              self.query.size,
                              image_opts=ImageOptions(transparent=True)))
Exemplo n.º 3
0
 def get_map(self, query):
     bbox = query.bbox
     w = bbox[2] - bbox[0]
     h = bbox[3] - bbox[1]
     res_x = w/query.size[0]
     res_y = h/query.size[1]
     debug_info = "bbox: %r\nres: %.8f(%.8f)" % (bbox, res_x, res_y)
     return message_image(debug_info, size=query.size,
         image_opts=ImageOptions(transparent=True))
Exemplo n.º 4
0
 def test_message(self):
     image_opts = PNG_FORMAT.copy()
     image_opts.bgcolor = '#113399'
     img = message_image('test', size=(100, 150), image_opts=image_opts)
     assert isinstance(img, ImageSource)
     assert img.size == (100, 150)
     # 6 values in histogram (3xRGB for background, 3xRGB for text message)
     eq_([x for x in img.as_image().histogram() if x > 10],
          [14923, 77, 14923, 77, 14923, 77])
Exemplo n.º 5
0
 def test_message(self):
     image_opts = PNG_FORMAT.copy()
     image_opts.bgcolor = '#113399'
     img = message_image('test', size=(100, 150), image_opts=image_opts)
     assert isinstance(img, ImageSource)
     assert img.size == (100, 150)
     # 6 values in histogram (3xRGB for background, 3xRGB for text message)
     eq_([x for x in img.as_image().histogram() if x > 10],
         [14923, 77, 14923, 77, 14923, 77])
Exemplo n.º 6
0
 def test_blank(self):
     image_opts = PNG_FORMAT.copy()
     image_opts.bgcolor = '#113399'
     img = message_image('', size=(100, 150), image_opts=image_opts)
     assert isinstance(img, ImageSource)
     eq_(img.size, (100, 150))
     pil_img = img.as_image()
     eq_(pil_img.getpixel((0, 0)), ImageColor.getrgb('#113399'))
     # 3 values in histogram (RGB)
     assert [x for x in pil_img.histogram() if x > 0] == [15000, 15000, 15000]
Exemplo n.º 7
0
 def test_transparent(self):
     image_opts = ImageOptions(transparent=True)
     print(image_opts)
     img = message_image('', size=(100, 150), image_opts=image_opts)
     assert isinstance(img, ImageSource)
     assert img.size == (100, 150)
     pil_img = img.as_image()
     eq_(pil_img.getpixel((0, 0)), (255, 255, 255, 0))
     # 6 values in histogram (3xRGB for background, 3xRGB for text message)
     assert [x for x in pil_img.histogram() if x > 0] == \
            [15000, 15000, 15000, 15000]
Exemplo n.º 8
0
 def test_transparent(self):
     image_opts = ImageOptions(transparent=True)
     print(image_opts)
     img = message_image('', size=(100, 150), image_opts=image_opts)
     assert isinstance(img, ImageSource)
     assert img.size == (100, 150)
     pil_img = img.as_image()
     eq_(pil_img.getpixel((0, 0)), (255, 255, 255, 0))
     # 6 values in histogram (3xRGB for background, 3xRGB for text message)
     assert [x for x in pil_img.histogram() if x > 0] == \
            [15000, 15000, 15000, 15000]
Exemplo n.º 9
0
 def test_blank(self):
     image_opts = PNG_FORMAT.copy()
     image_opts.bgcolor = '#113399'
     img = message_image('', size=(100, 150), image_opts=image_opts)
     assert isinstance(img, ImageSource)
     eq_(img.size, (100, 150))
     pil_img = img.as_image()
     eq_(pil_img.getpixel((0, 0)), ImageColor.getrgb('#113399'))
     # 3 values in histogram (RGB)
     assert [x for x in pil_img.histogram()
             if x > 0] == [15000, 15000, 15000]
Exemplo n.º 10
0
 def render(self, request_error):
     request = request_error.request
     params = request.params
     format = params.format
     size = params.size
     if size is None:
         size = (256, 256)
     transparent = "transparent" in params and params["transparent"].lower() == "true"
     bgcolor = WMSImageExceptionHandler._bgcolor(request.params)
     image_opts = ImageOptions(format=format, bgcolor=bgcolor, transparent=transparent)
     result = message_image(request_error.msg, size=size, image_opts=image_opts)
     return Response(result.as_buffer(), content_type=params.format_mime_type)
Exemplo n.º 11
0
 def render(self, request_error):
     request = request_error.request
     params = request.params
     format = params.format
     size = params.size
     if size is None:
         size = (256, 256)
     transparent = ('transparent' in params
                    and params['transparent'].lower() == 'true')
     bgcolor = WMSImageExceptionHandler._bgcolor(request.params)
     image_opts = ImageOptions(format=format,
                               bgcolor=bgcolor,
                               transparent=transparent)
     result = message_image(request_error.msg,
                            size=size,
                            image_opts=image_opts)
     return Response(result.as_buffer(),
                     content_type=params.format_mime_type)