1 | """ |
---|
2 | Refactored model of object to support WMS requests through |
---|
3 | ows_server. |
---|
4 | |
---|
5 | Primary goals of this model is to: |
---|
6 | - support multiple dimensions. |
---|
7 | - Allow caching of layer views by dimensions and CRS to mitigate |
---|
8 | the overhead of data retreival and rendering. |
---|
9 | - To hide how layers are actually retrieved and rendered from ows_server. |
---|
10 | |
---|
11 | """ |
---|
12 | |
---|
13 | class ILayerMapper(object): |
---|
14 | """ |
---|
15 | Map keyword arguments to a collection of layers. |
---|
16 | |
---|
17 | ILayerMapper supports the retrieval of sets of layers according to arbitary |
---|
18 | keyword/value pairs. |
---|
19 | |
---|
20 | """ |
---|
21 | def map(self, **kwargs): |
---|
22 | """ |
---|
23 | Given arbitary keywords/value pairs list the names of |
---|
24 | all layers available. |
---|
25 | |
---|
26 | @return: A mapping of layer names to ILayer implementations. |
---|
27 | @raise ValueError: If no layers are available for these keywords. |
---|
28 | |
---|
29 | """ |
---|
30 | raise NotImplementedError |
---|
31 | |
---|
32 | |
---|
33 | class ILayer(object): |
---|
34 | """ |
---|
35 | An interface representing a WMS layer. |
---|
36 | |
---|
37 | @ivar title: The layer title. As seen in the Capabilities document. |
---|
38 | @ivar abstract: Abstract as seen in the Capabilities document. |
---|
39 | @ivar dimensions: A dictionary of IDimension objects. |
---|
40 | @ivar units: A string describing the units. |
---|
41 | @ivar crss: A sequence of SRS/CRSs supported by this layer. |
---|
42 | @ivar legendSize: (width, height) in pixels of legend. |
---|
43 | |
---|
44 | @todo: Do we need minValue/maxValue? |
---|
45 | |
---|
46 | """ |
---|
47 | title = abstract = dimensions = units = crss = NotImplemented |
---|
48 | |
---|
49 | def getBBox(self, crs): |
---|
50 | """ |
---|
51 | @return: A 4-typle of the bounding box in the given coordinate |
---|
52 | reference system. |
---|
53 | |
---|
54 | """ |
---|
55 | raise NotImplementedError |
---|
56 | |
---|
57 | def getSlab(self, crs, dimValues=None, renderOpts={}): |
---|
58 | """ |
---|
59 | Creates a slab of the layer in a particular CRS and set of |
---|
60 | dimensions. |
---|
61 | |
---|
62 | @param crs: The coordinate reference system. |
---|
63 | @param dimValues: A mapping of dimension names to dimension values |
---|
64 | as specified in the IDimension.extent |
---|
65 | @param renderOpts: A generic mapping object for passing rendering |
---|
66 | options |
---|
67 | @return: An object implementing ILayerSlab |
---|
68 | |
---|
69 | """ |
---|
70 | raise NotImplementedError |
---|
71 | |
---|
72 | def getCacheKey(self, crs, dimValues=None, renderOpts={}): |
---|
73 | """ |
---|
74 | Create a unique key for use in caching a slab. |
---|
75 | |
---|
76 | The intention here is that most of the work should be done when |
---|
77 | instantiating an ILayerSlab object. These can be cached by the |
---|
78 | server for future use. The server will first call getCacheKey() |
---|
79 | for the slab creation arguments and if the key is in it's cache |
---|
80 | it will use a pre-generated ILayerSlab object. |
---|
81 | |
---|
82 | """ |
---|
83 | raise NotImplementedError |
---|
84 | |
---|
85 | def getLegendImage(self, orientation='vertical', renderOpts={}): |
---|
86 | """ |
---|
87 | Create an image of the colourbar for this layer. |
---|
88 | |
---|
89 | @param orientation: Either 'vertical' or 'horizontal' |
---|
90 | @return: A PIL image |
---|
91 | |
---|
92 | """ |
---|
93 | raise NotImplementedError |
---|
94 | |
---|
95 | class IDimension(object): |
---|
96 | """ |
---|
97 | @ivar units: The units string. |
---|
98 | @ivar extent: Sequence of extent values. |
---|
99 | |
---|
100 | """ |
---|
101 | units = extent = NotImplemented |
---|
102 | |
---|
103 | class ILayerSlab(object): |
---|
104 | """ |
---|
105 | An interface representing a particular horizontal slice of a WMS layer. |
---|
106 | |
---|
107 | ILayerSlab objects are designed to be convenient to cache. |
---|
108 | They should be pickleable to enable memcached support in the future. |
---|
109 | |
---|
110 | @ivar layer: The source ILayer instance. |
---|
111 | @ivar crs: The coordinate reference system. |
---|
112 | @ivar dimValues: A mapping of dimension values of this view. |
---|
113 | @ivar renderOpts: The renderOpts used to create this view. |
---|
114 | @ivar bbox: The bounding box as a 4-tuple. |
---|
115 | |
---|
116 | """ |
---|
117 | layer = crs = dimValues = renderOpts = bbox = NotImplemented |
---|
118 | |
---|
119 | def getImage(self, bbox, width, height): |
---|
120 | """ |
---|
121 | Create an image of a sub-bbox of a given size. |
---|
122 | |
---|
123 | @ivar bbox: A bbox 4-tuple. |
---|
124 | @ivar width: width in pixels. |
---|
125 | @ivar height: height in pixels. |
---|
126 | @return: A PIL Image object. |
---|
127 | |
---|
128 | """ |
---|
129 | raise NotImplementedError |
---|
130 | |
---|