Changeset 5133 for cows


Ignore:
Timestamp:
23/03/09 13:22:38 (10 years ago)
Author:
domlowe
Message:

supporting maxfeatures keyword

File:
1 edited

Legend:

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

    r5132 r5133  
    141141        return xmlschema 
    142142     
    143     def _runQuery(self, queryxml = None, storedqueryid=None, typename=None, **kwargs): 
     143    def _runQuery(self, queryxml = None, storedqueryid=None, typename=None, maxfeatures=None,**kwargs): 
    144144        """ this is used by both the GetFeature and GetPropertyValue methods to 
    145145        run a wfs:query over a featurecollection and return a subset of the collection.  
     
    161161            log.debug('Final resultset from stored query %s'%resultset) 
    162162        else:            
    163             #If neither query or storedquery_id are provided then return entire featureset, filtered on 'typename' if supplied. 
     163            #If neither query or storedquery_id are provided then return entire featureset, filtered on 'typename' and/or 'maxfeatures' if supplied. 
    164164            resultset=self.featureset.getFeatureList() 
    165165            if typename: 
    166166                templist = resultset[:] 
    167                 for feature in templist: 
     167                for feature in templist:   #remove any features of the wrong feature type 
    168168                    if feature.featuretype != typename: 
    169169                        resultset.remove(feature) 
    170170                resultset=resultset 
     171                if maxfeatures: #reduce the response to the requested number of feature instances 
     172                    maxf=int(maxfeatures) 
     173                    if len(resultset) >maxf: 
     174                        resultset=resultset[:maxf] 
    171175        return resultset, additionalobjects 
    172176 
     
    261265        storedqueryid=self.getOwsParam('storedquery_id', default=None) 
    262266        typename=self.getOwsParam('typename', default=None) 
     267        maxfeatures=self.getOwsParam('maxfeatures', default=None) 
    263268        
    264269        #retrieve any other parameters and pass them off to the stored query (they are ignored in the case of the queryxml option 
    265270        otherparams={} 
    266271        for key in self._owsParams.keys(): 
    267             if key not in ['query', 'request', 'service', 'version', 'storedquery_id', 'typename']: 
     272            if key not in ['query', 'request', 'service', 'version', 'storedquery_id', 'typename', 'maxfeatures']: 
    268273                otherparams[key]=self._owsParams[key]        
    269         c.resultset, c.additionalobjects=self._runQuery(queryxml, storedqueryid, typename, **otherparams) 
     274        c.resultset, c.additionalobjects=self._runQuery(queryxml, storedqueryid, typename, maxfeatures, **otherparams) 
    270275                
    271276        #Group resultset together in a wfs feature collection (use template) 
Note: See TracChangeset for help on using the changeset viewer.