Ignore:
Timestamp:
11/02/08 10:29:34 (12 years ago)
Author:
mkochan
Message:

Made StationConvertor? class use the Station.py module.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/csml2kml/KMLDocument.py

    r3302 r3362  
    11from cElementTree import ElementTree, Element, SubElement, XML 
    22 
     3class KMLElement: 
     4    ''' 
     5    Abstract class, representing any element of a KML document -- i.e. anything contained *within* 
     6    the <kml:Document> element. 
     7    ''' 
     8 
     9    def build(self): 
     10        ''' 
     11        It is required that each KMLElement instance is able to build() itself into an ElementTree.Element 
     12        instance of KML, which it represents. 
     13        ''' 
     14        raise NotImplementedError("Abstract method, to be overriden by child classes") 
     15 
    316class KMLDocument: 
    417    ''' 
    518    Wraps around a whole KML document and makes it possible to save it to a file directly. 
    6     Does *not* represent merely the <kml:Document> tag, but also the wrapping <kml:kml> tag. 
     19    Represent the <kml:Document>, so that the method build() builds the kml:Document element, 
     20    but also contains the method save() that allows saving that to a file, wrapped within the <kml> header. 
    721    ''' 
    822 
     
    1327        self.elements = [] 
    1428 
     29    def build(self): 
     30 
     31        # Create the <Document> an element to hold the document 
     32        documentElement = Element('Document') 
     33        SubElement(documentElement, 'name').text = self.name 
     34        SubElement(documentElement, 'open').text = '0' 
     35 
     36        # Build the associated styles 
     37        for style in self.styles: 
     38            documentElement.append( style.build() ) 
     39 
     40        # Build the sub-elements 
     41        for element in self.elements: 
     42            documentElement.append( element.build() ) 
     43         
     44        return documentElement 
     45         
    1546    def save(self, outputFilename): 
    1647        ''' 
     
    3465                    elem.tail = i 
    3566 
    36         # Create an element to hold the document 
    37         self.documentElement = Element('Document') 
    38         SubElement(self.documentElement, 'name').text = self.name 
    39         SubElement(self.documentElement, 'open').text = '0' 
    40  
    41         # Build the associated styles 
    42         for style in self.styles: 
    43             self.documentElement.append( style.build() ) 
    44  
    45         # Build the sub-elements 
    46         for element in self.elements: 
    47             self.documentElement.append( element.build() ) 
     67        # Build the Document element 
     68        documentElement = self.build() 
    4869 
    4970        # Attach the Document element as a subelement of a root 'kml' element 
    5071        rootElement=Element('kml', xmlns='http://earth.google.com/kml/2.2') 
    51         rootElement.append(self.documentElement) 
     72        rootElement.append(documentElement) 
    5273        _indentXML(rootElement) 
    5374 
     
    5778        elementTree.write(kmlFile) 
    5879        kmlFile.close() 
    59  
    60 class KMLElement: 
    61     ''' 
    62     Abstract class, representing any element of a KML document -- i.e. anything contained *within* 
    63     the <kml:Document> element. 
    64     ''' 
    65  
    66     def build(self): 
    67         ''' 
    68         It is required that each KMLElement instance is able to build() itself into an ElementTree.Element 
    69         instance of KML, which it represents. 
    70         ''' 
    71         raise NotImplementedError("Abstract method, to be overriden by child classes") 
    7280 
    7381class KMLStyle(KMLElement): 
Note: See TracChangeset for help on using the changeset viewer.