Changeset 3552 for TI05-delivery


Ignore:
Timestamp:
03/03/08 16:48:04 (12 years ago)
Author:
spascoe
Message:

Version works with latest ukcip02_server. About to reorganise.

Location:
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/pylons/model.py

    r3548 r3552  
    2020 
    2121def setLayerMapper(lm): 
     22    global _layerMapper 
    2223    if not isinstance(lm, ILayerMapper): 
    2324        raise TypeError("Object %s does not implement ILayerMapper" % lm) 
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/pylons/wms_controller.py

    r3548 r3552  
    88 
    99from matplotlib.cm import get_cmap 
    10 from pylons import request, response 
     10from pylons import request, response, c 
    1111 
    1212import logging 
    1313log = logging.getLogger(__name__) 
    1414 
    15 from ows_common.wms import WmsDatasetSummary, Dimension, PossibleValues 
     15import Image 
     16 
     17from ows_common.wms import WmsDatasetSummary, Dimension 
     18from ows_common.domain import PossibleValues 
     19from ows_common.common import BoundingBox 
    1620from ows_common.pylons import ows_controller, model 
    1721from ows_common.exceptions import * 
     22from ows_common import bbox_util 
     23from ows_common.contents import Contents 
    1824 
    1925class WMSController(ows_controller.OWSController): 
    20  
    21     service = 'WMS' 
    22     owsOperations = ows_controller.OWSController.owsOperations + ['GetMap', 'GetInfo'] 
    23     validVersions = ['1.1.1'] 
    24  
     26     
    2527    _pilImageFormats = { 
    2628        'image/png': 'PNG', 
     
    2931        'image/tiff': 'TIFF' 
    3032        } 
     33 
     34    #------------------------------------------------------------------------- 
     35    # Attributes required by OWSController 
     36 
     37    service = 'WMS' 
     38    owsOperations = ows_controller.OWSController.owsOperations + ['GetMap', 'GetInfo'] 
     39    validVersions = ['1.1.1'] 
     40 
     41    #------------------------------------------------------------------------- 
    3142 
    3243    def __before__(self, **kwargs): 
     
    5869        ows_controller.addOperation('GetInfo') 
    5970        log.debug('Loading capabilities contents') 
     71        c.capabilities.contents = Contents() 
    6072        for layerName, layer in self.layers.items(): 
    6173            log.debug('Loading layer %s' % layerName) 
     
    6476            bboxObjs = [] 
    6577            for crs in layer.crss: 
    66                 bbox = layer.getBbox(crs) 
     78                bbox = layer.getBBox(crs) 
    6779                bboxObjs.append(BoundingBox(bbox[:2], bbox[2:], crs=crs)) 
    6880            # Get dimensions 
     
    97109        # Layer handling 
    98110        layerName = self.getOwsParam('layers') 
    99         if ',' in layer: 
     111        if ',' in layerName: 
    100112            raise InvalidParameterValue( 
    101113                'Multi-layer GetMap requests are not supported', 'layers') 
     
    122134        # Dimension handling 
    123135        dimValues = {} 
    124         for dimName, dim in self.layer.dimensions.items(): 
     136        for dimName, dim in layerObj.dimensions.items(): 
    125137            defaultValue = dim.extent[0] 
    126138            dimValues[dimName] = self.getOwsParam('time', default=defaultValue) 
     
    128140        # The real work 
    129141        #!TODO: Minimum and maximum values 
    130         slab = layerObj.getSlab(srs, dims, dict(minValue=0, maxValue=100)) 
    131         img = view.getImage(bbox, width, height) 
     142        slab = layerObj.getSlab(srs, dimValues, dict(minValue=0, maxValue=100)) 
     143 
     144        # We must request a bbox within the layer's bbox. 
     145        lbbox = layerObj.getBBox(srs) 
     146        ibbox = bbox_util.intersection(bbox, lbbox) 
     147 
     148        log.debug('bbox = %s' % (bbox,)) 
     149        log.debug('lbbox = %s' % (lbbox,)) 
     150        log.debug('ibbox = %s' % (ibbox,)) 
     151 
     152        # If bbox is not within layerObj.bbox then we need to calculate the pixel 
     153        # offset of the inner bbox, request the right width/height and paste the 
     154        # image into a blank background 
     155        if bbox == ibbox: 
     156            img = slab.getImage(bbox, width, height) 
     157            log.debug('slab image.size = %s' % (img.size,)) 
     158        else: 
     159            sx, sy = bbox_util.relativeSize(ibbox, bbox) 
     160            log.debug('scaling: %s,%s' % (sx, sy)) 
     161            img1 = slab.getImage(ibbox, int(width*sx), int(height*sy)) 
     162            log.debug('inner image.size = %s' % (img1.size,)) 
     163 
     164            img = Image.new('RGBA', (width, height)) 
     165            pxOrigin = bbox_util.geoToPixel(ibbox[0], ibbox[3], bbox, width, height) 
     166            log.debug('pxOrigin = %s' % (pxOrigin,)) 
     167            img.paste(img1, pxOrigin) 
     168             
    132169 
    133170        # IE < 7 doesn't display the alpha layer right.  Here we sniff the 
Note: See TracChangeset for help on using the changeset viewer.