Changeset 3459 for DPPP


Ignore:
Timestamp:
19/02/08 15:44:03 (11 years ago)
Author:
mkochan
Message:

Changed GridSeriesConvertor? and kmlfeatures to use KML.

Location:
DPPP/kml/csml2kml/python
Files:
5 edited

Legend:

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

    r3451 r3459  
    33 
    44import csml.parser 
     5from KML import * 
    56import kmlfeatures 
    67from csmlwrappers import GridSeriesFeatureWrapper 
     8 
    79 
    810class GridSeriesConvertor: 
     
    3234         
    3335        for viewConfig in self.config.findall('View'): 
    34             kmlViewFolder = KMLFolder() 
     36 
     37            kmlViewFolder = KMLFolder(viewConfig.get('name'), [], opened = False, visible = False) 
     38 
    3539            features = self.ds.featureCollection.featureMembers 
    3640            for feature in features: 
     
    3842                # GridSeriesFeatureWrapper allows extended querying of a GridSeriesFeature object 
    3943                gsFeature = GridSeriesFeatureWrapper(feature) 
    40                 description = feature.description.CONTENT    
     44                description = feature.description.CONTENT 
    4145                name = feature.name.CONTENT 
    4246                bBox = gsFeature.getBBox() 
     
    5155 
    5256                # Generate a populated KML folder containing the feature, append it to the view 
    53                 kmlFeatureFolder = gsKML.exportFeature(viewConfig) 
     57                kmlFeatureFolder = gsKML.toKML(viewConfig) 
    5458                kmlViewFolder.children.append(kmlFeatureFolder) 
    5559             
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/KML.py

    r3451 r3459  
    3232        documentElement = Element('Document') 
    3333        SubElement(documentElement, 'name').text = self.name 
    34         SubElement(documentElement, 'open').text = '0' 
     34        SubElement(documentElement, 'open').text = '1' 
    3535 
    3636        # Build the associated styles 
     
    132132    ''' 
    133133     
    134     def __init__(self, id, name, lon, lat, featuresHtml, styleID = None, data=None): 
     134    def __init__(self, id, name, lon, lat, featuresHtml, styleID = None, data=None, visible = True): 
    135135        self.id = id 
    136136        self.name = name 
     
    140140        self.styleID = styleID 
    141141        self.data = data 
     142        self.visible = visible 
    142143 
    143144    def build(self): 
    144145        placemarkElement = Element('Placemark') 
    145146        SubElement(placemarkElement, 'name').text = self.name 
    146         SubElement(placemarkElement, 'open').text = '0' 
     147 
     148        if self.visible: 
     149            SubElement(placemarkElement, 'visibility').text = '1' 
     150        else: 
     151            SubElement(placemarkElement, 'visibility').text = '0' 
     152 
    147153        if self.styleID: 
    148154            SubElement(placemarkElement, 'styleUrl').text = '#' + self.styleID 
     
    178184    ''' 
    179185 
    180     def __init__(self, name, children, styleID = None, region = None): 
     186    def __init__(self, name, children, styleID = None, region = None, opened = True, visible = True): 
    181187        self.name = name 
    182188        self.children = children 
    183189        self.styleID = styleID 
    184190        self.region = region 
     191        self.opened = opened 
     192        self.visible = visible 
    185193 
    186194    def build(self): 
     
    189197            SubElement(folderElement, 'styleUrl').text = '#' + self.styleID 
    190198        SubElement(folderElement, 'name').text = self.name 
     199        if self.visible: 
     200            SubElement(folderElement, 'visibility').text = '1' 
     201        else: 
     202            SubElement(folderElement, 'visibility').text = '0' 
     203        if self.opened: 
     204            SubElement(folderElement, 'open').text = '1' 
     205        else: 
     206            SubElement(folderElement, 'open').text = '0' 
    191207        if self.region: 
    192208            if not isinstance(self.region, KMLRegion): 
     
    213229 
    214230    def build(self): 
    215  
    216231        llabElement = Element('LatLonAltBox') 
    217232        SubElement(llabElement, 'west').text = str(self.west) 
     
    232247    '''Represents the <kml:GroundOverlay> tag.''' 
    233248 
    234     def __init__(self, name, sourceUrl, timespanStart, timespanEnd, west, south, east, north): 
    235         self.name = name 
     249    def __init__(self, name, sourceUrl, timespanStart, timespanEnd, west, south, east, north, visible = True): 
     250        self.name = name 
     251        self.sourceUrl = sourceUrl 
    236252        self.timespanStart = timespanStart 
    237253        self.timespanEnd = timespanEnd 
    238         self.sourceUrl = sourceUrl 
    239254        self.west = west 
    240255        self.south = south 
    241256        self.east = east 
    242257        self.north = north 
     258        self.visible = visible 
    243259 
    244260    def build(self): 
     
    247263 
    248264        SubElement(groundOverlayElement, 'name').text = self.name 
    249         SubElement(groundOverlayElement, 'open').text = '0' 
    250         SubElement(groundOverlayElement, 'visibility').text = '0' 
     265 
     266        if self.visible: 
     267            SubElement(groundOverlayElement, 'visibility').text = '1' 
     268        else: 
     269            SubElement(groundOverlayElement, 'visibility').text = '0' 
    251270 
    252271        timespanElement = SubElement(groundOverlayElement, 'TimeSpan') 
    253         SubElement(timespanElement, 'begin').text = ('%04d-%02d-%02d') % timespanStart.utctimetuple()[0:3] 
    254         SubElement(timespanElement, 'end').text = ('%04d-%02d-%02d') % timespanEnd.utctimetuple()[0:3] 
     272        SubElement(timespanElement, 'begin').text = ('%04d-%02d-%02d') % self.timespanStart.utctimetuple()[0:3] 
     273        SubElement(timespanElement, 'end').text = ('%04d-%02d-%02d') % self.timespanEnd.utctimetuple()[0:3] 
    255274 
    256275        # Include the WMS service call address 
    257276        iconElement = SubElement(groundOverlayElement, 'icon') 
    258         SubElement(iconElement, 'href').text = sourceUrl 
     277        SubElement(iconElement, 'href').text = self.sourceUrl 
    259278        SubElement(iconElement, 'refreshMode').text = 'onExpire' 
    260279 
     
    266285 
    267286        return groundOverlayElement 
    268          
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/kmlfeatures.py

    r3451 r3459  
    99from datetime import datetime 
    1010from cElementTree import ElementTree, Element, SubElement 
     11 
     12from KML import * 
    1113 
    1214class GridSeriesKML(object): 
     
    126128        ''' 
    127129        if self.description: 
    128             kmlFeatureFolder = KMLFolder(self.description, []) 
    129         else: 
    130             kmlFeatureFolder = KMLFolder(self.name, []) 
    131          
    132         kmlFeatureFolder.opened = kmlFeatureFolder.visible = False 
    133          
     130            kmlFeatureFolder = KMLFolder(self.description, [], visible = False, opened = False)             
     131        else: 
     132            kmlFeatureFolder = KMLFolder(self.name, [], visible = False, opened = False)             
     133 
    134134        if self.splitTimeStepsBy == None: 
    135135 
     
    140140        else: 
    141141             
    142             def getCategory(timeStep): 
     142            def _getCategory(timeStep): 
    143143                (year, month, day) = self.getYMD(timeStep) 
    144144                if self.splitTimeStepsBy == None: 
     
    152152 
    153153            for timeStep in self.timeSteps: 
    154                 category = getCategory(timeStep) 
     154                category = _getCategory(timeStep) 
    155155                if not dict.has_key(category): 
    156156                    dict[category] = [] 
     
    168168                        categoryName = categoryName.replace('#MONTH#', getMonthCommonName(category)) 
    169169                 
    170                 kmlCategoryFolder = KMLFolder(categoryName, []) 
    171                 kmlCategoryFolder.opened = kmlCategoryFolder.visible = False 
     170                kmlCategoryFolder = KMLFolder(categoryName, [], visible = False, opened = False) 
    172171                for timeStep in dict[category]: 
    173                     kmlGroundOverlay = self.buildGroundOverlayElement(timeStep) 
     172                    kmlGroundOverlay = self.buildKmlGroundOverlay(timeStep) 
    174173                    kmlCategoryFolder.children.append(kmlGroundOverlay) 
    175174                kmlFeatureFolder.children.append(kmlCategoryFolder) 
     
    235234        return featureElement 
    236235 
     236    def buildKmlGroundOverlay(self, timeStep): 
     237        ''' [VISIBILITY?]''' 
     238 
     239        (startDateTime, endDateTime) = self.getLogicalTimeSpan(timeStep) 
     240 
     241        return KMLGroundOverlay( 
     242            self.name + ' ' + timeStep, 
     243            self.buildWMSRequest(timeStep), 
     244            startDateTime, 
     245            endDateTime, 
     246            self.bBox.west, self.bBox.south, self.bBox.east, self.bBox.north, 
     247            visible = False 
     248            ) 
     249 
    237250    def buildGroundOverlayElement(self, timeStep): 
    238251 
     
    244257        timespanElement=SubElement(goElement, 'TimeSpan') 
    245258        (startDateTime, endDateTime) = self.getLogicalTimeSpan(timeStep) 
    246         SubElement(timespanElement, 'begin').text = ('%04d-%02d-%02d') % startDateTime.utctimetuple()[0:3] 
    247         SubElement(timespanElement, 'end').text = ('%04d-%02d-%02d') % endDateTime.utctimetuple()[0:3] 
     259        SubElement(timespanElement, 'begin').text = ('%04d-%02d-%02d') % (startDateTime.utctimetuple()[0:3]) 
     260        SubElement(timespanElement, 'end').text = ('%04d-%02d-%02d') % (endDateTime.utctimetuple()[0:3]) 
    248261 
    249262        # Include the WMS service call address 
     
    301314    ''' 
    302315    There is no need for this class. This is because there is no way of showing a csml:PointSeriesFeature 
    303     in Google Earth. Instead, it's graph gets loaded from a dynamic web link. The graphing/rendering service 
     316    in Google Earth. Instead, its graph gets loaded from a dynamic web link. The graphing/rendering service 
    304317    is supposed to be independent and not contained in this egg. 
    305318    ''' 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/tests/testGridSeriesConvertor.py

    r3439 r3459  
    11from GridSeriesConvertor import GridSeriesConvertor 
    22 
    3 c = GridSeriesConvertor('../../../testdata/clim_10.csml', '../../../testdata/clim_10.csml2kml.conf.xml', '../../../output/clim_10.kml') 
    4 c.writeKML() 
     3c = GridSeriesConvertor('../../../../testdata/clim_10.csml', '../../../../testdata/clim_10.csml2kml.conf.xml', '../../../../output/clim_10.2.kml') 
     4c.convert() 
  • DPPP/kml/csml2kml/python/notes.txt

    r3451 r3459  
    2323|| * ___/ 
    2424     
     25[o] Make the "tests" contain 3 dirs: python, testdata, and testoutputs; for that reason probably move "tests" 
     26    from the CSML2KML egg and create a separate, testing, egg.  
     27[o] Put into ~/eggs a dynamic link to the CSML2KML, and the path from $PYTHONPATH -- this is a more "always-ready" approach. 
    2528[+] Assertion and type checking in Python 
    2629[o] Resolve slow functioning of wget() 
Note: See TracChangeset for help on using the changeset viewer.