Changeset 4415 for cows/trunk


Ignore:
Timestamp:
07/11/08 12:08:49 (11 years ago)
Author:
domlowe
Message:
 
Location:
cows/trunk/cows
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cows/trunk/cows/pylons/wfs_controller.py

    r4413 r4415  
    4040 
    4141    service = 'WFS' 
    42     owsOperations = (ows_controller.OWSController.owsOperations + ['DescribeFeatureType', 'GetFeature', 'DescribeStoredQueries','ListStoredQueries']) 
     42    owsOperations = (ows_controller.OWSController.owsOperations + ['DescribeFeatureType', 'GetFeature', 'DescribeStoredQueries','ListStoredQueries', 'GetPropertyValue']) 
    4343    validVersions = ['1.1.0', '2.0.0'] 
    4444     
     
    8888        ows_controller.addOperation('DescribeFeature') 
    8989        ows_controller.addOperation('DescribeStoredQueries') 
     90        ows_controller.addOperation('ListStoredQueries') 
     91        ows_controller.addOperation('GetPropertyValue') 
    9092         
    9193         
     
    131133        log.debug('location of application schema %s' %(xmlschema)) 
    132134        return xmlschema 
     135     
     136    def _runQuery(self, queryxml = None, storedqueryid=None, **kwargs): 
     137        """ this is used by both the GetFeature and GetPropertyValue methods to 
     138        run a wfs:query over a featurecollection and return a subset of the collection.  
     139        The query may be defined as an xml <wfs:query> or may be referenced by a StoredQuery_id  
     140        TODO: handle kwargs to pass to storedquery 
     141        """ 
     142        if queryxml: 
     143            qp=FEQueryProcessor() 
     144            resultset=qp.evaluate(self.featureset, queryxml) 
     145            log.debug('Final resultset from query processor %s'%resultset) 
     146        elif storedqueryid: 
     147            storedquery, func=self.layerMapper.queryDescriptions.queries[storedqueryid] 
     148            resultset=func(self.featureset, **kwargs) 
     149            log.debug('Final resultset from stored query %s'%resultset) 
     150        else: 
     151            resultset=[] 
     152             #TODO need to raise error if neither query or storedquery_id are provided?? 
     153        return  resultset 
    133154 
    134155    def DescribeFeatureType(self): 
     
    150171        return msg 
    151172   
     173    def GetPropertyValue(self): 
     174        """ GetPropertyValue request - similar to get feature but only returns chosen property 
     175        values """ 
     176        valueReference = self.getOwsParam('valueReference') 
     177        queryxml=self.getOwsParam('query',default=None) 
     178        storedqueryid=self.getOwsParam('storedquery_id', default=None) 
     179        #get any other parameters from self._owsParams and pass them to the stored query 
     180        otherparams={} 
     181        for key in self._owsParams.keys(): 
     182            if key not in ['query', 'request', 'service', 'version', 'storedquery_id', 'valuereference']: 
     183                otherparams[key]=self._owsParams[key]      
     184        c.resultset=self._runQuery(queryxml, storedqueryid, **otherparams) 
     185         
     186        #TODO: Now need to take account of valueReference request parameter, and distill the  
     187        #resultset down to just the requested properties. 
     188         
     189         
     190        response.headers['content-type'] = 'text/xml' 
     191        #TODO, new template for values 
     192        t = ows_controller.templateLoader.load('wfs_valuecollection.xml') 
     193        return t.generate(c=c).render()  
     194   
    152195    def GetFeature(self): 
    153196        """ GetFeature request 
    154197        """ 
    155         #TODO QUERY model 
    156198        version = self.getOwsParam('version', default=self.validVersions[0]) 
    157199        if version not in self.validVersions: 
     
    160202 
    161203        #The GetFeature request may either use the 'query' filter encoding or a  
    162         #storedquery, but not both: 
    163 #        if self.getOwsParam('storedquery_id'): 
    164          
     204        #storedquery, but not both:       
    165205        #Parse the query to analyse the filters it contains 
    166206        queryxml=self.getOwsParam('query',default=None) 
    167207        storedqueryid=self.getOwsParam('storedquery_id', default=None) 
    168          
    169         #TODO get any other parameters from self._owsParams and pass them to the stored query        
    170         if queryxml: 
    171             qp=FEQueryProcessor() 
    172             c.resultset=qp.evaluate(self.featureset, queryxml) 
    173             log.debug('Final resultset from query processor %s'%c.resultset) 
    174         elif storedqueryid: 
    175             storedquery, func=self.layerMapper.queryDescriptions.queries[storedqueryid] 
    176             c.resultset=func(self.featureset, arg1='cat', arg2='dog') 
    177             log.debug('Final resultset from stored query %s'%c.resultset) 
    178         else: 
    179             pass #TODO need to raise error if neither query or storedquery_id are provided 
    180208        
     209        #retrieve any other parameters and pass them off to the stored query (they are ignored in the case of the queryxml option 
     210        otherparams={} 
     211        for key in self._owsParams.keys(): 
     212            if key not in ['query', 'request', 'service', 'version', 'storedquery_id']: 
     213                otherparams[key]=self._owsParams[key]        
     214        c.resultset=self._runQuery(queryxml, storedqueryid, **otherparams) 
     215                
    181216        #Group resultset together in a wfs feature collection (use template) 
    182217        response.headers['content-type'] = 'text/xml' 
  • cows/trunk/cows/service/imps/csmlbackend/wfs_csmllayer.py

    r4412 r4415  
    101101        self.queries[qid]=(query, CSMLQueries.query_two_func)       
    102102 
    103          
    104  
    105  
     103        #query to select features by phenomenon 
     104        qid='phenomenonQuery' 
     105        qet=QueryExpressionText('csml:GridSeriesFeature')#TODO, this could definitely differ for different features... 
     106        pex=ParameterExpression('phenomenon', 'string') 
     107        query=StoredQuery(qid, title='SelectFeaturesByPhenomenon', abstract = 'Select features based on their phenomenon type, e.g. "temperature"', queryExpressionText = qet, parameter=pex) 
     108        self.queries[qid]=(query, CSMLQueries.query_getFeatureByPhenomenon) 
    106109 
    107110 
     
    170173         
    171174    def getFeaturesByPropertyEqualTo(self, propertyname, value): 
    172         log.debug('GET FEATURES BY PropertyEqualTo') 
     175        log.debug('GET FEATURES BY PropertyEqualTo, value=%s'%value) 
    173176        result=[] 
     177        value=value #value may be unicode 
    174178        if propertyname == 'csml:parameter': 
    175179            log.debug('filtering on csml:parameter')           
    176180            for featureid,feature in self.featureinstances.iteritems(): 
    177181                if feature._feature.parameter.getStandardName() == value: 
    178                     result.append(feature)         
    179         return result 
     182                    result.append(feature)       
     183                elif feature._feature.parameter.getNonStandardName() == value:                     
     184                    result.append(feature)  
     185            return result 
    180186     
    181187class CSMLFeatureInstance(IFeatureInstance): 
     
    232238         
    233239 
     240 
  • cows/trunk/cows/service/imps/csmlbackend/wfs_csmlstoredqueries.py

    r4408 r4415  
    66""" 
    77 
     8import logging 
     9log = logging.getLogger(__name__) 
     10 
    811class dummyfeaturefortesting(object): 
    912    def __init__(self, x): 
     
    1215        return '<someGML>%s</someGML>'%self.x 
    1316 
    14 def query_one_func(featureset, arg1=None, arg2=None): 
    15     result = [dummyfeaturefortesting('blah1')] 
     17def query_one_func(featureset, arg1='blah1', arg2=None): 
     18    result = [dummyfeaturefortesting(arg1 + ' ' + arg2)] 
    1619    return result 
    1720 
     
    1922    result = [dummyfeaturefortesting('blah2')] 
    2023    return result 
     24 
     25def query_getFeatureByPhenomenon(featureset, phenomenon): 
     26    return featureset.getFeaturesByPropertyEqualTo('csml:parameter', phenomenon)     
Note: See TracChangeset for help on using the changeset viewer.