Ignore:
Timestamp:
14/01/08 17:03:23 (13 years ago)
Author:
mkochan
Message:

[UNTESTED] Added multiple views of GridSeries? data -- added splitting into folders by month and year. Made this configurable in the CSML2KML config file.

File:
1 edited

Legend:

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

    r3204 r3214  
    3636    def writeKML(self): 
    3737        
    38         # Start with an empty KML document: 
    39         kmldocname='TEST GridSeries KML' 
    40         kml_document=Element('Document') 
    41         SubElement(kml_document, 'name').text=kmldocname 
    42         SubElement(kml_document, 'open').text='1' 
     38        # Start with an empty KML document 
     39        kmlDocName='TEST GridSeries KML' 
     40        kmlDocumentElement=Element('Document') 
     41        SubElement(kmlDocumentElement, 'name').text=kmlDocName 
     42        SubElement(kmlDocumentElement, 'open').text='1' 
    4343 
    4444        datasetName = os.path.split(self.csmlFilename)[1].split('.')[0] 
    4545 
    46         # Create a separate KML folder for each feature 
    47         for feature in self.ds.featureCollection.featureMembers: 
     46        # Create and populate a separate folder for each view 
     47        for view in self.config.getRoot().findall('View'): 
     48            splitByText = view.find('SplitBy').text 
     49            logicalYearTransformText = view.find('LogicalYearTransform').text 
     50            print 'Split by %s, using %s' % (splitByText, logicalYearTransformText) 
     51             
     52            # Create a separate KML folder for each feature 
     53            for feature in features: 
     54                 
     55                # GridSeriesFeatureWrapper allows extended querying of a GridSeriesFeature object 
     56                gsFeature=GridSeriesFeatureWrapper(feature)  
    4857 
    49             # GridSeriesFeatureWrapper allows extended querying of a GridSeriesFeature object 
    50             gsFeature=GridSeriesFeatureWrapper(feature)  
     58                description = feature.description.CONTENT      
     59                name = feature.name.CONTENT 
     60                bBox = gsFeature.getBBox() 
     61                timeSteps = gsFeature.getTimeSteps() 
     62                timeBounds = gsFeature.getTimeBounds() 
    5163 
    52             description = feature.description.CONTENT      
    53             name = feature.name.CONTENT 
    54             bBox = gsFeature.getBBox() 
    55             timeSteps = gsFeature.getTimeSteps() 
    56             timeBounds = gsFeature.getTimeBounds() 
     64                # Instantiate a GridSeriesKML object with this information 
     65                gsKML = kmlfeatures.GridSeriesKML( 
     66                    self.config, self.csmlFilename, name, description, bBox, timeSteps, timeBounds 
     67                    ) 
    5768 
    58             # Instantiate a GridSeriesKML object with this information 
    59             gsKML = kmlfeatures.GridSeriesKML(self.config, self.csmlFilename, name, description, bBox, timeSteps, timeBounds) 
     69                # Call the outputKML method of this object to generate a populated KML Folder element 
     70                kmlViewElement = gsKML.outputKML(view) 
    6071 
    61             # Call the outputKML method of this object to generate a populated KML Folder element 
    62             kml_folder = gsKML.outputKML(kmlfeatures.getDecadeSince1900) 
     72                # Append the folder to the kml document. 
     73                kmlDocumentElement.append(kmlViewElement) 
     74             
     75        # Attach the Document element as a subelement of the root 'kml' element 
     76        kmlRootElement=Element('kml', xmlns='http://earth.google.com/kml/2.2') 
     77        kmlRootElement.append(kmlDocumentElement) 
     78        self._indentXML(kmlRootElement, 0) 
    6379 
    64             # Append the folder to the kml document. 
    65             kml_document.append(kml_folder) 
    66  
    67         # Attach the Document element as a subelement of the root 'kml' element 
    68         kml_root=Element('kml', xmlns='http://earth.google.com/kml/2.2') 
    69         kml_root.append(kml_document) 
    70         self._indentXML(kml_root, 0) 
    71         tree = ElementTree(kml_root) 
    72          
     80        # Write the KML document to a file 
     81        tree = ElementTree(kmlRootElement)        
    7382        f = open(self.kmlFilename, 'w') 
    7483        tree.write(f) 
Note: See TracChangeset for help on using the changeset viewer.