source: TI05-delivery/ows_framework/branches/ows_framework-ddp/ows_server/ows_server/controllers/ddp_wms.py @ 2707

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/branches/ows_framework-ddp/ows_server/ows_server/controllers/ddp_wms.py@2707
Revision 2707, 4.0 KB checked in by spascoe, 14 years ago (diff)

Basic WMS serving pre-generated images is working. Most of
the configuration stuff is in models/ddp_data.py for now.

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5"""
6Example WMS controller driven by CSML.
7
8@author: Stephen Pascoe
9
10"""
11from ows_server.lib.base import *
12from ows_server.lib.decorators import *
13from ows_server.lib import grid_util, render
14import ows_server.lib.validators as V
15
16from ows_common import exceptions as OWS_E
17from ows_common.wms import *
18from ows_common.common import BoundingBox
19from ows_common.domain import ValuesUnit, PossibleValues
20
21from ows_server.models import ddp_data
22
23#import cdms
24import os, sys
25from cStringIO import StringIO
26#import MA
27
28class DdpWmsController(OwsController):
29
30    _ows_parameters = {
31        'Format': make_domain(['text/xml']),
32        'ExceptionFormat': make_domain(['text/xml']),
33        }
34
35    #_ows_constraints = {
36        # MaximumLayerLevels
37        # MaximumWidth
38        # MaximumWidth
39    #    }
40
41    def _loadCapabilities(self):
42        """
43        Overriding subclass to add layer capabilities
44
45        """
46        # Get default capabilities from superclass
47        sm = super(DdpWmsController, self)._loadCapabilities()
48
49        # For WMS 1.3.0 compatibility we need a single root DatasetSummary
50        ds = WmsDatasetSummary(titles=['DDP Test dataset (afixaa.pei3aug.pp)'],
51                               datasetSummaries=[],
52                               CRSs=['CRS:84'])
53        # Add a DatasetSummary for each feature       
54        #for f_n in c.dataset.getFeatureList():
55        #    feature_ds = self._loadFeatureSummary(c.dataset.getFeature(f_n))
56        #    ds.datasetSummaries.append(feature_ds)
57
58        sm.contents = Contents(datasetSummaries=[ds])
59        return sm
60
61   
62    @operation
63    @parameter('Format', possibleValues=['text/xml'])
64    @parameter('Service', possibleValues=['WMS'], required=True)
65    @parameter('Version', possibleValues=['1.3.0'])
66    def GetCapabilities(self, file, service=None, version=None):
67        """
68        @note: format and updatesequence parameters are not supported
69            by this WMS.
70
71        """
72        # Populate the context object with information required by the template
73        c.dataset = csmlCache[file]
74
75        return self._renderCapabilities('ows/wms_capabilities')
76
77
78    @operation
79    @parameter('Version', possibleValues=['1.3.0'], required=True)
80    @parameter('Layers', required=True, validator=V.single_layer)
81    @parameter('Styles', required=True)
82    @parameter('CRS', possibleValues=['CRS:84'], required=True)
83    @parameter('Bbox', required=True, validator=V.bbox_2d)
84    @parameter('Width', required=True, validator=V.integer('Width'))
85    @parameter('Height', required=True, validator=V.integer('Height'))
86    @parameter('Format', required=True)
87    @parameter('Transparent', validator=V.boolean('Transparent'))
88    @parameter('Bgcolor')
89    @parameter('Exceptions')
90    # Dimension parameters Time, Elevation, etc. are handled separately
91    def GetMap(self, version, layers, styles, crs, bbox, width, height, format,
92               transparent=False, bgcolor=None, exceptions=None):
93
94        variable = layers
95       
96        # Check the layer refers to an available variable
97        if variable not in ddp_data.variables:
98            raise OWS_E.InvalidParameterValue('Layer not found', 'layers')     
99
100        # Parse time dimension.
101        try:
102            time = self.ows_params['time']
103        except KeyError:
104            raise OWS_E.MissingParameterValue('time dimension not specified', 'time')
105
106        if time not in ddp_data.time_domain:
107            raise OWS_E.InvaludParameterValue('time dimension value incorrect', 'time')
108           
109        # Get the PIL image for this variable/time
110        img = ddp_data.get_image_subset(variable, time, bbox, width, height)
111
112        # Serialise it to PNG
113        buf = StringIO()
114        img.save(buf, 'PNG')
115
116        return Response(content=buf.getvalue(), mimetype='image/png')
Note: See TracBrowser for help on using the repository browser.