Changeset 3757 for DPPP


Ignore:
Timestamp:
04/04/08 11:30:44 (11 years ago)
Author:
mkochan
Message:

Made list of views views to be used in wms2kml configurable. Enforced timestamps in WMS queries to contain ".0" for microseconds.

Location:
DPPP/kml/python
Files:
14 edited

Legend:

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

    r3743 r3757  
    77from matplotlib import dates     # a very good date/time module from matplotviz -- allows years < 1970 
    88from KML import * 
     9import utils 
    910 
    1011wmsXmlNamespace = 'http://www.opengis.net/wms'  # a XML namespace in which the <wms:Layer> element is defined 
     
    361362            else: 
    362363                crsParam = 'SRS' 
     364 
     365            crs = c.find('CRS').text 
    363366                 
    364  
    365367            imageFormat = c.find('ImageFormat').text 
    366368            imageWidth = c.find('ImageWidth').text 
    367369            imageHeight = c.find('ImageHeight').text 
    368             crs = c.find('CRS').text 
    369  
    370             # If the timezone is UTC (which in ISO form would look like 'yyyy-mm-ddThh:mm:ss+00:00'), 
    371             # then replace it with 'Z'. 
    372             timestepString = timestep.isoformat() 
    373             #!TODO: This shouldn't be necessary but is needed to work with CSML WMSs at the moment 
    374             timestepString += '.0' 
    375             timestepString = timestepString.replace('+00:00', 'Z') 
     370 
     371            # Create the proper time stamp 
     372            timestepString = utils.datetimeToTimestamp(timestep) 
    376373 
    377374            wmsRequest = '%s?request=GetMap&VERSION=%s&FORMAT=%s&LAYERS=%s&BBOX=%s&WIDTH=%s&HEIGHT=%s&%s=%s&TIME=%s' % (url, serviceVersion, imageFormat, self.layer.name, str(self.layer.bbox), imageWidth, imageHeight, crsParam, crs, timestepString) 
     
    394391                visible = False 
    395392                ) 
    396  
     393     
    397394        # Create a KML folder that represents the view of the layer 
    398395        kmlLayerViewFolder = KMLFolder(self.name, [], visible = False, opened = False, description = self.description) 
  • DPPP/kml/python/csml2kml/csml2kml/WMSLayerConvertor.py

    r3743 r3757  
    1010    ''' 
    1111 
    12     def __init__(self, topWmsLayer, wmsRequestConfigElement, baseKmlOutputDirectory, baseKmlOutputUrl): 
     12    def __init__(self, topWmsLayer, viewTypes, wmsRequestConfigElement, baseKmlOutputDirectory, baseKmlOutputUrl): 
    1313        ''' 
    1414        The constructor. 
     
    2525        ''' 
    2626        self.topWmsLayer = topWmsLayer 
     27        self.viewTypes = viewTypes 
    2728        self.wmsRequestConfigElement = wmsRequestConfigElement 
    2829        self.baseKmlOutputDirectory = baseKmlOutputDirectory 
     
    4647        However, more views can be created (by extending {WMSLayer.View}) and added later. 
    4748        """ 
    48         #!TODO: make viewTypes configurable. 
    49         #viewTypes = [ViewWholeTimecourse, ViewSplittedByMonth, ViewSplittedByPeriod] 
    50         viewTypes = [ViewWholeTimecourse] 
    51         self.topWmsLayer.toKML(self.wmsRequestConfigElement, viewTypes, self.baseKmlOutputDirectory, self.baseKmlOutputUrl) 
     49        self.topWmsLayer.toKML(self.wmsRequestConfigElement, self.viewTypes, self.baseKmlOutputDirectory, self.baseKmlOutputUrl) 
  • DPPP/kml/python/csml2kml/csml2kml/scripts/wms2kml.py

    r3743 r3757  
    22from csml2kml.ET import ElementTree, XML 
    33from csml2kml.utils import wget 
     4import csml2kml.WMSLayer 
    45from csml2kml.WMSLayer import WMSCapabilities 
    56from csml2kml.WMSLayerConvertor import WMSLayerConvertor 
     
    2728    wmsCapabilities.parseXML(wmsCapabilitiesElement) 
    2829     
     30    # Create a list of layer view types to be used -- i.e. a list of *classes* (not instances!) which 
     31    # represent different ways of viewing WMS layers. 
     32    viewTypes = [] 
     33    for viewTypeNameElement in configElementTree.getroot().findall('Views/View'): 
     34        viewType = csml2kml.WMSLayer.__getattribute__(viewTypeNameElement.text) 
     35        viewTypes.append(viewType) 
     36 
    2937    # Initialise the convertor and perform the conversion 
    3038    wmsLayerConvertor = WMSLayerConvertor( 
    31         wmsCapabilities.topWmsLayer, wmsRequestConfigElement, outputRootDirectory, serverRootDirectory 
     39        wmsCapabilities.topWmsLayer, viewTypes, wmsRequestConfigElement, outputRootDirectory, serverRootDirectory 
    3240        ) 
    3341    wmsLayerConvertor.convert() 
  • DPPP/kml/python/csml2kml/csml2kml/utils.py

    r3717 r3757  
    4040    @type timestamp: C{str} 
    4141    @return: Corresponding datetime 
    42     @rtype: C{dates.datetime.datetime} 
     42    @rtype: C{matplotlib.dates.datetime.datetime} 
    4343    ''' 
    4444    mo = re.match('(.+)24\:00\:00(Z?)', timestamp) 
     
    4949    else: 
    5050        return dates.dateutil.parser.parse(timestamp) 
     51 
     52def datetimeToTimestamp(datetime, enforceMicrosecs = True, enforceZulu = True): 
     53    ''' 
     54    A datetime-to-timestamp conversion function for convenience (as the standard conversion functions do not easily 
     55    allow as much flexibility as we need.) 
     56    @param datetime: The datetime to be converted. 
     57    @param enforceMicrosecs: If C{True}, microseconds are always shown. If C{False}, they are never shown. 
     58    @paran enforceZulu: If C{True}, then the "Z" letter is appended at the end of timestamp given that the 
     59    timezone is UTC or C{None} (throws C{NotImplementedError} if other time zone is used). 
     60    If C{False}, no timezone info is given. 
     61    ''' 
     62    if enforceMicrosecs: 
     63        if datetime.microsecond == 0: 
     64            microsecStr = '.0' 
     65        else: 
     66            microsecStr = '.%06d' % microsec 
     67    else: 
     68        microsecStr = '' 
     69 
     70    if enforceZulu: 
     71        if datetime.tzname() == None or datetime.tzname() == 'UTC': 
     72            tzStr = 'Z' 
     73        else: 
     74            raise NotImplementedError('Time zones other than none and UTC are not supported.') 
     75    else: 
     76        tzStr = '' 
     77 
     78    return '%04d-%02d-%02dT%02d:%02d:%02d%s%s' % (datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, datetime.second, microsecStr, tzStr) 
  • DPPP/kml/python/csml2kmlpylon/deploy.ini

    r3718 r3757  
    1414use = egg:Paste#http 
    1515host = 0.0.0.0 
    16 port = 8084 
     16port = 8082 
    1717 
    1818[app:main] 
Note: See TracChangeset for help on using the changeset viewer.