source: cows/trunk/cows/service/wms_iface.py @ 4266

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/service/wms_iface.py@4266
Revision 4266, 4.9 KB checked in by domlowe, 11 years ago (diff)

Splitting wms_iface into wxs_iface and wms_iface interfaces.
Modifying implemenations of wms_iface to inherit from new interfaces.

Line 
1"""
2The classes in this module define an interface between the OWS Pylons
3server and components that provide Web Map Server layers. They extend the interfaces
4defined in wxs_iface.py.
5
6The interface was designed with several requirements in mind:
7 - support multiple dimensions (in the WMS sense, i.e. non-geospatial dimensions).
8 - support multiple CRSs/SRSs
9 - Allow caching of horizontal slices (called layer slabs) by
10   dimensions and CRS to mitigate the overhead of data retreival and rendering.
11 - To hide how layers are actually retrieved and rendered from ows_server.
12
13IwmsLayer instances provide dimension and CRS information to the server
14and can render a legend.  A layer image is requested by a two stage
15process.  First the CRS and non-geospatial dimensions are selected
16through IwmsLayer to return a IwmsLayerSlab instance.  WMS images are then
17retrieved through IwmsLayerSlab for a given bounding box.
18
19This allows implementations to cache the result if it makes sense to
20do so.  implementing IwmsLayer.getCacheKey() will cause the server to
21cache IwmsLayerSlab objects for future use, therefore not requiring
22repeated calls to IwmsLayer.getSlab().  This strategy works well with
23tiling WMS clients that will make multiple GetMap requests with the
24same CRS and dimension parameters.
25
26
27
28"""
29
30from wxs_iface import ILayer
31
32       
33
34class IwmsLayer(ILayer):
35    """
36    An interface representing a WMS layer, based on ILayer.
37   
38    @ivar legendSize: (width, height) in pixels of legend.
39
40    @ivar featureInfoFormats: A sequence of formats supported for the
41        self.getFeatureInfo method.  If this is None or empty GetFeatureInfo
42        is not supported.
43
44    @todo: Do we need minValue/maxValue?
45
46    """
47
48
49    def getSlab(self, crs, dimValues=None, renderOpts={}):
50        """
51        Creates a slab of the layer in a particular CRS and set of
52        dimensions.
53
54        @param crs: The coordinate reference system.
55        @param dimValues: A mapping of dimension names to dimension values
56            as specified in the IDimension.extent
57        @param renderOpts: A generic mapping object for passing rendering
58            options
59        @return: An object implementing ILayerSlab
60
61        """
62        raise NotImplementedError
63
64    def getCacheKey(self, crs, dimValues=None, renderOpts={}):
65        """
66        Create a unique key for use in caching a slab.
67
68        Any unique combination of crs, dimValues and renderOpts should
69        produce a unique key.
70
71        The intention here is that most of the work should be done when
72        instantiating an ILayerSlab object.  These can be cached by the
73        server for future use.  The server will first call getCacheKey()
74        for the slab creation arguments and if the key is in it's cache
75        it will use a pre-generated ILayerSlab object.
76
77        """
78        raise NotImplementedError
79
80    def getLegendImage(self, orientation='vertical', renderOpts={}):
81        """
82        Create an image of the colourbar for this layer.
83       
84        @param orientation: Either 'vertical' or 'horizontal'
85        @return: A PIL image
86
87        """
88        raise NotImplementedError
89
90    def getFeatureInfo(self, format, crs, point, dimValues):
91        """
92        Return a response string descibing the feature at a given
93        point in a given CRS.
94
95        @param format: One of self.featureInfoFormats.  Defines which
96            format the response will be in.
97        @param crs: One of self.crss
98        @param point: a tuple (x, y) in the supplied crs of the point
99            being selected.
100        @param dimValues: A mapping of dimension names to dimansion values.
101        @return: A string containing the response.
102
103        """
104        raise NotImplementedError
105       
106
107class IwmsDimension(object):
108    """
109    An interface representing a WMS dimension
110   
111    @ivar units: The units string.
112    @ivar extent: Sequence of extent values.
113
114    """
115    units = extent = NotImplemented
116
117class IwmsLayerSlab(object):
118    """
119    An interface representing a particular horizontal slice of a WMS layer.
120
121    IwmsLayerSlab objects are designed to be convenient to cache.
122    Ideally they should be pickleable to enable memcached support in
123    the future.
124
125    @ivar layer: The source IwmsLayer instance.
126    @ivar crs: The coordinate reference system.
127    @ivar dimValues: A mapping of dimension values of this view.
128    @ivar renderOpts: The renderOpts used to create this view.
129    @ivar bbox: The bounding box as a 4-tuple.
130
131    """
132    layer = crs = dimValues = renderOpts = bbox = NotImplemented
133
134    def getImage(self, bbox, width, height):
135        """
136        Create an image of a sub-bbox of a given size.
137
138        @param bbox: A bbox tuple (llx, lly, urx, ury).  bbox will
139            always lie within the self.layer.getBBox(self.crs)
140        @param width: width in pixels.
141        @param height: height in pixels.
142        @return: A PIL Image object.
143
144        """
145        raise NotImplementedError
146
Note: See TracBrowser for help on using the repository browser.