示例#1
0
    def process(self, tile):
        #from lat,lng bbox to mapnik bbox
        p0 = self.map_proj.forward(Coord(tile.bbox[0][1],tile.bbox[0][0]))
        p1 = self.map_proj.forward(Coord(tile.bbox[1][1],tile.bbox[1][0]))
        bbox = Box2d(p0,p1)        
        image = Image(tile.size[0],tile.size[1])
        features = None
        
        result = self._check_region(bbox)
        if result is not None:
            if result[0]:
                result[1].resize(image.width(),image.height())
                result[1].zoom_to_box(bbox)
                self.adjust_language(result(1), tile.lang)
                render(result[1],image)
                features = self.save_rendered_metadata(result[1], tile.size, tile.dimensions)
            else :
                mq_logging.info("COMPOSITE MAP: %s" % result[2])
                default_image = Image(tile.size[0],tile.size[1])
                # mask style
                self.mask_map.resize(image.width(),image.height())
                self.mask_map.zoom_to_box(bbox)
                self.adjust_language(self.mask_map, tile.lang)
                render(self.mask_map,image)
                
                # default style
                self.default_map.resize(default_image.width(),default_image.height())
                self.default_map.zoom_to_box(bbox)
                self.adjust_language(self.default_map, tile.lang)
                render(self.default_map,default_image)
                features = self.save_rendered_metadata(self.default_map, tile.size, tile.dimensions)
                
                # composite DST_OUT
                default_image.composite(image,CompositeOp.dst_out)
                
                # current style
                result[1].resize(image.width(),image.height())
                result[1].zoom_to_box(bbox)
                image.set_alpha(0)
                self.adjust_language(result[1], tile.lang)
                render(result[1],image)
                if features is not None:
                    features.features.extend(self.save_rendered_metadata(result[1], tile.size, tile.dimensions).features)
                else:
                    features = self.save_rendered_metadata(result[1], tile.size, tile.dimensions)

                # blend 
                image.blend(0,0,default_image,1.0)                
        else :
            # use default style
            self.default_map.resize(image.width(),image.height())
            self.default_map.zoom_to_box(bbox)
            self.adjust_language(self.default_map, tile.lang)
            render(self.default_map,image)
            features = self.save_rendered_metadata(self.default_map, tile.size, tile.dimensions)

        #convert to PIL image
        image = PIL.Image.frombuffer('RGBA', (image.width(), image.height()), image.tostring(), 'raw', 'RGBA', 0, 3)

        return RenderResult.from_image(tile, image, features)