Changeset 3620


Ignore:
Timestamp:
17/03/08 10:08:07 (11 years ago)
Author:
domlowe
Message:

csml wms working with correct bbox behaviour

Location:
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/imps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/imps/test_csmllayer.py

    r3609 r3620  
    11import wms_csmllayer 
     2import csml 
    23 
    34def test_layerMapper(): 
    45    lm=wms_csmllayer.CSMLLayerMapper() 
    56    print 'building layermap' 
    6     layers=lm.map(file='/home/dom/hadgem/hadgem1.csml') 
     7    file='hadgem1' 
     8    layers=lm.map(fileoruri=file) 
    79     
    810    #for key, layer in layers.items(): 
     
    4143    print 'getting slab3...' 
    4244    layerid = 'RJ1QcBwz' 
    43     slab3= layers[layerid].getSlab('EPSG:4324', dimValues={'time':'1998-12-06T12:00:00.0', 'height':'0'}) 
     45    slab3= layers[layerid].getSlab('EPSG:4324', dimValues={'time':'1995-12-06T12:00:00.0', 'height':'0'}) 
    4446    img3=slab3.getImage((-80, -160, 80, 160) ,320, 320) 
    4547    img3.save("testimage3.jpeg", "JPEG") 
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/imps/wms_csmllayer.py

    r3609 r3620  
    99from pywms.render_imp import RGBARenderer 
    1010from matplotlib import cm 
     11import genutil 
    1112 
    1213class CSMLLayerMapper(object): 
     
    3839        domain = feature.getDomain() 
    3940        for dim in feature.getAxisLabels(): 
    40             dimensions[dim]=CSMLDimension(domain, dim, tmpunits.pop()) 
     41            nextdim=CSMLDimension(domain, dim, tmpunits.pop()) 
     42            if dim not in ['latitude', 'longitude']: 
     43                dimensions[dim]=nextdim 
    4144        crs=feature.getNativeCRS() 
    4245        crss=[self._crscat.getCRS(crs).twoD] 
    4346        return title, abstract, dimensions, units, crss 
    4447     
    45     def map(self, file=None): 
    46         """ 
    47         Given arbitary keywords/value pairs list the names of 
     48    def map(self, **kwargs): 
     49        """ 
     50        Given csml.parser.Dataset object list the names of 
    4851        all layers available. 
    4952         
     
    5154        @raise ValueError: If no layers are available for these keywords.  
    5255        """ 
     56        fileoruri=kwargs['fileoruri'] 
     57         
     58        #TODO - handle file paths/directories URIs in config 
     59        #For testing purposes...: 
     60        filename='/home/dom/hadgem/%s.csml'%fileoruri 
     61        ds=csml.parser.Dataset(filename) 
     62        
     63         
    5364        layermap={} 
    5465        self._crscat=csml.csmllibs.csmlcrs.CRSCatalogue() 
    55         if file: 
    56             ds=csml.parser.Dataset(file) 
    57             for feature in csml.csmllibs.csmlextra.listify(ds.featureCollection.featureMembers): 
    58                 title, abstract, dimensions, units, crss=self._getInfo(feature) 
    59                 layermap[feature.id]=CSMLLayer(title,abstract, dimensions, units, crss, feature) 
     66        for feature in csml.csmllibs.csmlextra.listify(ds.featureCollection.featureMembers): 
     67            title, abstract, dimensions, units, crss=self._getInfo(feature) 
     68            layermap[feature.id]=CSMLLayer(title,abstract, dimensions, units, crss, feature) 
    6069        if len(layermap) > 0: 
    6170            return layermap 
     
    8594        self.crss=crss 
    8695        self._feature=feature 
     96        self.legendSize=(30,100) 
    8797 
    8898    def getBBox(self, crs): 
     
    90100        @return: A 4-typle of the bounding box in the given coordinate 
    91101            reference system. 
    92          
    93         """ 
    94         return [] 
     102        """ 
     103        bb= self._feature.getCSMLBoundingBox().getBox() 
     104        #convert 0 - 360 to -180, 180 as per common WMS convention 
     105        if abs(bb[2]-bb[0]) >= 359 and abs(bb[2]-bb[0]) < 361: 
     106            bb[0], bb[2]=-180, 180 
     107        return bb 
    95108        #raise NotImplementedError 
    96 #dimValues={'surface':'2','time':'1968-01-02T00:00:00.0Z'} 
     109         
    97110    def getSlab(self, crs, dimValues=None, renderOpts={}): 
    98111        """ 
     
    129142 
    130143        """ 
    131         raise NotImplementedError 
     144        return None 
     145        #raise NotImplementedError 
    132146 
    133147 
     
    143157    def __init__(self, domain, dimname, unit): 
    144158        self.units = unit 
    145         self.extent =domain[dimname] 
     159        self.extent = [] 
     160        for val in domain[dimname]: 
     161            self.extent.append(str(val)) 
     162                
     163        
     164         
    146165         
    147166class CSMLLayerSlab(object): 
     
    179198 
    180199        """ 
    181          
    182  
    183         cmap=cm.gist_rainbow_r # where does colourmap come from? 
     200        cmap=cm.gist_rainbow_r # renderOpts is hook for colourmap.   
    184201        grid=Grid(self.layer, self._netcdf, bbox, width, height) 
    185202        #how to handle varmin,varmax? ..read array? 
     203        #minval, maxval=genutil.minmax(grid.value) 
    186204        minval=min(min(l) for l in grid.value) 
    187205        maxval=max(max(l) for l in grid.value) 
     
    211229    def __init__(self, layer, netcdf, bbox, width, height): 
    212230        #we know the axes are called latitude and longitude as the CSML code has written it: 
    213         tvar=netcdf(layer.title).subRegion(latitude=(bbox[1], bbox[3]), longitude=(bbox[0],bbox[3]),squeeze=1) 
     231 
     232        v=netcdf(layer.title) 
     233        tvar=v(latitude=(bbox[1], bbox[3]), longitude=(bbox[0],bbox[2]),squeeze=1) 
    214234        order=tvar.getOrder() 
    215          
    216235        #array of data 
    217236        self.value=tvar.getValue() 
    218          
    219237        #order of axes 
    220238        if order == 'xy': 
     
    224242            self.ix=1 
    225243            self.iy=0 
    226          
    227244        lat = tvar.getLatitude() 
    228245        lon = tvar.getLongitude() 
Note: See TracChangeset for help on using the changeset viewer.