source: cows/trunk/cows/service/imps/csmlbackend/ @ 4439

Subversion URL:
Revision 4439, 3.7 KB checked in by domlowe, 12 years ago (diff)

Support for gridseries subsetting stored query

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:
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.
11import wfs_csmllayer
13import logging
14log = logging.getLogger(__name__)
15import csml.parser
16from xml.etree import ElementTree as etree
17from pylons import request, config
19class dummyfeaturefortesting(object):
20    def __init__(self, x):
21        self.x=x
22    def toGML(self):
23        return '<someGML>%s</someGML>'%self.x
25def query_one_func(featureset, arg1='blah1', arg2=None):
26    result = [dummyfeaturefortesting(arg1 + ' ' + arg2)]
27    return result
29def query_two_func(featureset, arg1=None, arg2=None):
30    result = [dummyfeaturefortesting('blah2')]
31    return result
33def query_getFeatureByPhenomenon(featureset, phenomenon):
34    return featureset.getFeaturesByPropertyEqualTo('csml:parameter', phenomenon)   
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='{}' + 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]
54def query_extractGridSeriesFromGridSeries(featureset, featureid, bbox, timerange):
55    #TODO factor out code in common with other subsetting queries
56    csmloutputdir=config['publish_dir']
57    feature=featureset.getFeatureByGMLid(featureid)._feature
58    #break the bounding box into latitude and longitude:
59    #TODO, this really needs to be generic and refer to the srs of the underlying feature.
60    bb=str(bbox).split(',')
61    lat=(float(bb[1]),float(bb[3]))
62    lon=(float(bb[0]),float(bb[2]))
63    log.debug('requesting latitude: %s, longitude: %s'%(lat, lon))
64    newfeature, netcdfpath, storagedescriptor=feature.subsetToGridSeries(time=str(timerange), latitude=lat, longitude=lon, outputdir=csmloutputdir)
65    #wrap this in a wfs CSMLFeatureInstance object:
66    csmlfi=wfs_csmllayer.CSMLFeatureInstance('subset feature title', 'subset feature abstract', newfeature)
67    #And serialise the storage descriptor as XML.
68    qualifiedFeatureType='{}' + storagedescriptor.__class__.__name__
69    emptyelem=etree.Element(qualifiedFeatureType)
70    log.debug(request.environ)
71    #change the path of the storage descriptor to the download url - assumes routes maps to filestore
72    storagedescriptor.fileName.CONTENT='http://'+request.environ['HTTP_HOST']+'/filestore/' +storagedescriptor.fileName.CONTENT
73    csmlelem=storagedescriptor.toXML(emptyelem)
74    storagedescXML=etree.tostring(csmlelem)
75    return [csmlfi], [storagedescXML]
Note: See TracBrowser for help on using the repository browser.