source: cows/branches/cows-vis/cowsclient/cowsclient/model/WMC.py @ 5265

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/branches/cows-vis/cowsclient/cowsclient/model/WMC.py@5265
Revision 5265, 2.3 KB checked in by domlowe, 11 years ago (diff)

adding separate cowsclient pylons app

Line 
1# python class to support methods on a WMC ... to conform with
2# renderEntity etc ...
3#
4from cowsclient.lib.utilities import *
5#from geoUtilities import *
6#from ndgUtils.ETxmlView import loadET, nsdumb
7#from ndgUtils.DocumentRetrieve import genericHTTP
8import urllib
9
10   
11class WMC:
12    ''' Simple representation of a WMC document  '''
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/')  #TODO, store this in config
20        x=genericHTTP()
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.