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