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

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

Validators provide a mechanism for type checking operation parameters.
This is slightly at odds with the Domain.isValidValue() way of doing
things: something that will need resolving eventually.

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