Changeset 3698 for DPPP


Ignore:
Timestamp:
28/03/08 15:26:39 (11 years ago)
Author:
mkochan
Message:

Extended StationConvertor? to handle colouring of stations. Added config file for the ECN dataset.

Location:
DPPP/kml/csml2kml/python
Files:
1 added
8 edited

Legend:

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

    r3654 r3698  
    150150    to be associated with C{KMLPlacemark} objects. 
    151151    @type iconURL: C{str} 
     152    @ivar iconColor: Can contain a color to be blended with the icon image, in hexadecimal RGBA format 
     153    (for example, "00ff00ff" would mean green with 100% alpha). 
     154    @type iconColor: C{str} 
    152155    @ivar balloonTemplate: Can contain a HTML template with variables that are substituted during build 
    153156    using from C{KMLPlacemark.data} attributes; 
     
    160163    ''' 
    161164 
    162     def __init__(self, id, iconURL = None, balloonTemplate = None, listItemType = None): 
     165    def __init__(self, id, iconURL = None, iconColor = 'ffffffff', balloonTemplate = None, listItemType = None): 
    163166        self.id = id 
    164167        self.iconURL = iconURL 
     168        self.iconColor = iconColor 
    165169        self.balloonTemplate = balloonTemplate 
    166170        if listItemType: 
     
    178182        if self.iconURL: 
    179183            iconStyleElement = SubElement(styleElement, 'IconStyle') 
    180             SubElement(iconStyleElement, 'scale').text = '1.2' 
     184            SubElement(iconStyleElement, 'scale').text = '1.2'             
     185            SubElement(iconStyleElement, 'color').text = self.iconColor 
    181186            iconElement = SubElement(iconStyleElement, 'Icon') 
    182187            SubElement(iconElement, 'href').text = self.iconURL 
     
    202207    @rtype: C{KMLStyle} 
    203208    ''' 
    204     return KMLStyle(id, iconURL, balloonTemplate) 
     209    return KMLStyle(id, iconURL = iconURL, balloonTemplate = balloonTemplate) 
    205210 
    206211class KMLPlacemark(KMLElement): 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/StationConvertor.py

    r3686 r3698  
    55from ET import ElementTree, Element, SubElement, XML 
    66import re 
    7 import urllib 
    87from KML import * 
    98from QuadTree import * 
    10 from utils import wget 
     9import utils 
    1110from Station import NPStation, WFSStationCollection 
    1211 
     
    3130        self.documentName = self.config.find('DocumentName').text 
    3231 
     32        # Read the dataset identifier 
     33        ##### self.datasetId = self.config.find('DatasetID').text 
     34 
    3335        # URL of GeoServer to get a <wfs:StationCollection> from 
    3436        self.geoServerRequestUrl = self.config.find('GetAllStationsRequestURL').text 
    3537 
    36         # Get template for placemark balloons; create a KML style for placemarks 
     38        # Get template for placemark balloons; create two KML styles for white and red placemarks 
     39        # (red for stations with embedded features, white for the rest). 
    3740        self.balloonTemplate = self.config.find('BalloonTemplate').text 
    38         self.placemarkKmlStyle = createDefaultPlacemarKMLStyle(balloonTemplate = self.balloonTemplate) 
     41        self.whitePlacemarkKmlStyle = createDefaultPlacemarKMLStyle(balloonTemplate = self.balloonTemplate) 
     42        self.whitePlacemarkKmlStyle.id = 'white_placemark_style' 
     43        self.redPlacemarkKmlStyle = createDefaultPlacemarKMLStyle(balloonTemplate = self.balloonTemplate) 
     44        self.redPlacemarkKmlStyle.id = 'red_placemark_style' 
     45        self.redPlacemarkKmlStyle.iconColor = 'ff4444ff' # light red (white is default so no need to set it) 
    3946 
    4047        # Initialize placemark data -- i.e. values to be substituted for placeholders in the balloon template 
     
    5259        self.lockedFolderStyle = KMLStyle('locked_folder_style', listItemType = 'checkHideChildren') 
    5360 
     61        # Initialize the viewing interval 
     62        self.displayIntervalStart = utils.parseTimestamp(self.config.find('DisplayIntervalStart').text) 
     63        self.displayIntervalEnd = utils.parseTimestamp(self.config.find('DisplayIntervalEnd').text) 
     64 
    5465    def _npStationToKmlPlacemark(self, npStation): 
    5566        ''' 
    56         Converts a C{Station.NPStation} object into it's C{KML.KMLPlacemark} representation 
     67        Converts a C{Station.NPStation} object into it's C{KML.KMLPlacemark} representation. 
     68        Uses red placemark style for stations with some embedded features, white style for the remaining stations. 
    5769        @rtype: C{KML.KMLPlacemark} 
    5870        ''' 
     71        # isVisibleFeature will be True iff the stations contains AT LEAST ONE feature that measurement time in that period 
     72        isVisibleFeature = False 
     73        for stationFeature in npStation.stationFeatures: 
     74            if self.displayIntervalStart >= stationFeature.collectBeginDate and self.displayIntervalEnd <= stationFeature.collectEndDate: 
     75                isVisibleFeature = True 
     76                break 
     77 
     78        if isVisibleFeature: 
     79            placemarkKmlStyle = self.redPlacemarkKmlStyle 
     80        else: 
     81            placemarkKmlStyle = self.whitePlacemarkKmlStyle 
    5982        return KMLPlacemark(npStation.id, npStation.desc, npStation.lon, npStation.lat, 
    60                             styleID = self.placemarkKmlStyle.id, data = self.stationData 
     83                            styleID = placemarkKmlStyle.id, data = self.stationData 
    6184                            ) 
    6285 
     
    127150 
    128151        return kmlDocument 
    129  
     152     
    130153    def convert(self): 
    131154        ''' 
     
    144167 
    145168        # Get a collection of stations from a GeoServer, and put the stations into a list 
    146         geoServerResponse = wget(self.geoServerRequestUrl) 
     169        geoServerResponse = utils.wget(self.geoServerRequestUrl) 
    147170        wfsStationsCollection = WFSStationCollection() 
    148171        wfsStationsCollection.parseString(geoServerResponse) 
     
    150173 
    151174        # Create a KML document and attach the stations, either directly or using KML regions 
    152         kmlDocument = KMLDocument(self.documentName, [self.placemarkKmlStyle]) 
     175        kmlDocument = KMLDocument(self.documentName, [self.whitePlacemarkKmlStyle, self.redPlacemarkKmlStyle]) 
    153176        if self.useSections: 
    154177            kmlDocument = self._buildKmlDocumentUsingSections(kmlDocument, npStations) 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/config/midas.csml2kml.conf.xml

    r3686 r3698  
    33  <UseRegions>yes</UseRegions> 
    44  <GetAllStationsRequestURL><![CDATA[http://bond.badc.rl.ac.uk:8084/geoserver/wfs?request=getFeature&service=wfs&version=1.1.0&typename=np:Station&maxFeatures=100000]]></GetAllStationsRequestURL> 
    5   <BalloonTemplate>&lt;h2&gt;Station $[station_name]&lt;/h2&gt;Click here to see the list of &lt;a href=&quot;http://superglue.badc.rl.ac.uk:8084/csmlGrapher/list?station_name=$[station_name]&quot;&gt;CSML features associated with this station&lt;/a&gt; (this will open a window of your default web browser).</BalloonTemplate> 
     5  <BalloonTemplate>&lt;h2&gt;Station $[station_name]&lt;/h2&gt;Click here to see the list of &lt;a href=&quot;http://superglue.badc.rl.ac.uk:8084/csmlGrapher/list?dataset_id=midas&amp;station_name=$[station_name]&quot;&gt;CSML features associated with this station&lt;/a&gt; (this will open a window of your default web browser).</BalloonTemplate> 
    66  <StationData> 
    77    <Datum name="station_id">#ID#</Datum> 
    88    <Datum name="station_name">#NAME#</Datum> 
    99  </StationData> 
     10  <DisplayIntervalStart>2006-6-1</DisplayIntervalStart> 
     11  <DisplayIntervalEnd>2006-8-1</DisplayIntervalEnd> 
    1012  <OutputKmzFilename>/home/users/mkochan/svn-root/kml/csml2kml/output/midas_stations.kmz</OutputKmzFilename> 
    1113</Stations2KML> 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/utils.py

    r3693 r3698  
    66import urllib2 
    77from matplotlib import dates 
    8  
    9 class UrlRetrievalError(Exception): 
    10     def __init__(self, value): 
    11         self.value = value 
    12     def __repr__(self): 
    13         return repr(self.value) 
    148 
    159def wget(url): 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/config/midas.csml2kmlpylon.conf.xml

    r3693 r3698  
    11<GrapherWebService> 
    2   <DisplayIntervalStart>1-5-2006</DisplayIntervalStart> 
    3   <DisplayIntervalEnd>1-6-2006</DisplayIntervalEnd> 
     2  <DisplayIntervalStart>2006-6-1</DisplayIntervalStart> 
     3  <DisplayIntervalEnd>2006-8-1</DisplayIntervalEnd> 
    44  <ServedFromURL>http://superglue.badc.rl.ac.uk:8084/csmlGrapher</ServedFromURL> 
    55  <Dataset id="midas" name="MIDAS"> 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/controllers/csmlGrapher.py

    r3693 r3698  
    8181 
    8282        # Acquire the GeoServer response and parse it into a CSMLFeatureCollection object 
     83        print geoServerRequestUrl 
    8384        geoServerResponse = wget(geoServerRequestUrl) 
    8485        if not geoServerResponse: 
     
    272273        print geoServerRequestUrl 
    273274        geoServerResponse = wget(geoServerRequestUrl) 
    274         if not geoServerResponse: 
    275             raise LookupError('Cannot acquire response from server (wrong URL or server down)') 
    276275        wfsStationCollection = csml2kml.Station.WFSStationCollection() 
    277276        wfsStationCollection.parseString(geoServerResponse) 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/development.ini

    r3657 r3698  
    3535# Debug mode will enable the interactive debugging tool, allowing ANYONE to 
    3636# execute malicious code after an exception is raised. 
    37 set debug = false 
     37# set debug = false 
    3838 
    3939# Logging configuration 
Note: See TracChangeset for help on using the changeset viewer.