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

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

Remove rogue print and import statements.

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