| 1 | from web import Document, Template, dispatch | 1 | from web import Document, Template, dispatch |
|---|
| 2 | from bbox import BBox | 2 | from bbox import BBox |
|---|
| 3 | from warnings import warn | 3 | from 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 |
|---|
| 7 | from config import spatialdb | 7 | from config import spatialdb |
|---|
| 8 | | 8 | |
|---|
| 10 | bbox = BBox(spatial=spatialdb) | 10 | bbox = BBox(spatial=spatialdb) |
|---|
| 11 | | 11 | |
|---|
| 12 | class Request(Document): | 12 | class 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): |
|---|
| 24 | return bbox | 23 | return bbox |
|---|
| 25 | | 24 | |
|---|
| 26 | class GetFeature(Request): | 25 | class 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 = [] |
|---|
| 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) |
|---|
| 59 | | 61 | |
|---|
| 60 | | 62 | |
|---|
| 61 | class DescribeFeatureType(Request): | 63 | class DescribeFeatureType(Request): |
|---|
| 62 | def GET(self, action, input): | 64 | def GET(self, action, input): |
|---|
| 63 | pass | 65 | pass |
|---|
| 64 | | 66 | |
|---|
| 65 | class GetCapabilities(Document): | 67 | class 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 | |
|---|