source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/WMC.py @ 3747

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/WMC.py@3747
Revision 3747, 2.3 KB checked in by cbyrom, 13 years ago (diff)

Fix Con Terra integration of web client:
Added new template, conterra_xmlconfig.kid to do the creation of
the xmlConfig data to POST.
Changed conterra_aggregate to contain a form which automatically
POSTs a request with the xmlConfig data, when the template is rendered.
Extended selectedItems to include conterra_aggegrage.kid - so that
the selections page is redrawn following a POST to the conterra client.
Also updated the wms_util and WMC python scripts to extract the
required data for the new Con Terra input formats.

Line 
1# python class to support methods on a WMC ... to conform with
2# renderEntity etc ...
3#
4from Utilities import *
5from geoUtilities import *
6from ndgUtils.ETxmlView import loadET, nsdumb
7from ndgUtils import ndgObject
8from ndgUtils.DocumentRetrieve import genericHTTP
9import urllib
10
11   
12class WMC:
13    ''' Simple representation of a WMC document - for use with the Con Terra interface templates '''
14    def __init__(self,url):
15       
16        self.url = url
17        self.layers = []
18
19        '''Initialise a python wmc, retrieving it from the specified URL '''
20        x=genericHTTP(proxyServer='http://wwwcache3.rl.ac.uk:8080/')
21        try:
22            wmcDoc = x.get(url)
23        except Exception, e:
24            self.title = "Document could not be retrieved properly"
25            return
26       
27        self.tree = loadET(wmcDoc) 
28       
29        # now try and interpret it
30        helper=nsdumb(self.tree)
31        self.title=helper.getText(self.tree,'General/Title')
32
33        #load up information about spatial bounding box
34        #self.bbox=Bounding(self.tree,helper,entity='WMC')
35       
36        layersTree = helper.find(self.tree, 'LayerList')
37        if layersTree:
38            # add each of the layer elements
39            layerElements = layersTree.getchildren()
40            for layer in layerElements:
41                self.layers.append(WMCLayer(layer)) 
42           
43    def getAllLayers():
44        layersData = []
45        for child in self.layers:
46            layersData.append(ET.tostring(child))
47        return ''.join(layersData)
48
49
50class WMCLayer:
51    ''' Simple representation of a WMC layer '''
52    def __init__(self, layerXML):
53       
54        self.xml = layerXML
55       
56        # Now extract the basic layer info - for easy retrieval in kid template
57        helper=nsdumb(self.xml)
58        self.name = helper.getText(self.xml, 'Name')
59        # NB, there may be a better way of getting the href, but the nsdumb doesn't currently
60        # support XPATH attribute functionality
61        elem = helper.find(self.xml, 'Server/OnlineResource')
62        for attribute in elem.attrib:
63            if attribute.find('href') > -1:
64                self.wmsURL = elem.attrib.get(attribute)
65           
66
67
68import unittest
69
70class TestCase(unittest.TestCase):
71    """
72    """
73
74
75if __name__=="__main__":
76    unittest.main()
77
78       
79       
Note: See TracBrowser for help on using the repository browser.