source: cows/branches/wcsmerge/cows/service/wcs_iface.py @ 4574

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

First stage in merging - still in flux.

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#NOTE: FOR NOW, copy wms iface as starting point
28
29"""
30
31from wxs_iface import ILayer
32
33       
34
35class IwmsLayer(ILayer):
36    """
37    An interface representing a WMS layer, based on ILayer.
38   
39    @ivar legendSize: (width, height) in pixels of legend.
40
41    @ivar featureInfoFormats: A sequence of formats supported for the
42        self.getFeatureInfo method.  If this is None or empty GetFeatureInfo
43        is not supported.
44
45    @todo: Do we need minValue/maxValue?
46
47    """
48
49
50    def getSlab(self, crs, dimValues=None, renderOpts={}):
51        """
52        Creates a slab of the layer in a particular CRS and set of
53        dimensions.
54
55        @param crs: The coordinate reference system.
56        @param dimValues: A mapping of dimension names to dimension values
57            as specified in the IDimension.extent
58        @param renderOpts: A generic mapping object for passing rendering
59            options
60        @return: An object implementing ILayerSlab
61
62        """
63        raise NotImplementedError
64
65    def getCacheKey(self, crs, dimValues=None, renderOpts={}):
66        """
67        Create a unique key for use in caching a slab.
68
69        Any unique combination of crs, dimValues and renderOpts should
70        produce a unique key.
71
72        The intention here is that most of the work should be done when
73        instantiating an ILayerSlab object.  These can be cached by the
74        server for future use.  The server will first call getCacheKey()
75        for the slab creation arguments and if the key is in it's cache
76        it will use a pre-generated ILayerSlab object.
77
78        """
79        raise NotImplementedError
80
81    def getLegendImage(self, orientation='vertical', renderOpts={}):
82        """
83        Create an image of the colourbar for this layer.
84       
85        @param orientation: Either 'vertical' or 'horizontal'
86        @return: A PIL image
87
88        """
89        raise NotImplementedError
90
91    def getFeatureInfo(self, format, crs, point, dimValues):
92        """
93        Return a response string descibing the feature at a given
94        point in a given CRS.
95
96        @param format: One of self.featureInfoFormats.  Defines which
97            format the response will be in.
98        @param crs: One of self.crss
99        @param point: a tuple (x, y) in the supplied crs of the point
100            being selected.
101        @param dimValues: A mapping of dimension names to dimansion values.
102        @return: A string containing the response.
103
104        """
105        raise NotImplementedError
106       
107
108class IwmsDimension(object):
109    """
110    An interface representing a WMS dimension
111   
112    @ivar units: The units string.
113    @ivar extent: Sequence of extent values.
114
115    """
116    units = extent = NotImplemented
117
118class IwmsLayerSlab(object):
119    """
120    An interface representing a particular horizontal slice of a WMS layer.
121
122    IwmsLayerSlab objects are designed to be convenient to cache.
123    Ideally they should be pickleable to enable memcached support in
124    the future.
125
126    @ivar layer: The source IwmsLayer instance.
127    @ivar crs: The coordinate reference system.
128    @ivar dimValues: A mapping of dimension values of this view.
129    @ivar renderOpts: The renderOpts used to create this view.
130    @ivar bbox: The bounding box as a 4-tuple.
131
132    """
133    layer = crs = dimValues = renderOpts = bbox = NotImplemented
134
135    def getImage(self, bbox, width, height):
136        """
137        Create an image of a sub-bbox of a given size.
138
139        @param bbox: A bbox tuple (llx, lly, urx, ury).  bbox will
140            always lie within the self.layer.getBBox(self.crs)
141        @param width: width in pixels.
142        @param height: height in pixels.
143        @return: A PIL Image object.
144
145        """
146        raise NotImplementedError
147
Note: See TracBrowser for help on using the repository browser.