Changeset 4422 for cows/trunk


Ignore:
Timestamp:
11/11/08 16:45:48 (11 years ago)
Author:
domlowe
Message:

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

Location:
cows/trunk/cows
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cows/trunk/cows/pylons/templates/wfs_featurecollection.xml

    r4300 r4422  
    99<wfs:FeatureCollection xmlns:py="http://genshi.edgewall.org/" 
    1010                  xmlns:wfs="http://www.opengis.net/wfs" 
    11                   xmlns:gml="http://www.opengis.net/gml">        
    12         <gml:FeatureMember py:for="feature in c.resultset" 
     11                  xmlns:gml="http://www.opengis.net/gml" 
     12                  xmlns:csml="http://ndg.nerc.ac.uk/csml">       
     13        <wfs:member py:for="feature in c.resultset" 
    1314             py:content="XML(feature.toGML())"/> 
     15        <wfs:AdditionalObjects> 
     16                <wfs:member py:for="addobj in c.additionalobjects" 
     17                        py:content="XML(addobj)"/> 
     18        </wfs:AdditionalObjects> 
    1419</wfs:FeatureCollection> 
    1520                   
  • cows/trunk/cows/pylons/wfs_controller.py

    r4417 r4422  
    139139        The query may be defined as an xml <wfs:query> or may be referenced by a StoredQuery_id  
    140140        """ 
     141        additionalobjects=[] #not implemented for filter encoding, just for storedqueries (e.g. subsetting) 
    141142        if queryxml: 
    142143            qp=FEQueryProcessor() 
     
    145146        elif storedqueryid: 
    146147            storedquery, func=self.layerMapper.queryDescriptions.queries[storedqueryid] 
    147             resultset=func(self.featureset, **kwargs) 
     148            storedqueryresult=func(self.featureset, **kwargs) 
     149            if len(storedqueryresult) == 2: 
     150                resultset=storedqueryresult[0] 
     151                additionalobjects=storedqueryresult[1] 
     152            else: 
     153                resultset=storedqueryresult 
    148154            log.debug('Final resultset from stored query %s'%resultset) 
    149155        else:            
    150156            #If neither query or storedquery_id are provided then return entire featureset 
    151157            resultset=self.featureset.getFeatureList() 
    152         return  resultset 
     158        return resultset, additionalobjects 
    153159 
    154160    def _applyXPath(self, xpath, features): 
     
    195201            if key not in ['query', 'request', 'service', 'version', 'storedquery_id', 'valuereference']: 
    196202                otherparams[key]=self._owsParams[key]      
    197         featureresultset=self._runQuery(queryxml, storedqueryid, **otherparams)         
     203        featureresultset, additionalobjects =self._runQuery(queryxml, storedqueryid, **otherparams)         
    198204        
    199205        #Now need to take account of valueReferencexpath, and distill the  
     
    225231            if key not in ['query', 'request', 'service', 'version', 'storedquery_id']: 
    226232                otherparams[key]=self._owsParams[key]        
    227         c.resultset=self._runQuery(queryxml, storedqueryid, **otherparams) 
     233        c.resultset, c.additionalobjects=self._runQuery(queryxml, storedqueryid, **otherparams) 
    228234                
    229235        #Group resultset together in a wfs feature collection (use template) 
  • cows/trunk/cows/service/imps/csmlbackend/wfs_csmllayer.py

    r4417 r4422  
    77from cows.service.wfs_iface import * 
    88from cows.model.storedquery import * 
    9 import csml 
     9import csml.parser 
    1010from xml.etree import ElementTree as etree 
    1111from shapely.geometry import Polygon, Point 
     
    107107        query=StoredQuery(qid, title='SelectFeaturesByPhenomenon', abstract = 'Select features based on their phenomenon type, e.g. "temperature"', queryExpressionText = qet, parameter=pex) 
    108108        self.queries[qid]=(query, CSMLQueries.query_getFeatureByPhenomenon) 
     109         
     110        #query to extract a PointFeature from a PointSeriesFeature 
     111        qid='extractPointFromPointSeries' 
     112        qet=QueryExpressionText('csml:PointFeature') 
     113        pex=ParameterExpression('timeinstance', 'string') 
     114        query=StoredQuery(qid, title='SelectFeaturesByPhenomenon', abstract = 'Extract a csml:PointFeature for a single time instance from a csml:PointSeriesFeature', queryExpressionText = qet, parameter=pex) 
     115        self.queries[qid]=(query, CSMLQueries.query_extractPointFromPointSeries) 
    109116 
    110117 
     
    210217    def toGML(self): 
    211218        """ Create a GML (CSML) representation of the feature """ 
    212          
    213         #TODO un-hardcode this: 
    214         emptyelem=etree.Element('{http://ndg.nerc.ac.uk/csml}GridSeriesFeature') 
     219        qualifiedFeatureType='{http://ndg.nerc.ac.uk/csml}' + self.featuretype 
     220        emptyelem=etree.Element(qualifiedFeatureType) 
    215221        csmlelem=self._feature.toXML(emptyelem) 
    216222        return etree.tostring(csmlelem) 
  • cows/trunk/cows/service/imps/csmlbackend/wfs_csmlstoredqueries.py

    r4415 r4422  
    44 
    55wfs_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. 
    610""" 
     11import wfs_csmllayer 
    712 
    813import logging 
    914log = logging.getLogger(__name__) 
     15import csml.parser 
     16from xml.etree import ElementTree as etree 
    1017 
    1118class dummyfeaturefortesting(object): 
     
    2532def query_getFeatureByPhenomenon(featureset, phenomenon): 
    2633    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 TracChangeset for help on using the changeset viewer.