source: cows/trunk/cows/service/imps/csmlbackend/wfs_csmlstoredqueries.py @ 4422

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/service/imps/csmlbackend/wfs_csmlstoredqueries.py@4422
Revision 4422, 1.9 KB checked in by domlowe, 12 years ago (diff)

Extended framework to allow for wfs:AdditionalObjects - which can be used for csml storage descriptors.

Line 
1""" This module contains CSML WFS 2.0 stored query implementations.
2To add a new stored query, write the functional code here, then describe the functionality as
3a new query in:
4
5wfs_csmllayer.CSMLStoredQueries.queries
6
7These query functions should either return a resultset (python list) containing the features,
8or 2 lists, one being the resultset, and the other containing string representations of XML addtional
9objects - in CSML these are going to be StorageDescriptors.
10"""
11import wfs_csmllayer
12
13import logging
14log = logging.getLogger(__name__)
15import csml.parser
16from xml.etree import ElementTree as etree
17
18class dummyfeaturefortesting(object):
19    def __init__(self, x):
20        self.x=x
21    def toGML(self):
22        return '<someGML>%s</someGML>'%self.x
23
24def query_one_func(featureset, arg1='blah1', arg2=None):
25    result = [dummyfeaturefortesting(arg1 + ' ' + arg2)]
26    return result
27
28def query_two_func(featureset, arg1=None, arg2=None):
29    result = [dummyfeaturefortesting('blah2')]
30    return result
31
32def query_getFeatureByPhenomenon(featureset, phenomenon):
33    return featureset.getFeaturesByPropertyEqualTo('csml:parameter', phenomenon)   
34
35def query_extractPointFromPointSeries(featureset, timeinstance):
36    #TODO:  configure output directory
37    #TODO: error handling
38    feature=featureset.getFeatureByGMLid('S9c7oW2p')._feature
39    newfeature, netcdfpath, storagedescriptor=feature.subsetToPoint(time=str(timeinstance), outputdir='/home/dom/csmlstore/csmlout')       
40    #wrap this in a wfs CSMLFeatureInstance object:
41    csmlfi=wfs_csmllayer.CSMLFeatureInstance('subset feature title', 'subset feature abstract', newfeature)
42    #And serialise the storage descriptor as XML.
43    qualifiedFeatureType='{http://ndg.nerc.ac.uk/csml}' + storagedescriptor.__class__.__name__
44    emptyelem=etree.Element(qualifiedFeatureType)
45    csmlelem=storagedescriptor.toXML(emptyelem)
46    storagedescXML=etree.tostring(csmlelem)     
47    return [csmlfi], [storagedescXML]
Note: See TracBrowser for help on using the repository browser.