Changeset 3198


Ignore:
Timestamp:
10/01/08 15:35:44 (12 years ago)
Author:
mkochan
Message:

Changed WMS request-building code; outsourced most request parameters to a config file, config.xml. (This will later be bound to each CSML file.)

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

Legend:

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

    r3193 r3198  
    4040        SubElement(kml_document, 'open').text='1' 
    4141 
     42        datasetName = os.path.split(self.csmlFilename)[1].split('.')[0] 
     43 
    4244        # Create a separate KML folder for each feature 
    4345        for feature in self.ds.featureCollection.featureMembers: 
     46 
    4447            # GridSeriesFeatureWrapper allows extended querying of a GridSeriesFeature object 
    4548            gsFeature=GridSeriesFeatureWrapper(feature)  
    4649 
    47             description =  feature.description.CONTENT      
    48             shortname = feature.name.CONTENT 
    49             bbox=gsFeature.getBBox() 
    50             timesteps=gsFeature.getTimeSteps() 
    51             timebounds=gsFeature.getTimeBounds() 
    52  
    53             # [UNCLEAR] 
    54             # wmsendpoint e.g. http://ndgbeta.badc.rl.ac.uk/wcs/badc.nerc.ac.uk__NDG-A0__AWQX8gTc? 
    55             wmsendpoint='tba' 
    56             #wmsendpoint e.g. 'clim_10/cld' 
    57             #is this consistent for all WMSs -- perhaps we need to provide this information as input parameter 
    58             # [NOTE] Uses csmlFilename -- un-nice way of passing endpoint 
    59             wmslayer=os.path.split(self.csmlFilename)[1].split('.')[0]+ '/' + feature.name.CONTENT 
     50            description = feature.description.CONTENT      
     51            name = feature.name.CONTENT 
     52            bBox = gsFeature.getBBox() 
     53            timeSteps = gsFeature.getTimeSteps() 
     54            timeBounds = gsFeature.getTimeBounds() 
    6055 
    6156            # Instantiate a GridSeriesKML object with this information 
    62             gsKML=kmlfeatures.GridSeriesKML(description, shortname, wmsendpoint, wmslayer, bbox, timesteps, timebounds) 
     57            gsKML = kmlfeatures.GridSeriesKML(description, name, bBox, timeSteps, timeBounds) 
    6358 
    6459            # Call the outputKML method of this object to generate a populated KML Folder element 
    65             kml_folder=gsKML.outputKML(kmlfeatures.GridSeriesKML.getDecadeSince1990) 
     60            kml_folder = gsKML.outputKML(kmlfeatures.GridSeriesKML.getDecadeSince1900) 
    6661 
    6762            # Append the folder to the kml document. 
  • DPPP/kml/csml2kml/python/csmlwrappers.py

    r3193 r3198  
    2121        return timesteps 
    2222     
    23     # [TO_DO]  Requires a look into the specs. 
     23    # Currently unsupported because it is not properly used in CSML 
    2424    def getTimeBounds(self): 
    2525        timebounds='' 
  • DPPP/kml/csml2kml/python/kmlfeatures.py

    r3193 r3198  
    55 
    66class GridSeriesKML(object): 
    7     ''' represents a CSML GridSeriesFeature in KML (via WMS requests).''' 
     7    ''' Represents a CSML GridSeriesFeature in KML (via WMS requests).''' 
    88     
    9     def __init__(self, description, shortname, wmsendpoint, wmslayer, bbox, timesteps, timebounds): 
    10         ''' initialise with the key information content''' 
     9    def __init__(self, parentFilename, name, description, bBox, timeSteps, timeBounds): 
     10        ''' Initialise with the key information content''' 
     11 
     12        #Name of the CSML file in which feature is contained 
     13        self.parentFilename = parentFilename 
     14 
     15        #A short name for the feature: 
     16        self.name=name 
    1117 
    1218        #A descriptive name for the feature: 
    13         self.description=description         
    14         #A short name for the feature: 
    15         self.shortname=shortname 
    16         #The WMS endpoint:    
    17         self.wmsendpoint=wmsendpoint 
    18         #The WMS layer name: 
    19         self.wmslayer=wmslayer 
     19        self.description=description 
     20 
    2021        #The latitude/longitude bounding box as a csmlwrappers.BBox object  
    21         self.bbox=bbox 
    22         #The timesteps  
    23         self.timesteps=timesteps 
    24         #The valid bounds of the individual timesteps 
    25         self.timebounds=timebounds 
     22        self.bBox=bBox 
     23 
     24        #The time steps  
     25        self.timeSteps=timeSteps 
     26 
     27        #Valid bounds of the individual timesteps 
     28        self.timeBounds=timeBounds 
    2629     
    2730    def getDecadeSince1900(self, year): 
     
    3134        return year 
    3235 
    33     #--------------------------------------------------------------------------------     
    34     # _getLogicalTimeSpan() 
    35     # [UNCLEAR] Am not sure about difference between asking WMS for data at some date 
    36     #           and at midnight of that day -- which is correct? 
    37     #-------------------------------------------------------------------------------- 
    3836    def _getLogicalTimeSpan(self, timestep, getLogicalYear): 
    3937        '''Translate timestep to a timespan that covers a full month in a year 
    40         corresponding to the decade (e.g. 1900s -> 0, 1980s -> 8 
     38           corresponding to the decade (e.g. 1900s -> 0, 1980s -> 8 
    4139        ''' 
    4240        matchObject = re.match("(\d+)\-(\d+)\-(\d+)T", timestep) 
     
    5351        return (startDate, endDate) 
    5452     
    55     # [HARDCODED] 
     53    # [UNRESOLVED] bBox dependency 
    5654    def _buildWMSRequest(self, timestep): 
    57         ''' build wms request based on values of wmsendpoint, wmslayer, bbox ''' 
    58         #hardcoded to ipcc development site for demo purposes - in NERC portals endpoint should be of form: http://host/wms/identifier 
    59         wmsrequest='       http://www-devel.ipcc-data.org/maps/wms/obs?request=GetMap&SERVICE=1.1.1&FORMAT=image/png&LAYERS=%s&BBOX=-180,-90,180,90&WIDTH=640&HEIGHT=480&SRS=EPSG:4326&TIME=%s'%(self.wmslayer, timestep+'Z') 
     55        ''' Build a WMS request ''' 
     56        
     57        c = getFeatureWMSRequestConfig() 
     58        url = c.get('URL').CONTENT 
     59        serviceVersion = c.get('ServiceVersion').CONTENT 
     60        imageFormat = c.get('ImageFormat').CONTENT 
     61        imageWidth = c.get('ImageWidth').CONTENT 
     62        imageHeight = c.get('ImageHeight').CONTENT 
     63        layerName = c.get('LayerName').CONTENT 
     64        filenameExcludingSuffix = string.join(parentFilename.split('.')[:-1], '.') 
     65        layerName.replace('#FILENAME_EXCL_SUFFIX#', filenameExcludingSuffix) 
     66        layerName.replace('#FEATURE_NAME#', name) 
     67        crs = c.get('CRS').CONTENT 
    6068 
    61         return wmsrequest 
     69        wmsRequest = '%s?request=GetMap&SERVICE=%s&FORMAT=%s&LAYERS=%s&BBOX=%s&WIDTH=%s&HEIGHT=%s&CRS=%s&TIME=%s' % (url, serviceVersion, imageFormat, layerName, bBox, imageWidth, imageHeight, crs, timeStep+'Z') 
     70 
     71        return wmsRequest 
    6272 
    6373    def outputKML(self, logicalYearTransform): 
Note: See TracChangeset for help on using the changeset viewer.