Changeset 4359


Ignore:
Timestamp:
27/10/08 12:47:54 (11 years ago)
Author:
domlowe
Message:

wfs filtering by bbox working with pointseries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cows/trunk/cows/service/imps/csmlbackend/wfs_csmllayer.py

    r4354 r4359  
    88import csml 
    99from xml.etree import ElementTree as etree 
    10 from shapely.geometry import Polygon 
     10from shapely.geometry import Polygon, Point 
    1111from cows.bbox_util import union 
    1212 
     
    9090     
    9191    def _checkforOverlap(self, filterbbox, featurebbox): 
    92         """ Uses Shapely Polygons to calculate bounding box intersections """         
     92        """ Uses Shapely Polygons to calculate bounding box intersections """ 
     93        log.debug('comparing against %s'%str(filterbbox))         
    9394        filterpolygon=Polygon(((filterbbox[0],filterbbox[1]),(filterbbox[0],filterbbox[3]),(filterbbox[2],filterbbox[3]),(filterbbox[2],filterbbox[1]))) 
    9495        featurepolygon=Polygon(((featurebbox[0],featurebbox[1]),(featurebbox[0],featurebbox[3]),(featurebbox[2],featurebbox[3]),(featurebbox[2],featurebbox[1])))         
     96        log.debug(dir(filterpolygon)) 
     97        log.debug('intersect result%s'%featurepolygon.intersects(filterpolygon)) 
    9598        return filterpolygon.intersects(featurepolygon) 
     99     
     100    def _checkforPointinBox(self, filterbbox, location): 
     101        """ Uses Shapely Polygons to calculate bounding box intersections """ 
     102        log.debug('comparing against %s'%str(filterbbox))         
     103        filterpolygon=Polygon(((filterbbox[0],filterbbox[1]),(filterbbox[0],filterbbox[3]),(filterbbox[2],filterbbox[3]),(filterbbox[2],filterbbox[1]))) 
     104        featurepoint=Point(float(location[0]), float(location[1])) 
     105        log.debug(featurepoint.within(filterpolygon)) 
     106        log.debug('intersect result%s'%featurepoint.intersects(filterpolygon)) 
     107        return featurepoint.intersects(filterpolygon) 
    96108     
    97109    def getFeaturesByBBox(self,bboxtuple, srsname):           
    98110        log.debug('GET FEATURES BY BBOX') 
    99111        result=[] 
     112        log.debug('Request BBOX: %s %s'%(bboxtuple,srsname)) 
    100113        for featureid,feature in self.featureinstances.iteritems(): 
    101             try: 
     114            if hasattr(feature._feature, 'boundedBy'): 
     115                log.debug('Checking bbox for feature %s: '%feature._feature.id) 
    102116                lowercorner=feature._feature.boundedBy.lowerCorner.CONTENT.split() 
    103117                uppercorner=feature._feature.boundedBy.upperCorner.CONTENT.split() 
    104                 featurebbox=(float(lowercorner[0]), float(lowercorner[1]), float(uppercorner[0]), float(uppercorner[1])) 
     118                featurebbox=(float(lowercorner[0]), float(lowercorner[1]), float(uppercorner[0]), float(uppercorner[1]))                 
    105119                if self._checkforOverlap(bboxtuple, featurebbox): 
    106                     result.append(feature) 
    107             except AttributeError: #sometimes the features don't have the bounding box metadata 
    108                 pass 
     120                    result.append(feature)   
     121            elif hasattr(feature._feature, 'location'): 
     122                log.debug('Checking location for feature %s: '%feature._feature.id) 
     123                log.debug(feature._feature.location) 
     124                location=feature._feature.location.CONTENT.split() 
     125                if self._checkforPointinBox(bboxtuple, location): 
     126                    result.append(feature)                         
    109127        return result 
    110128 
Note: See TracChangeset for help on using the changeset viewer.