source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_wms.py @ 2577

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_wms.py@2577
Revision 2577, 4.3 KB checked in by spascoe, 12 years ago (diff)

More consistent method naming. Using lowerCamelCase for methods but
underscore_separated names for internal variables, functions and modules.

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"""
10from ows_server.lib.base import *
11from ows_server.controllers.csml_api import get_csml_doc
12from ows_server.lib.decorators import *
13
14from elementtree import ElementTree as ET
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.lib.csml_util import get_csml_doc
22
23
24class CsmlWmsController(OwsController):
25
26    _ows_parameters = {
27        'Format': make_domain(['text/xml']),
28        'ExceptionFormat': make_domain(['text/xml']),
29        }
30
31    #_ows_constraints = {
32        # MaximumLayerLevels
33        # MaximumWidth
34        # MaximumWidth
35    #    }
36
37
38    def _loadFeatureDimensions(self, feature):
39        dims = {}
40        #!WARNING
41        # This bit is a hack until the CSML API implements a mechanism
42        # to determine which elements of a domain are longitude and latitude.
43        for axis_name, axis in feature.getDomain().iteritems():
44            if axis_name in ['longitude', 'latitude']:
45                continue
46            dims[axis_name] = Domain(possibleValues=PossibleValues.fromAllowedValues(axis),
47                                     #!TODO: this is a fudge until we can deduce UOM.
48                                     valuesUnit=ValuesUnit(uoms=[''],
49                                                           referenceSystems=['']))
50        return dims
51
52    def _loadFeatureSummary(self, feature):
53        dims = self._loadFeatureDimensions(feature)
54       
55        return WmsDatasetSummary(identifier=feature.id,
56                                 titles=[feature.description.CONTENT],
57                                 boundingBoxes=[BoundingBox([-180,-90], [180,90],
58                                                            crs='CRS:84')],
59                                 dimensions=dims,               
60                                 )
61
62    def _loadCapabilities(self):
63        """
64        Overriding subclass to add layer capabilities
65
66        """
67        # Get default capabilities from superclass
68        sm = super(CsmlWmsController, self)._loadCapabilities()
69
70        # For WMS 1.3.0 compatibility we need a single root DatasetSummary
71        ds = WmsDatasetSummary(titles=['Root Dataset'], datasetSummaries=[],
72                               CRSs=['CRS:84'])
73        # Add a DatasetSummary for each feature       
74        for f_n in c.dataset.getFeatureList():
75            feature_ds = self._loadFeatureSummary(c.dataset.getFeature(f_n))
76            ds.datasetSummaries.append(feature_ds)
77
78        sm.contents = Contents(datasetSummaries=[ds])
79        return sm
80
81   
82    @operation
83    @parameter('Format', possibleValues=['text/xml'])
84    @parameter('Service', possibleValues=['WMS'], required=True)
85    @parameter('Version', possibleValues=['1.3.0'])
86    def GetCapabilities(self, file, service=None, version=None):
87        """
88        @note: format and updatesequence parameters are not supported
89            by this WMS.
90
91        """
92       
93        # Populate the context object with information required by the template
94        c.dataset = get_csml_doc(file)
95
96        return self._renderCapabilities('ows/wms_capabilities')
97
98
99    @operation
100    @parameter('Version', possibleValues=['1.3.0'], required=True)
101    @parameter('Layers', required=True)
102    @parameter('Styles', required=True)
103    @parameter('CRS', possibleValues=['CRS:84'], required=True)
104    @parameter('Bbox', required=True)
105    @parameter('Width', required=True)
106    @parameter('Height', required=True)
107    @parameter('Format', required=True)
108    @parameter('Transparent')
109    @parameter('Bgcolor')
110    @parameter('Exceptions')
111    # Dimension parameters Time, Elevation, etc. are handled separately
112    def GetMap(self, version, layers, styles, crs, bbox, width, height, format,
113               transparent, bgcolor, exceptions):
114
115        dataset = get_csml_doc(file)
116
117        # Support a single layer only
118        layer_list = layers.split(',')
119        if len(layer_list) > 1:
120            raise OWS_E.InvalidParameterValue('Only one layer supported per request', 'layers')
121
122       
Note: See TracBrowser for help on using the repository browser.