/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/wms/parser.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Extensions/wms/parser.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2144 by joey, Tue Mar 30 17:25:20 2004 UTC revision 2164 by joey, Tue Apr 13 13:15:22 2004 UTC
# Line 89  class WMSCapabilitiesParser: Line 89  class WMSCapabilitiesParser:
89          Information should only be retrieved with the respective          Information should only be retrieved with the respective
90          get*() methods.          get*() methods.
91          """          """
92          root = xml.dom.minidom.parseString(data).documentElement          xml_dom = xml.dom.minidom.parseString(data)
93            root = xml_dom.documentElement
94    
95          # Extract the title          # Extract the title
96          foo = getElementByName(getElementByName(root, 'Service'), 'Title')          foo = getElementByName(getElementByName(root, 'Service'), 'Title')
# Line 104  class WMSCapabilitiesParser: Line 105  class WMSCapabilitiesParser:
105          # Extract fees information          # Extract fees information
106          foo = getElementByName(getElementByName(root, 'Service'), 'Fees')          foo = getElementByName(getElementByName(root, 'Service'), 'Fees')
107          if foo and len(foo.childNodes[0].data) \          if foo and len(foo.childNodes[0].data) \
108                 and lower(foo.childNodes[0].data) != 'none':                 and foo.childNodes[0].data.lower() != 'none':
109              self.fees = foo.childNodes[0].data              self.fees = foo.childNodes[0].data
110                    
111          # Extract access information          # Extract access information
112          foo = getElementByName(getElementByName(root, 'Service'),          foo = getElementByName(getElementByName(root, 'Service'),
113                                 'AccessConstraints')                                 'AccessConstraints')
114          if foo and len(foo.childNodes[0].data) \          if foo and len(foo.childNodes[0].data) \
115                 and lower(foo.childNodes[0].data) != 'none':                 and foo.childNodes[0].data.lower() != 'none':
116              self.access = foo.childNodes[0].data              self.access = foo.childNodes[0].data
117                    
118          # Extract output format information          # Extract output format information
# Line 125  class WMSCapabilitiesParser: Line 126  class WMSCapabilitiesParser:
126          self.peekLayers(getElementByName(getElementByName(          self.peekLayers(getElementByName(getElementByName(
127              root, 'Capability'), 'Layer'), -1)              root, 'Capability'), 'Layer'), -1)
128    
129            xml_dom.unlink()
130    
131    
132      def peekLayers(self, top, parent):      def peekLayers(self, top, parent):
133          """          """
# Line 183  class WMSCapabilitiesParser: Line 186  class WMSCapabilitiesParser:
186                  self.layers[index]['bbox'][srs][corner] \                  self.layers[index]['bbox'][srs][corner] \
187                      = foo.attributes.get(corner).nodeValue                      = foo.attributes.get(corner).nodeValue
188                            
         # Check for integrity  
         self.checkLayerSRS(index)  
   
189          # Traverse subsidiary layers          # Traverse subsidiary layers
190          sublayer = getElementsByName(top, 'Layer')          sublayer = getElementsByName(top, 'Layer')
191          for l in sublayer:          for l in sublayer:
192              self.peekLayers(l, index)              self.peekLayers(l, index)
193    
194    
     def checkLayerSRS(self, index):  
         """  
         Checks the integrity of the underlying XML data.  
   
         This is done by comparing the <SRS> elements with the  
         calculated list from the BoundingBox elements.  
   
         index -- position in the layers array to check  
         """  
   
         pivot = index  
         calculated = []  
         while pivot != -1:  
             if 'bbox' in self.layers[pivot]:  
                 for srs in self.layers[pivot]['bbox'].keys():  
                     if srs not in calculated:  
                         calculated.append(srs)  
             pivot = self.layers[pivot]['parent']  
   
         pivot = index  
         specified = []  
         while pivot != -1:  
             if 'srs' in self.layers[pivot]:  
                 for srs in self.layers[pivot]['srs']:  
                     if srs not in specified:  
                         specified.append(srs)  
             pivot = self.layers[pivot]['parent']  
   
         equal = True  
         # Check for same number of elements  
         if len(calculated) != len(specified):  
             equal = False  
   
         # Loop through all elements for existance  
         for elm in calculated:  
             if elm not in specified:  
                 equal = False  
   
         if not equal:  
             if self.srs_discrepancies is None:  
                 self.srs_discrepancies = []  
             if 'name' in self.layers[index]:  
                 id = "name:%s" % self.layers[index]['name']  
             else:  
                 id = "title:%s" % self.layers[index]['title']  
             self.srs_discrepancies.append(id)  
   
   
195      def getTitle(self):      def getTitle(self):
196          """          """
197          Returns the main title of the WMS object.          Returns the main title of the WMS object.
# Line 530  if __name__ == "__main__": Line 482  if __name__ == "__main__":
482    
483      import os      import os
484    
485        sample = "test/sample.xml"
486      try:      try:
487          f = open("test/sample.xml", "r")          f = open(sample, "r")
488      except IOError:      except IOError:
489          try:          try:
490              f = open(os.path.dirname(__file__) + "/test/sample.xml", "r")              f = open(os.path.dirname(__file__) + "/" + sample, "r")
491          except IOError:          except IOError:
492              print "Cannot open sample.xml for reading"              print "Cannot open %s for reading" % sample
493    
494      if f is not None:      if f is not None:
495          sample = f.read();          sample = f.read();

Legend:
Removed from v.2144  
changed lines
  Added in v.2164

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26