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

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

Many changes to implement Dimension elements in the Capabilities document.

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
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 _load_feature_ds(self, feature):
39
40        dims = {}
41        #!WARNING
42        # This bit is a hack until the CSML API implements a mechanism
43        # to determine which elements of a domain are longitude and latitude.
44        for axis_name, axis in feature.getDomain().iteritems():
45            if axis_name in ['longitude', 'latitude']:
46                continue
47            dims[axis_name] = make_domain(possibleValues=axis,
48                                          #!TODO: this is a fudge until we can deduce UOM.
49                                          valuesUnit=ValuesUnit(uoms=[''],
50                                                                referenceSystems=['']))
51       
52        return WmsDatasetSummary(identifier=feature.id,
53                                 titles=[feature.description.CONTENT],
54                                 boundingBoxes=[BoundingBox([-180,-90], [180,90],
55                                                            crs='CRS:84')],
56                                 dimensions=dims,
57                                 
58                                 )
59       
60
61    def _load_capabilities(self):
62        """
63        Overriding subclass to add layer capabilities
64
65        """
66        # Get default capabilities from superclass
67        sm = super(CsmlWmsController, self)._load_capabilities()
68
69        # For WMS 1.3.0 compatibility we need a single root DatasetSummary
70        ds = WmsDatasetSummary(titles=['Root Dataset'], datasetSummaries=[],
71                               CRSs=['CRS:84'])
72        # Add a DatasetSummary for each feature       
73        for f_n in c.dataset.getFeatureList():
74            feature_ds = self._load_feature_ds(c.dataset.getFeature(f_n))
75            ds.datasetSummaries.append(feature_ds)
76
77        sm.contents = Contents(datasetSummaries=[ds])
78        return sm
79
80   
81    @operation
82    @parameter('Format', possibleValues=['text/xml'])
83    @parameter('Service', possibleValues=['WMS'], required=True)
84    @parameter('Version', possibleValues=['1.3.0'])
85    def GetCapabilities(self, file, service=None, version=None):
86        """
87        @note: format and updatesequence parameters are not supported
88            by this WMS.
89
90        """
91       
92        # Populate the context object with information required by the template
93        c.dataset = get_csml_doc(file)
94
95        return self._render_capabilities('ows/wms_capabilities')
96
97
98    @operation
99    @parameter('Version', possibleValues=['1.3.0'], required=True)
100    @parameter('Layers', required=True)
101    @parameter('Styles', required=True)
102    @parameter('CRS', possibleValues=['CRS:84'], required=True)
103    @parameter('Bbox', required=True)
104    @parameter('Width', required=True)
105    @parameter('Height', required=True)
106    @parameter('Format', required=True)
107    @parameter('Transparent')
108    @parameter('Bgcolor')
109    @parameter('Exceptions')
110    # Dimension parameters Time, Elevation, etc. are handled separately
111    def GetMap(self, version, layers, styles, crs, bbox, width, height, format,
112               transparent, bgcolor, exceptions):
113        pass
Note: See TracBrowser for help on using the repository browser.