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

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@5945
Revision 5945, 2.6 KB checked in by pnorton, 11 years ago (diff)

Improved the csml_data_reader so that it no longer assumes the feature id is the variable name.

Improved the data reader layer so that it now gets the dataset name from the csml file.

Added some code to the geoplot slabs that is used for selecting a log scale.

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        try:
49            self.datasetName = reader.ds.name.CONTENT
50        except AttributeError:
51            self.datasetName = 'CSML/Geoplot WMS Service'
52       
53        for name, title, abstract, dimensions, units, crss, bb in \
54                                     reader.getWMSLayerInfo():
55           
56            layermap[name] = DRGeoplotWmsLayer(name, title, abstract, dimensions, units, crss, bb, reader)
57           
58           
59        if len(layermap) > 0:
60            self.layermapcache[fileoruri]=layermap
61            return layermap
62        else:
63            raise ValueError
64       
65    def _getReader(self, fileoruri):
66        """
67        Searches the reader classes to find one that contains the data for
68        the fileoruri given, when found the class is returned. If no
69        reader class is found and Exception is raised.
70        """
71       
72        log.debug("CSMLDataReader.isDataPresent(fileoruri) = %s" % (CSMLDataReader.isDataPresent(fileoruri),))
73        reader = None
74       
75        for klass in self.readerClasses:
76            if klass.isDataPresent(fileoruri):
77                reader = klass(fileoruri)
78                break
79       
80        if reader == None:
81            raise Exception("No reader found for fileoruri = %s" % (fileoruri,))
82       
83        return reader
Note: See TracBrowser for help on using the repository browser.