source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_wcs.py @ 2600

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_wcs.py@2600
Revision 2600, 4.7 KB checked in by domlowe, 14 years ago (diff)

temporal and spatial subsetting basics working for wcs

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"""
6WCS controller driven by CSML.
7
8@author: DominicLowe, Stephen Pascoe
9"""
10
11#NOTE, much of this is straight from WMS and needs to be overhauled.
12
13from ows_server.lib.base import *
14from ows_server.controllers.csml_api import get_csml_doc
15from ows_server.lib.decorators import *
16import ows_server.lib.validators as V
17
18from elementtree import ElementTree as ET
19from ows_common import exceptions as OWS_E
20from ows_common.wcs import *
21from ows_common.common import BoundingBox
22from ows_common.domain import ValuesUnit, PossibleValues
23
24from ows_server.lib.csml_util import get_csml_doc, extractToNetCDF
25
26
27
28class CsmlWcsController(OwsController):
29    _ows_parameters = {
30        'Format': make_domain(['text/xml']),
31        'ExceptionFormat': make_domain(['text/xml']),
32        }
33
34    #_ows_constraints = {
35        # MaximumLayerLevels
36        # MaximumWidth
37        # MaximumWidth
38    #    }
39
40
41    def _loadFeatureDimensions(self, feature):
42        dims = {}
43        #!WARNING
44        # This bit is a hack until the CSML API implements a mechanism
45        # to determine which elements of a domain are longitude and latitude.
46        for axis_name, axis in feature.getDomain().iteritems():
47            if axis_name in ['longitude', 'latitude']:
48                continue
49            dims[axis_name] = Domain(possibleValues=PossibleValues.fromAllowedValues(axis),
50                                     #!TODO: this is a fudge until we can deduce UOM.
51                                     valuesUnit=ValuesUnit(uoms=[''],
52                                                           referenceSystems=['']))
53        return dims
54
55    def _loadFeatureSummary(self, feature):
56        dims = self._loadFeatureDimensions(feature)
57        return WcsDatasetSummary(identifier=feature.id,
58                                 titles=[feature.description.CONTENT],
59                                 boundingBoxes=[BoundingBox([-180,-90], [180,90],
60                                                            crs='CRS:84')],
61                                 dimensions=dims, description=feature.description.CONTENT           
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(CsmlWcsController, self)._loadCapabilities()
71
72
73        ds = WcsDatasetSummary(titles=['Root Dataset'], datasetSummaries=[], CRSs=['CRS:84'])
74        # Add a DatasetSummary for each feature       
75        for f_n in c.dataset.getFeatureList():           
76            feature_ds = self._loadFeatureSummary(c.dataset.getFeature(f_n))
77            ds.datasetSummaries.append(feature_ds)
78
79        sm.contents = Contents(datasetSummaries=[ds])
80        return sm
81
82   
83    @operation
84    @parameter('Format', possibleValues=['text/xml'])
85    @parameter('Service', possibleValues=['WCS'], required=True)
86    @parameter('Version', possibleValues=['1.1.0'])
87    def GetCapabilities(self, file, service=None, version=None):
88        """
89        @note: format and updatesequence parameters are not supported
90            by this WMS.
91
92        """
93       
94        # Populate the context object with information required by the template
95        c.dataset = get_csml_doc(file)
96
97        return self._renderCapabilities('ows/wcs_capabilities')
98
99
100    @operation
101    @parameter('Version', possibleValues=['1.1.0'], required=True)
102    @parameter('Identifier', required=True)
103    @parameter('BoundingBox', required=True, validator=V.bbox_2d)
104    @parameter('TimeSequence',required=True)  #TODO, need validator to handle iso8601 time strings
105    @parameter('Format', possibleValues=['image/netcdf'], required=True)
106   
107    #TODO some more parameter to add here
108    # Dimension parameters Time, Elevation, etc. are handled separately
109    def GetCoverage(self, file, version, format, identifier, boundingbox, timesequence):
110       
111        # Retrieve dataset and selected feature
112        dataset = get_csml_doc(file)
113        feature = dataset.getFeature(identifier)
114        if feature is None:
115            raise OWS_E.InvalidParameterValue('Coverage not found', 'identifier')
116
117        #set bounding box TODO
118        sel = dict(latitude=(boundingbox[1], boundingbox[3]), longitude=(boundingbox[0], boundingbox[2]))
119        sel['time']=timesequence #needs validating
120       
121        # Extract via CSML.subsetToGridSeries()
122        filename = extractToNetCDF(feature, sel)
123        netcdfFile=open(filename, 'r')
124        return Response(content=netcdfFile, mimetype='image/netcdf')
Note: See TracBrowser for help on using the repository browser.