Changeset 3508 for DPPP


Ignore:
Timestamp:
25/02/08 11:34:43 (11 years ago)
Author:
mkochan
Message:

testWMSCapabilities.py runs successfully, but produces unsatisfactory output.

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

Legend:

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

    r3506 r3508  
     1import os 
    12from pylab import dates     # a very good date/time module from matplotviz -- allows years < 1970 
    23from KML import * 
    34 
     5# [TODO] 
     6#        * Resolve maxDirDepth 
     7 
    48wmsXmlNamespace = 'http://www.opengis.net/wms' 
     9 
    510 
    611def wmsLayerFactory(layerElement): 
     
    1722        childWmsLayers.append(childWmsLayer) 
    1823    if childElements != []: 
    19         return WMSLayer(name, title, abstract, childWmsLayers) 
     24        return WMSLayer(name, title, abstract, childWmsLayers)         
    2025    else: 
    2126        dimensionElements = layerElement.findall('{%s}Dimension' % wmsXmlNamespace) 
    2227        for dimensionElement in dimensionElements: 
    2328            if dimensionElement.get('name') == 'time': 
    24                 times = map( dates.dateutil.parser.parse, dimensionElement.text.split(',') ) 
    25         return BottomWMSLayer(name, title, abstract, times) 
     29                timesteps = map( dates.dateutil.parser.parse, dimensionElement.text.split(',') ) 
     30        return BottomWMSLayer(name, title, abstract, timesteps) 
    2631 
    2732class WMSLayer: 
     
    9297        ''' 
    9398 
    94         def buildWMSRequest(timestep): 
     99        def buildWMSRequest(layerName, timestep): 
    95100            ''' Build a WMS request ''' 
    96101 
     
    108113            bBox = '-180,-90,180,90' 
    109114             
    110             wmsRequest = '%s?request=GetMap&amp;SERVICE=%s&amp;FORMAT=%s&amp;LAYERS=%s&amp;BBOX=%s&amp;WIDTH=%s&amp;HEIGHT=%s&amp;CRS=%s&TIME=%s' % (url, serviceVersion, imageFormat, layerName, bBox, imageWidth, imageHeight, crs, timeStep) 
     115            wmsRequest = '%s?request=GetMap&amp;SERVICE=%s&amp;FORMAT=%s&amp;LAYERS=%s&amp;BBOX=%s&amp;WIDTH=%s&amp;HEIGHT=%s&amp;CRS=%s&TIME=%s' % (url, serviceVersion, imageFormat, layerName, bBox, imageWidth, imageHeight, crs, timestep.isoformat()) 
    111116 
    112117            return wmsRequest 
    113118 
    114119        def buildKmlGroundOverlay(view, timestep): 
    115             (timespanStart, timespanEnd) = view.getLogicalTimeSpan(timestep) 
     120            (timespanStart, timespanEnd) = view.getLogicalTimespan(timestep) 
    116121            return KMLGroundOverlay( 
    117                 self.name + ' ' + timeStep, 
    118                 buildWMSRequest(timestep), 
     122                self.name + ' ' + timestep.isoformat(), 
     123                buildWMSRequest(self.name, timestep), 
    119124                timespanStart, timespanEnd, 
    120125                -180, -90, 180, 90, 
     
    138143 
    139144            for category in categories: 
    140                 categoryName = view.getCategoryName(category) 
     145                categoryName = view.getCategoryDescription(timestep) 
    141146                kmlCategoryFolder = KMLFolder(categoryName, [], visible = False, opened = False) 
    142147                for timestep in dict[category]: 
     
    163168        pass 
    164169 
    165     def getLogicalTimespan(timestep): 
     170    def getLogicalTimespan(self, timestep): 
    166171        ''' 
    167172        Abstract method, defined in derived classes. 
     
    172177        pass 
    173178 
    174     def getCategory(timestep): 
     179    def getCategory(self, timestep): 
    175180        pass 
    176181 
    177     def getCategoryName(category): 
    178         ''' 
    179         Abstract method, defined in derived classes.  
    180         Get a human-readable name for this viewing category. 
    181         For instance, a value 2 could be replaced with a 'February' (in case of split-by-month view),  
    182         or a value 1990 could be replaced with a 'Decade of 1990' (in case of split-by-decade view). 
     182    def getCategoryDescription(self, timestep): 
     183        ''' 
     184        Abstract method, defined in derived classes. 
     185        Get a human-readable description of the category that timestep belongs to. 
    183186        ''' 
    184187        pass 
    185188 
    186     def _getSameDate(timestep): 
     189    def _getSameDate(self, timestep): 
    187190        return timestep 
    188191 
    189     def _getFirstDayOfMonth(timestep): 
     192    def _getFirstDayOfMonth(self, timestep): 
    190193        return timestep.replace(day=1) 
    191194 
    192     def _get20thCenturyDecade(timestep): 
     195    def _get20thCenturyDecade(self, timestep): 
    193196        replYear = (timestep.year - 1900) / 10 + 1       # get decade as a "logical" year 
    194197        return timestep.replace(year=replYear, day=1)    # start a month on the 1st of the month 
    195198 
    196     def _getMonthHence(timestep): 
     199    def _getMonthHence(self, timestep): 
    197200        if timestep.month+1 <= 12: 
    198201            return timestep.replace(month=timestep.month+1) 
     
    200203            return timestep.replace(year=timestep.year+1, month=1) 
    201204     
    202     def _getYearHence(timestep): 
     205    def _getYearHence(self, timestep): 
    203206        return timestep.replace(year=timestep.year+1) 
    204207 
    205     def _getDecadeHence(timestep): 
     208    def _getDecadeHence(self, timestep): 
    206209        return timestep.replace(year=timestep.year+10) 
    207210 
     
    212215 
    213216    def getLogicalTimespan(self, timestep): 
    214         timespanStart = _get20thCenturyDecade(timestep) 
    215         timespanEnd = _getMonthHence(timespanStart) 
     217        timespanStart = self._get20thCenturyDecade(timestep) 
     218        timespanEnd = self._getMonthHence(timespanStart) 
    216219        return (timespanStart, timespanEnd) 
    217220 
    218221    def getCategory(self, timestep): 
    219         return dt.isoformat() 
    220  
    221     def getCategoryName(self, timestep): 
    222         return dt.isoformat() 
     222        return timestep.isoformat() 
     223 
     224    def getCategoryDescription(self, timestep): 
     225        return self.getCategory(timestep) 
    223226 
    224227class ViewSplittedByMonth(View): 
     
    228231 
    229232    def getLogicalTimespan(self, timestep): 
    230         timespanStart = _getFirstDayOfMonth(timestep) 
    231         timespanEnd = _getDecadeHence(timespanStart) 
     233        timespanStart = self._getFirstDayOfMonth(timestep) 
     234        timespanEnd = self._getDecadeHence(timespanStart) 
    232235        return (timespanStart, timespanEnd) 
    233236 
     
    235238        return timestep.month 
    236239 
    237     def getCategoryName(self, timestep): 
     240    def getCategoryDescription(self, timestep): 
     241        ''' 
     242        Get a human-readable description of the category that timestep belongs to. 
     243        For instance, for timestep being 2000-02-14T10:11:12Z (which belongs into category 2), the result is 'February'. 
     244        ''' 
    238245        monthNames = ['January', 'February', 'March', 'April', 'May', 'June',  
    239246                      'July', 'August', 'September', 'October', 'November', 'December'] 
     
    246253 
    247254    def getLogicalTimespan(self, timestep): 
    248         timespanStart = _getFirstDayOfMonth(timestep) 
    249         timespanEnd = _getMonthHence(timespanStart) 
     255        timespanStart = self._getFirstDayOfMonth(timestep) 
     256        timespanEnd = self._getMonthHence(timespanStart) 
    250257        return (timespanStart, timespanEnd) 
    251258 
     
    253260        return timestep.year 
    254261 
    255     def getCategoryName(self, category): 
     262    def getCategoryDescription(self, timestep): 
     263        ''' 
     264        Get a human-readable description of the category that timestep belongs to. 
     265        For instance, for timestep being 1990-05-17T02:05:17Z, the result would be 'Decade of 1990'. 
     266        ''' 
    256267        return 'Decade of ' + str(self.getCategory(timestep)) 
    257268 
     
    275286class WMSLayersConvertor: 
    276287     
    277     # [RESOLVE] maxDirDepth 
    278288    def __init__(self, topWmsLayer, wmsRequestConfigElement, baseKmlOutputDirectory): 
    279289        self.topWmsLayer = topWmsLayer 
     
    293303            if currentLevel < self.maxDirDepth: 
    294304                currentDir = parentDir + '/' + wmsLayer.name 
    295                 ###os.mkdir(currentDir) 
     305                os.mkdir(currentDir) 
    296306                print 'Created directory "%s"' % currentDir 
    297307                if not isinstance(wmsLayer, BottomWMSLayer): 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/tests/testWMSCapabilities.py

    r3506 r3508  
    1515etree2 = ElementTree() 
    1616etree2.parse('../../../../testdata/ar4.conf.xml') 
    17 wmsRequestConfigElement = etree2.getroot() 
     17wmsRequestConfigElement = etree2.getroot().find('WMSRequest') 
    1818 
    19 wmsLayersConvertor = WMSLayersConvertor(wmsCapabilities.topWmsLayer, None, '../../../../output/wms-ar4') 
     19wmsLayersConvertor = WMSLayersConvertor(wmsCapabilities.topWmsLayer, wmsRequestConfigElement, '../../../../output/wms-ar4') 
    2020wmsLayersConvertor.convert() 
Note: See TracChangeset for help on using the changeset viewer.