Changeset 570

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

removed some debugging, comments

Files:

Legend:

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

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