Changeset 558

Show
Ignore:
Timestamp:
11/07/06 18:08:29 (2 years ago)
Author:
zool
Message:

incomplete

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bbox/bbox/wfssimple.py

    Revision 539 Revision 558
    1from web import Document, Template, dispatch 1from web import Document, Template, dispatch 
    2from bbox import BBox 2from bbox import BBox 
    3from warnings import warn 3from warnings import warn 
    4# configuration? 4# configuration? 
    5# Why not do a RESTfully addressable version of this? 5# Why not do a RESTfully addressable version of this? 
    6# Then it loses a lot of WFS-ness 6# Then it loses a lot of WFS-ness 
    7from config import spatialdb  7from config import spatialdb  
    8 8 
    9formats = { 'text/xml': 'gml', 'application/rdf+xml': 'rdf', 'application/json':'json'9formats = { 'text/xml': 'gml', 'application/rdf+xml': 'rdf', 'application/json':'json', 'application/atom+xml':'atom'
    10bbox = BBox(spatial=spatialdb) 10bbox = BBox(spatial=spatialdb) 
    11 11 
    12class Request(Document): 12class Request(Document): 
    13    # we should pass in a bbox object here, huh 13    # we should pass in a bbox object here, huh 
    14    def outputformat(self): 14    def outputformat(self): 
    15        query = self.input 15        query = self.input 
    16        if query.has_key('OUTPUTFORMAT'): 16        if query.has_key('OUTPUTFORMAT'): 
    17            self.format = query['OUTPUTFORMAT'].value 17            self.format = query['OUTPUTFORMAT'].value 
    18        else: 18        else: 
    19            self.format = 'text/xml' 19            self.format = 'text/xml' 
    20        return formats[self.format] 20        return formats[self.format] 
    21 21 
    22    def bbox(self): 22    def bbox(self): 
    23        warn(str(bbox))   
    24        return bbox 23        return bbox 
    25 24 
    26class GetFeature(Request): 25class GetFeature(Request): 
    27 26 
    28    def GET(self,*args): 27    def GET(self,*args): 
    29        """Retrieve features from the DB. By default, returns everything, 28        """Retrieve features from the DB. By default, returns everything, 
    30        possibly limited in number by MAXFEATURES (what about paging?)   29        possibly limited in number by MAXFEATURES (what about paging?)   
    31        Results can be limited by BBOX and MINDATE and or MAXDATE 30        Results can be limited by BBOX and MINDATE and or MAXDATE 
    32        and one can specify an alternative (but not optional?) OUTPUTFORMAT""" 31        and one can specify an alternative (but not optional?) OUTPUTFORMAT""" 
    33         32         
    34        query = self.input 33        query = self.input 
    35        features = [] 34        features = [] 
      35        envelope = None 
    36 36 
    37        box = mindate = maxdate = None 37        box = mindate = maxdate = None 
    38        if query.has_key('BBOX'): box = query['BBOX'].value 38        if query.has_key('BBOX'): box = query['BBOX'].value 
    39        if query.has_key('MINDATE'): mindate = query['MINDATE'].value 39        if query.has_key('MINDATE'): mindate = query['MINDATE'].value 
    40        if query.has_key('MAXDATE'): maxdate = query['MAXDATE'].value    40        if query.has_key('MAXDATE'): maxdate = query['MAXDATE'].value    
    41 41 
    42        if box is not None: 42        if box is not None: 
    43            # a simple form where there are 2 coordinates ( within_box() ) 43            # a simple form where there are 2 coordinates ( within_box() ) 
    44            # a complex form where there are N points and an "optional crsuri" 44            # a complex form where there are N points and an "optional crsuri" 
    45            # with no indication of how it's specified ( within_shape ) 45            # with no indication of how it's specified ( within_shape ) 
    46            # plus, we may get an optional date start/end/range here. 46            # plus, we may get an optional date start/end/range here. 
    47 47 
    48            points = box.split(',') 48            points = box.split(',') 
    49            if len(points) is 4:  49            if len(points) is 4:  
    50                features = self.bbox().spatialStore.within_box(minx=points[0],miny=points[1],maxx=points[2],maxy=points[3],mindate=mindate,maxdate=maxdate)     50                features = self.bbox().spatialStore.within_box(minx=points[0],miny=points[1],maxx=points[2],maxy=points[3],mindate=mindate,maxdate=maxdate)     
    51            else: 51            else: 
    52                features = self.bbox().spatialStore.within_shape(points,mindate=mindate,maxdate=maxdate) 52                features = self.bbox().spatialStore.within_shape(points,mindate=mindate,maxdate=maxdate) 
    53           
    54        elif mindate is not None or maxdate is not None: 53        elif mindate is not None or maxdate is not None: 
    55            features = self.bbox.spatialStore.within_date(mindate=mindate,maxdate=maxdate)  54      
    56                      55             features = self.bbox().spatialStore.within_date(mindate=mindate,maxdate=maxdate) 
       56         if len(features) > 0: 
       57             envelope = self.bbox().spatialStore.envelope(features) 
       58  
    57        format = self.outputformat() 59        format = self.outputformat() 
    58        return self.output('feature.'+format,features = features)      60        return self.output('feature.'+format,features = features,envelope=envelope)    
    59 61 
    60 62 
    61class DescribeFeatureType(Request): 63class DescribeFeatureType(Request): 
    62    def GET(self, action, input): 64    def GET(self, action, input): 
    63        pass 65        pass 
    64 66 
    65class GetCapabilities(Document): 67class GetCapabilities(Document): 
    66    def GET(self,id): 68    def GET(self,id): 
    67        return self.output('capabilities.xml') 69        return self.output('capabilities.xml') 
    68 70 
    69          71  
       72 class WFSSimple(Request): 
       73     def GET(self,*args): 
       74         response = '' 
       75         if self.input.has_key('REQUEST'): 
       76             request = self.input['REQUEST'].value 
       77             module = None 
       78             warn(request) 
       79             # i forget the smart syntax for doing this. i did try. 
       80             if request is 'GetFeature': module = bbox.wfssimple.GetFeature() 
       81             if request is 'GetCapabilities': module = GetCapabilities() 
       82             if request is 'DescribeFeatureType': module = DescribeFeatureType(input=self.input) 
       83             response = module.GET() 
       84         return response