Changeset 3214 for DPPP


Ignore:
Timestamp:
14/01/08 17:03:23 (12 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.

Location:
DPPP/kml/csml2kml
Files:
4 edited

Legend:

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

    r3204 r3214  
    66    def __init__(self, configFilename): 
    77        self.tree = ElementTree() 
    8         self.tree.parse(configFilename) 
    9         self.root = self.tree.getroot() 
     8        self.root = self.tree.parse(configFilename) 
    109 
    1110    # Get the text value/content for a setting at some xPath. xPath cannot contain 
     
    1413        str = self.root.findtext(xPath) 
    1514        return str 
     15 
     16    # Get root 
     17    def getRoot(self): 
     18        return self.root 
  • 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) 
  • DPPP/kml/csml2kml/python/kmlfeatures.py

    r3210 r3214  
    2929 
    3030        # The time steps  
    31         self.timeSteps=timeSteps 
     31        self.timeSteps=timeSteps.split() 
    3232 
    3333        # Valid bounds of the individual timesteps 
    34         self.timeBounds=timeBounds 
     34        self.timeBounds=timeBounds.split() 
     35     
     36    def _getYMD(self, timestep): 
     37        matchObject = re.match("(\d+)\-(\d+)\-(\d+)T", timestep) 
     38        (sYear, sMonth, sDay) = matchObject.groups() 
     39        return (sYear, sMonth, sDay) 
    3540 
    36      
    3741    def _getLogicalTimeSpan(self, timestep, logicalYearTransform): 
    3842        '''Translate timestep to a timespan that covers a full month in a year 
     
    8892        return wmsRequest 
    8993 
    90     def outputKML(self, logicalYearTransform): 
     94    def outputKML(self, viewConfig): 
    9195        ''' method to output KML as ElementTree instance - returns a 'Folder' element which can be put into a KML Document element ''' 
    9296         
    93         # Build XML document structure -- call _buildWMSRequest to get individual request strings. 
     97        # Analyze view configuration -- this determines how data will be presented 
     98        sbText = viewConfig.find('SplitBy').text 
     99        lytText = viewConfig.find('LogicalYearTransform').text 
     100 
     101        viewElement=Element('Folder') 
     102        SubElement(viewElement, 'name').text='View_' + sbText 
     103        SubElement(viewElement, 'open').text='0' 
     104        SubElement(viewElement, 'visibility').text='0' 
     105         
     106        if lytText == 'DECADES_SINCE_1900': 
     107            logicalYearTransform = getDecadeSince1900 
     108        else: 
     109            logicalYearTransform = getSameYear 
     110 
     111        def split_by(timeStep): 
     112            (sYear, sMonth, sDay) = self._getYMD(timestep) 
     113            if sbText == '': 
     114                return timeStep 
     115            elif sbText == 'years': 
     116                return sYear 
     117            elif sbText == 'months': 
     118                return sMonth 
     119 
     120        def g(acc, x): 
     121            category = split_by(x) 
     122            if not acc.has_key(category): 
     123                acc[category] = [] 
     124            acc[category].append(x) 
     125 
     126        dict = reduce(g, timeSteps) 
     127         
     128        for category in dict: 
     129             
     130            # Build XML document structure -- call _buildWMSRequest to get individual request strings. 
    94131       
    95         folderElement=Element('Folder') 
    96         SubElement(folderElement, 'name').text=str(self.description) 
    97         SubElement(folderElement, 'open').text='0' 
    98         SubElement(folderElement, 'visibility').text='0' 
     132            folderElement=Element('Folder') 
     133            SubElement(folderElement, 'name').text='Folder_' + category 
     134            SubElement(folderElement, 'open').text='0' 
     135            SubElement(folderElement, 'visibility').text='0' 
    99136         
    100         for timestep in self.timeSteps.split(): 
     137            for timestep in dict[category]: 
    101138 
    102             goElement=SubElement(folderElement, 'GroundOverlay')       
    103             SubElement(goElement, 'name').text=self.name + ' ' + timestep 
    104             SubElement(goElement, 'open').text='0' 
    105             SubElement(goElement, 'visibility').text='0' 
     139                goElement=SubElement(folderElement, 'GroundOverlay')       
     140                SubElement(goElement, 'name').text=self.name + ' ' + timestep 
     141                SubElement(goElement, 'open').text='0' 
     142                SubElement(goElement, 'visibility').text='0' 
    106143 
    107             timespanElement=SubElement(goElement, 'TimeSpan') 
    108             (startTime, endTime) = self._getLogicalTimeSpan(timestep, logicalYearTransform) 
    109             SubElement(timespanElement, 'begin').text=startTime 
    110             SubElement(timespanElement, 'end').text=endTime 
     144                timespanElement=SubElement(goElement, 'TimeSpan') 
     145                (startTime, endTime) = self._getLogicalTimeSpan(timestep, logicalYearTransform) 
     146                SubElement(timespanElement, 'begin').text=startTime 
     147                SubElement(timespanElement, 'end').text=endTime 
    111148 
    112             # Include the WMS service call address 
    113             iconElement=SubElement(goElement,'icon') 
    114             SubElement(iconElement, 'href').text=self._buildWMSRequest(timestep) 
    115             SubElement(iconElement, 'refreshMode').text='onExpire' 
     149                # Include the WMS service call address 
     150                iconElement=SubElement(goElement,'icon') 
     151                SubElement(iconElement, 'href').text=self._buildWMSRequest(timestep) 
     152                SubElement(iconElement, 'refreshMode').text='onExpire' 
    116153 
    117             latlonboxElement=SubElement(goElement, 'LatLonBox') 
    118             SubElement(latlonboxElement, 'north').text=str(self.bBox.north) 
    119             SubElement(latlonboxElement, 'south').text=str(self.bBox.south) 
    120             SubElement(latlonboxElement, 'east' ).text=str(self.bBox.east) 
    121             SubElement(latlonboxElement, 'west' ).text=str(self.bBox.west) 
     154                latlonboxElement=SubElement(goElement, 'LatLonBox') 
     155                SubElement(latlonboxElement, 'north').text=str(self.bBox.north) 
     156                SubElement(latlonboxElement, 'south').text=str(self.bBox.south) 
     157                SubElement(latlonboxElement, 'east' ).text=str(self.bBox.east) 
     158                SubElement(latlonboxElement, 'west' ).text=str(self.bBox.west) 
    122159         
    123         return folderElement 
     160            SubElement(viewElement, folderElement) 
     161 
     162        return viewElement 
    124163 
    125164# ---------- These are defined *outside* the class -- i.e. they are plain functions  
  • DPPP/kml/csml2kml/testdata/clim_10.csml2kml.conf.xml

    r3210 r3214  
    1 <CSMLGridSeriesFeatureWMSRequest> 
    2   <URL>http://www-devel.ipcc-data.org/maps/wms/obs</URL> 
    3   <ServiceVersion>1.1.1</ServiceVersion> 
    4   <ImageFormat>image/png</ImageFormat> 
    5   <ImageWidth>640</ImageWidth> 
    6   <ImageHeight>480</ImageHeight> 
    7   <CRS>EPSG:4326</CRS> 
    8   <LayerName>#FILENAME_EXCL_SUFFIX#/#FEATURE_NAME#</LayerName> 
    9   <LongitudeBounds>UNCONSTRAINED</LongitudeBounds> 
    10   <LatitudeBounds>UNCONSTRAINED</LatitudeBounds> 
    11 </CSMLGridSeriesFeatureWMSRequest> 
     1<CSML2KMLConfig> 
     2  <CSMLGridSeriesFeatureWMSRequest> 
     3    <URL>http://www-devel.ipcc-data.org/maps/wms/obs</URL> 
     4    <ServiceVersion>1.1.1</ServiceVersion> 
     5    <ImageFormat>image/png</ImageFormat> 
     6    <ImageWidth>640</ImageWidth> 
     7    <ImageHeight>480</ImageHeight> 
     8    <CRS>EPSG:4326</CRS> 
     9    <LayerName>#FILENAME_EXCL_SUFFIX#/#FEATURE_NAME#</LayerName> 
     10    <LongitudeBounds>UNCONSTRAINED</LongitudeBounds> 
     11    <LatitudeBounds>UNCONSTRAINED</LatitudeBounds> 
     12  </CSMLGridSeriesFeatureWMSRequest> 
     13  <View name="By feature, whole century"> 
     14    <SplitTimePointsBy></SplitTimePointsBy> 
     15    <LogicalYearTransform>DECADES_SINCE_1900</LogicalYearTransform> 
     16  </View> 
     17  <View name="By feature and decade"> 
     18    <SplitTimePointsBy>year</SplitBy> 
     19    <LogicalYearTransform>IDENTICAL</LogicalYearTransform> 
     20  </View> 
     21  <View name="By feature and month"> 
     22    <SplitBy>month</SplitBy> 
     23    <LogicalYearTransform>IDENTICAL</LogicalYearTransform> 
     24  </View> 
     25</CSML2KMLConfig> 
Note: See TracChangeset for help on using the changeset viewer.