Changeset 4312 for cows/trunk/cows


Ignore:
Timestamp:
08/10/08 16:19:56 (11 years ago)
Author:
domlowe
Message:

getFeaturesByBBox implemented using shapely polygons for intersection.

File:
1 edited

Legend:

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

    r4311 r4312  
    88import csml 
    99from xml.etree import ElementTree as etree 
     10from shapely.geometry import Polygon 
    1011 
    1112import logging 
     
    8586        return self.featureinstances[gmlid] 
    8687     
    87     def getFeaturesByBBox(self,bboxtuple, srsname): 
    88         #dummy   
     88    def _checkforOverlap(self, filterbbox, featurebbox): 
     89        """ Uses Shapely Polygons to calculate bounding box intersections """         
     90        filterpolygon=Polygon(((filterbbox[0],filterbbox[1]),(filterbbox[0],filterbbox[3]),(filterbbox[2],filterbbox[3]),(filterbbox[2],filterbbox[1]))) 
     91        featurepolygon=Polygon(((featurebbox[0],featurebbox[1]),(featurebbox[0],featurebbox[3]),(featurebbox[2],featurebbox[3]),(featurebbox[2],featurebbox[1])))         
     92        return filterpolygon.intersects(featurepolygon) 
     93     
     94    def getFeaturesByBBox(self,bboxtuple, srsname):           
    8995        log.debug('GET FEATURES BY BBOX') 
    90         #dummy return value 
    91         #TODO, process bounding boxes for each feature                     
    92         return [self.featureinstances['BLcqIIBG']] 
     96        result=[] 
     97        for featureid,feature in self.featureinstances.iteritems(): 
     98            try: 
     99                lowercorner=feature._feature.boundedBy.lowerCorner.CONTENT.split() 
     100                uppercorner=feature._feature.boundedBy.upperCorner.CONTENT.split() 
     101                featurebbox=(float(lowercorner[0]), float(lowercorner[1]), float(uppercorner[0]), float(uppercorner[1])) 
     102                if self._checkforOverlap(bboxtuple, featurebbox): 
     103                    result.append(feature) 
     104            except AttributeError: #sometimes the features don't have the bounding box metadata 
     105                pass 
     106        return result 
    93107 
    94108     
Note: See TracChangeset for help on using the changeset viewer.