source: cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_reader_geoplot_layer_mapper.py @ 5692

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_reader_geoplot_layer_mapper.py@5697
Revision 5692, 2.5 KB checked in by pnorton, 11 years ago (diff)

Made some modifications to the data renderer backend. The display options are now attached to each of the slabs rather than being stored in the shared option parser and the controller.

I've also added some code to generate the display options JSON string.

Line 
1'''
2Created on 9 Jun 2009
3
4@author: pnorton
5'''
6
7import logging
8from copy import copy
9
10from cows.service.wxs_iface import ILayerMapper
11
12from cows.service.imps.data_reader_geoplot_backend.data_reader_geoplot_wms_layer import DRGeoplotWmsLayer
13
14from cows.service.imps.data_reader_geoplot_backend.data_readers.csml_data_reader import CSMLDataReader
15from cows.service.imps.data_reader_geoplot_backend.data_readers.modis_file_reader import ModisFileReader
16
17
18log = logging.getLogger(__name__)
19
20class DRGeoplotLayerMapper(ILayerMapper):
21   
22    def __init__(self):
23        self.layermapcache={}
24        self.readerClasses = [CSMLDataReader, ModisFileReader]
25   
26    def map(self, **kwargs):
27        """
28        Given csml.parser.Dataset object list the names of
29        all layers available.
30       
31        @return: A mapping of layer names to ILayer implementations.
32        @raise ValueError: If no layers are available for these keywords.
33        """
34        fileoruri=kwargs['fileoruri']
35               
36        if fileoruri in self.layermapcache.keys():
37           
38            log.debug("cached layermap used for fileoruri = %s" % (fileoruri,))
39           
40            #we've accessed this layer map before, get it from the cache dictionary
41            return self.layermapcache[fileoruri]
42       
43
44        layermap={}
45       
46        reader = self._getReader(fileoruri)
47       
48        for name, title, abstract, dimensions, units, crss, bb in \
49                                     reader.getWMSLayerInfo():
50           
51            layermap[name] = DRGeoplotWmsLayer(name, title, abstract, dimensions, units, crss, bb, reader)
52           
53           
54        if len(layermap) > 0:
55            self.layermapcache[fileoruri]=layermap
56            return layermap
57        else:
58            raise ValueError
59       
60    def _getReader(self, fileoruri):
61        """
62        Searches the reader classes to find one that contains the data for
63        the fileoruri given, when found the class is returned. If no
64        reader class is found and Exception is raised.
65        """
66       
67        log.debug("CSMLDataReader.isDataPresent(fileoruri) = %s" % (CSMLDataReader.isDataPresent(fileoruri),))
68        reader = None
69       
70        for klass in self.readerClasses:
71            if klass.isDataPresent(fileoruri):
72                reader = klass(fileoruri)
73                break
74       
75        if reader == None:
76            raise Exception("No reader found for fileoruri = %s" % (fileoruri,))
77       
78        return reader
Note: See TracBrowser for help on using the repository browser.