Ignore:
Timestamp:
18/08/09 14:51:08 (10 years ago)
Author:
domlowe
Message:

Merging in qesdi changes to cows trunk - still need to merge new backend.

Location:
cows/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cows/trunk

    • Property svn:ignore set to
      .project
      .pydevproject
      cows.egg-info
  • cows/trunk/cows/service/imps/csmlbackend/wms_csmllayer.py

    r5511 r5629  
    3131from cows.service.wms_iface import IwmsLayer, IwmsDimension, IwmsLayerSlab 
    3232from cows.service.imps.csmlbackend.csmlcommon import CSMLLayerMapper, CSMLConnector 
    33 import Image 
     33 
     34try: 
     35    from PIL import Image 
     36except: 
     37    import Image 
     38from cows import bbox_util 
    3439 
    3540class CSMLwmsLayerMapper(CSMLLayerMapper): 
     
    9196        for feature in csml.csmllibs.csmlextra.listify(ds.featureCollection.featureMembers): 
    9297            title, abstract, dimensions, units, crss=self.getInfo(feature) 
    93             layermap[feature.id]=CSMLwmsLayer(title,abstract, dimensions, units, crss, feature) 
     98            layermap[feature.id]=CSMLwmsLayer(title,abstract, dimensions, units, crss, feature, 
     99                                              name=feature.id) 
    94100        if len(layermap) > 0: 
    95101            self.layermapcache[fileoruri]=layermap 
     
    113119    """ 
    114120     
    115     def __init__(self, title, abstract, dimensions, units, crss, feature): 
     121    def __init__(self, title, abstract, dimensions, units, crss, feature, 
     122                 name=None): 
    116123        self.featureInfoFormats=None #NotImplemented 
    117124        self.title=title 
     125        self.name = name 
    118126        self.abstract=abstract 
    119127        self.dimensions=dimensions 
     
    154162        #raise NotImplementedError 
    155163         
    156     def getSlab(self, crs, dimValues=None, renderOpts={}): 
     164    def getSlab(self, crs, style, dimValues, transparent, bgcolor, renderOpts={}): 
    157165        """ 
    158166        Creates a slab of the layer in a particular CRS and set of 
     
    194202            raise NotImplementedError 
    195203         
    196     def getCacheKey(self, crs, dimValues=None, renderOpts={}): 
     204    def getCacheKey(self, crs, style, dimValues, transparent, bgcolor, renderOpts={}): 
    197205        """ 
    198206        Create a unique key for use in caching a slab. 
     
    400408        """ 
    401409 
    402         log.debug('getImage(%s, %s, %s)' % (bbox, width, height)) 
     410 
     411        lbbox = self.layer.getBBox(self.crs) 
     412        ibbox = bbox_util.intersection(bbox, lbbox) 
     413     
     414        log.debug('bbox = %s' % (bbox,)) 
     415        log.debug('lbbox = %s' % (lbbox,)) 
     416        log.debug('ibbox = %s' % (ibbox,)) 
     417     
     418        # If bbox is not within layerObj.bbox then we need to calculate the 
     419        # pixel offset of the inner bbox, request the right width/height 
     420        # and paste the image into a blank background 
     421        if bbox == ibbox: 
     422            img = self._renderImage(bbox, width, height) 
     423            log.debug('image.size = %s' % (img.size,)) 
     424                    
     425        else: 
     426            
     427            ix0, iy0 = bbox_util.geoToPixel(ibbox[0], ibbox[3], bbox, width, height, 
     428                                            roundUpY=True) 
     429            ix1, iy1 = bbox_util.geoToPixel(ibbox[2], ibbox[1], bbox, width, height, 
     430                                            roundUpX=True) 
     431            iw = ix1-ix0 
     432            ih = iy1-iy0 
     433            log.debug('Deduced inner image: %s, (%d x %d)' % ((ix0, iy0, ix1, iy1), iw, ih)) 
     434            img1 = self._renderImage(ibbox, iw, ih) 
     435 
     436            img = Image.new('RGBA', (width, height)) 
     437            img.paste(img1, (ix0, iy0)) 
     438                     
     439        return img 
     440 
     441 
     442    def _renderImage(self, bbox, width, height): 
     443        log.debug('_renderImage(%s, %s, %s)' % (bbox, width, height)) 
    403444         
    404445        cmap = cm.get_cmap(config['colourmap']) 
     
    422463        renderer=RGBARenderer(minval, maxval)          
    423464        return renderer.renderGrid(grid, bbox, width, height, cmap) 
     465     
    424466     
    425467class Grid(object): 
Note: See TracChangeset for help on using the changeset viewer.