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

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

Tidied up the datareader geoplot layer slabs so that there is only one class now, there was so little code in the style specific slabs that there seemed little point in keeping them.

Implemented a Modis file reader that reads and extracts a number of layers from a modis file on the filesystem. Currently the generated images appear to be the wrong way up but I can't find out why.

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
17log = logging.getLogger(__name__)
18
19class DRGeoplotLayerMapper(ILayerMapper):
20   
21    def __init__(self):
22        self.layermapcache={}
23        self.readerClasses = [CSMLDataReader, ModisFileReader]
24   
25    def map(self, **kwargs):
26        """
27        Given csml.parser.Dataset object list the names of
28        all layers available.
29       
30        @return: A mapping of layer names to ILayer implementations.
31        @raise ValueError: If no layers are available for these keywords.
32        """
33        fileoruri=kwargs['fileoruri']
34               
35        if fileoruri in self.layermapcache.keys():
36           
37            log.debug("cached layermap used for fileoruri = %s" % (fileoruri,))
38           
39            #we've accessed this layer map before, get it from the cache dictionary
40            return self.layermapcache[fileoruri]
41       
42
43        layermap={}
44       
45        reader = self._getReader(fileoruri)
46       
47        for name, title, abstract, dimensions, units, crss, bb in \
48                                     reader.getWMSLayerInfo():
49           
50            layermap[name] = DRGeoplotWmsLayer(name, title, abstract, dimensions, units, crss, bb, reader)
51           
52           
53        if len(layermap) > 0:
54            self.layermapcache[fileoruri]=layermap
55            return layermap
56        else:
57            raise ValueError
58       
59    def _getReader(self, fileoruri):
60       
61        log.debug("CSMLDataReader.isDataPresent(fileoruri) = %s" % (CSMLDataReader.isDataPresent(fileoruri),))
62        reader = None
63       
64        for klass in self.readerClasses:
65            if klass.isDataPresent(fileoruri):
66                reader = klass(fileoruri)
67                break
68       
69        if reader == None:
70            raise Exception("No reader found for fileoruri = %s" % (fileoruri,))
71       
72        return reader
Note: See TracBrowser for help on using the repository browser.