source: cows/trunk/cows/pylons/wfs_controller.py @ 4274

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/pylons/wfs_controller.py@4274
Revision 4274, 4.6 KB checked in by domlowe, 13 years ago (diff)

Adding initial WFS code. Plus further separation of CSML code and service specific code.

Line 
1"""
2WFS controller for OGC Web Services (OWS).
3
4@author: Dominic Lowe
5"""
6
7import re
8from cStringIO import StringIO
9from sets import Set
10from matplotlib.cm import get_cmap
11from pylons import request, response, c
12
13import logging
14log = logging.getLogger(__name__)
15
16import Image
17
18from cows.model.wfs import WfsFeatureSummary
19from cows.model import PossibleValues, WGS84BoundingBox, BoundingBox, Contents
20from cows.pylons import ows_controller
21from cows.exceptions import *
22from cows import bbox_util
23
24class WFSController(ows_controller.OWSController):
25    """
26    Subclass this controller in a pylons application and set the layerMapper
27    class attribute to implement a WFS. Each layer can be mapped to a Feature for the WFS.
28
29    @cvar layerMapper: an cows.service.wxs_iface.ILayerMapper object.
30   
31
32    """
33    layerMapper = None
34    #layers = {}   
35    _pilImageFormats = {
36        'image/png': 'PNG',
37        'image/jpg': 'JPEG',
38        'image/gif': 'GIF',
39        'image/tiff': 'TIFF'
40        }
41    _layerSlabCache = {}
42
43    #-------------------------------------------------------------------------
44    # Attributes required by OWSController
45
46    service = 'WFS'
47    owsOperations = (ows_controller.OWSController.owsOperations + ['DescribeFeatureType', 'GetFeature'])
48    validVersions = ['1.1.0']
49
50    #-------------------------------------------------------------------------
51
52    def __before__(self, **kwargs):
53        """
54        This default implementation of __before__() will pass all routes
55        arguments to the layer mapper to retrieve a list of layers for
56        this WFS.
57
58        It will be called automatically by pylons before each action method.
59
60
61        """
62        #self.updateSequence = "hello"
63        print "loading layers"
64        #print self.layers
65        self.layers = self.layerMapper.map(**kwargs)
66   
67        #-------------------------------------------------------------------------
68        # Methods implementing stubs in OWSController
69
70    def _renderCapabilities(self, version, format):
71        """
72        Renders capabilities document.
73        """
74        if version == '1.1.0':
75            t = ows_controller.templateLoader.load('wfs_capabilities_1_1_0.xml')
76        else:
77            # We should never get here!  The framework should raise an exception before now.
78            raise RuntimeError("Version %s not supported" % version)
79       
80        return t.generate(c=c).render()
81
82    def _loadCapabilities(self):
83        """
84        @note: Assumes self.layers has already been created by __before__().
85        Builds capabilities document.
86
87        """
88        log.info('Loading WFS Capabilites')
89       
90        ows_controller.addOperation('GetFeature')
91        ows_controller.addOperation('DescribeFeature')
92       
93       
94        featureInfoFormats = Set()
95
96        log.debug('Loading capabilities contents')
97        c.capabilities.contents = Contents()
98       
99       
100        ftlist={}
101       
102        #create dictionary of form {featuretype: [layer, layer, ...], {featuretype2: [layer, layer, ...]}
103        for layerName, layer in self.layers.items():
104            log.info(dir(layer))
105            if type(layer._feature) not in ftlist:
106                ftlist[type(layer._feature)] = [layer]
107            else:
108                ftlist[type(layer._feature)].append(layer)
109        log.info('FeatureTypeList: %s'%ftlist)
110       
111       
112        for layerName, layer in self.layers.items():
113            log.info('Loading layer %s' % layerName)
114            log.info('feature type %s'%layer._feature)
115
116            wgs84BBox = WGS84BoundingBox(layer.wgs84BBox[:2],
117                                         layer.wgs84BBox[2:])
118           
119            ds = WfsFeatureSummary(identifier=layerName,
120                                   titles=[layer.title],
121                                   abstracts=[layer.abstract],                                   
122                                   wgs84BoundingBoxes=[wgs84BBox])
123
124            c.capabilities.contents.datasetSummaries.append(ds)
125           
126    def DescribeFeatureType(self):
127        """ DescribeFeatureType """
128        pass           
129 
130    def GetFeature(self):
131        """ GetFeature request
132        """
133        version = self.getOwsParam('version', default=self.validVersions[0])
134        if version not in self.validVersions:
135            raise InvalidParameterValue('Version %s not supported' % version,
136                                        'version')
137        featureid=self.getOwsParam('featureid',default=None)
138        if featureid is not None:
139            msg = 'feature %s'%featureid
140        else:
141            msg = 'No feature specified'         
142        return msg
143   
144   
Note: See TracBrowser for help on using the repository browser.