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

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

prototype support for attributes in getpropertyvalue method - need to check with ogc.

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
17from pylons import request, config
18
19class dummyfeaturefortesting(object):
20    def __init__(self, x):
21        self.x=x
22    def toGML(self):
23        return '<someGML>%s</someGML>'%self.x
24
25def query_one_func(featureset, arg1='blah1', arg2=None):
26    result = [dummyfeaturefortesting(arg1 + ' ' + arg2)]
27    return result
28
29def query_two_func(featureset, arg1=None, arg2=None):
30    result = [dummyfeaturefortesting('blah2')]
31    return result
32
33def query_getFeatureByPhenomenon(featureset, phenomenon):
34    return featureset.getFeaturesByPropertyEqualTo('csml:parameter', phenomenon)   
35
36def query_extractPointFromPointSeries(featureset, featureid, timeinstance):
37    #TODO:  configure output directory
38    #TODO: error handling
39    csmloutputdir=config['publish_dir']
40    feature=featureset.getFeatureByGMLid(featureid)._feature
41    newfeature, netcdfpath, storagedescriptor=feature.subsetToPoint(time=str(timeinstance), outputdir=csmloutputdir)       
42    #wrap this in a wfs CSMLFeatureInstance object:
43    csmlfi=wfs_csmllayer.CSMLFeatureInstance('subset feature title', 'subset feature abstract', newfeature)
44    #And serialise the storage descriptor as XML.
45    qualifiedFeatureType='{http://ndg.nerc.ac.uk/csml}' + storagedescriptor.__class__.__name__
46    emptyelem=etree.Element(qualifiedFeatureType)
47    log.debug(request.environ)
48    #change the path of the storage descriptor to the download url - assumes routes maps to filestore
49    storagedescriptor.fileName.CONTENT='http://'+request.environ['HTTP_HOST']+'/filestore/' +storagedescriptor.fileName.CONTENT
50    csmlelem=storagedescriptor.toXML(emptyelem)
51    storagedescXML=etree.tostring(csmlelem)     
52    return [csmlfi], [storagedescXML]
Note: See TracBrowser for help on using the repository browser.