Ignore:
Timestamp:
11/11/08 10:05:31 (12 years ago)
Author:
domlowe
Message:

Implemented first cut of GetPropertyValue? method for wfs

File:
1 edited

Legend:

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

    r4415 r4417  
    1111from pylons import request, response, c, config 
    1212import ConfigParser 
    13  
     13import xml.etree.ElementTree as etree 
    1414import logging 
    1515log = logging.getLogger(__name__) 
     
    122122         
    123123    def _parsetypename(self, typename): 
    124         """ parse feature type name into schema and name"""        
     124        """ parse feature type name into schema and name and return schema"""        
    125125        if typename not in self.layers.keys(): 
    126126            raise InvalidParameterValue('Invalid typename parameter: %s. Typename must consist of namespace and featuretype separated with a colon, as displayed in the GetCapabilities response.'%typename, 'typename') 
     
    138138        run a wfs:query over a featurecollection and return a subset of the collection.  
    139139        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 
    141140        """ 
    142141        if queryxml: 
     
    148147            resultset=func(self.featureset, **kwargs) 
    149148            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?? 
     149        else:            
     150            #If neither query or storedquery_id are provided then return entire featureset 
     151            resultset=self.featureset.getFeatureList() 
    153152        return  resultset 
    154153 
     154    def _applyXPath(self, xpath, features): 
     155        """ applies an xpath expression to a set of features and returns  
     156        a set of wfs:members containing property values expressed in the xpath""" 
     157        resultset=[]         
     158        for feature in features: 
     159            featureXML=feature._feature.elem #the underlying XML 
     160            valuecomponent=featureXML.find(xpath) 
     161            if valuecomponent is not None: 
     162                valstr=etree.tostring(valuecomponent)            
     163                resultset.append(valstr) 
     164        return resultset       
     165     
     166     
    155167    def DescribeFeatureType(self): 
    156168        """ DescribeFeatureType """ 
     
    170182        response.headers['content-type'] = 'text/xml' 
    171183        return msg 
     184             
    172185   
    173186    def GetPropertyValue(self): 
     
    182195            if key not in ['query', 'request', 'service', 'version', 'storedquery_id', 'valuereference']: 
    183196                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  
     197        featureresultset=self._runQuery(queryxml, storedqueryid, **otherparams)         
     198        
     199        #Now need to take account of valueReferencexpath, and distill the  
    187200        #resultset down to just the requested properties. 
    188          
     201        c.resultset=self._applyXPath(valueReference, featureresultset) 
    189202         
    190203        response.headers['content-type'] = 'text/xml' 
Note: See TracChangeset for help on using the changeset viewer.