Changeset 3713


Ignore:
Timestamp:
01/04/08 12:30:38 (11 years ago)
Author:
mkochan
Message:

Added links to underlying CSML in csmlGrapher (can be toggled for each dataset).

Location:
DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/config/csml2kmlpylon.conf.xml

    r3705 r3713  
    66    <GeoServerURL>http://bond.badc.rl.ac.uk:8084/geoserver/wfs</GeoServerURL> 
    77    <DatetimeQueryFormat>1-JAN-1970</DatetimeQueryFormat> 
     8    <IsCSMLLinkVisible>yes</IsCSMLLinkVisible> 
    89  </Dataset> 
    910  <Dataset id="ecn" name="ECN"> 
    1011    <GeoServerURL>http://dppp.nerc-lancaster.ac.uk:8080/geoserver/wfs</GeoServerURL> 
    1112    <DatetimeQueryFormat>UTC_TIMESTAMP</DatetimeQueryFormat> 
     13    <IsCSMLLinkVisible>yes</IsCSMLLinkVisible> 
    1214  </Dataset> 
    1315</GrapherWebService> 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/controllers/csmlGrapher.py

    r3707 r3713  
    1818from csml2kml.utils import wget, URLError 
    1919from csml2kml.ET import Element, SubElement, ElementTree, XML 
     20from string import lower 
    2021 
    2122log = logging.getLogger(__name__) 
     
    2930        E.g. MIDAS and ECN are different datasets (each has a WFS URL from which it is being accessible). 
    3031        ''' 
    31         def __init__(self, id, name, geoServerUrl, datetimeQueryFormat): 
     32        def __init__(self, id, name, geoServerUrl, datetimeQueryFormat, isCsmlLinkVisible): 
    3233            self.id = id 
    3334            self.name = name 
    3435            self.geoServerUrl = geoServerUrl 
    3536            self.datetimeQueryFormat = datetimeQueryFormat 
     37            self.isCsmlLinkVisible = isCsmlLinkVisible 
    3638 
    3739    def __call__(self, environ, start_response): 
     
    5456        for datasetElement in datasetElements: 
    5557            id = datasetElement.get('id') 
     58             
    5659            self.datasets[id] = self.Dataset( 
    5760                id,  
    5861                datasetElement.get('name'), 
    5962                datasetElement.find('GeoServerURL').text, 
    60                 datasetElement.find('DatetimeQueryFormat').text 
     63                datasetElement.find('DatetimeQueryFormat').text, 
     64                datasetElement.find('IsCSMLLinkVisible').text.lower() == 'yes' 
    6165                ) 
    6266 
     
    102106        else: 
    103107            raise ValueError('Wrong keyword in the <DatetimeQueryFormat> tag in the config file.') 
     108 
     109    def _buildCsmlRequestUrl(self, dataset, station_name, feature_id): 
     110        ''' 
     111        Build a GeoServer query URL that can be used to retrieve a CSML PointSeriesFeature. 
     112        @param dataset: The dataset used to retrieve from 
     113        @type: C{Dataset} 
     114        @param station_name: Unique full name of the station, eg C{FAIR ISLE}. 
     115        @type station_name: C{str} 
     116        @param feature_id: Unique id of the CSML feature, eg C{air_temperature}. 
     117        @type feature_id: C{str} 
     118        @return: The URL. 
     119        @rtype: C{str} 
     120        ''' 
     121        return urllib.quote(dataset.geoServerUrl + '?request=getfeature&service=wfs&version=1.1.0&typename=csml:PointSeriesFeature&filter=<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>gml:description</ogc:PropertyName><ogc:Literal>'+ station_name +'</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>csml:parameter/swe:Phenomenon/gml:name</ogc:PropertyName><ogc:Literal>'+ feature_id +'</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsBetween><ogc:PropertyName>csml:value/csml:PointSeriesCoverage/csml:pointSeriesDomain/csml:TimeSeries/csml:timePositionList</ogc:PropertyName><ogc:LowerBoundary><ogc:Literal>'+ self._datetimeToGeoServerDate(self.displayIntervalStart, dataset.datetimeQueryFormat) +'</ogc:Literal></ogc:LowerBoundary><ogc:UpperBoundary><ogc:Literal>'+ self._datetimeToGeoServerDate(self.displayIntervalEnd, dataset.datetimeQueryFormat) +'</ogc:Literal></ogc:UpperBoundary></ogc:PropertyIsBetween></ogc:And></ogc:Filter>', '/._:?&=') 
    104122 
    105123    def _retrieveCsmlPointSeriesFeature(self, dataset, station_name, feature_id): 
     
    117135        @throws: A C{LookupError} exception with a message if there is no response from the server. 
    118136        ''' 
    119         # Prepare the request for the dataset's GeoServer 
    120         geoServerRequestUrl = urllib.quote(dataset.geoServerUrl + '?request=getfeature&service=wfs&version=1.1.0&typename=csml:PointSeriesFeature&filter=<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>gml:description</ogc:PropertyName><ogc:Literal>'+ station_name +'</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>csml:parameter/swe:Phenomenon/gml:name</ogc:PropertyName><ogc:Literal>'+ feature_id +'</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsBetween><ogc:PropertyName>csml:value/csml:PointSeriesCoverage/csml:pointSeriesDomain/csml:TimeSeries/csml:timePositionList</ogc:PropertyName><ogc:LowerBoundary><ogc:Literal>'+ self._datetimeToGeoServerDate(self.displayIntervalStart, dataset.datetimeQueryFormat) +'</ogc:Literal></ogc:LowerBoundary><ogc:UpperBoundary><ogc:Literal>'+ self._datetimeToGeoServerDate(self.displayIntervalEnd, dataset.datetimeQueryFormat) +'</ogc:Literal></ogc:UpperBoundary></ogc:PropertyIsBetween></ogc:And></ogc:Filter>', '/._:?&=') 
    121  
    122137        # Acquire the GeoServer response and parse it into a CSMLFeatureCollection object 
     138        geoServerRequestUrl = self._buildCsmlRequestUrl(dataset, station_name, feature_id) 
    123139        print geoServerRequestUrl 
    124140        try: 
     
    135151        except AttributeError: 
    136152            raise LookupError( 
    137                 'No data points available for the given time interval. ' +  
    138                 'Perhaps the interval is shorter than the frequency of data points, ' + 
    139                 'or collection of data for this feature was interrupted at the time.' 
     153                'Wrong feature ID or no data points available for the given time interval ' +  
     154                '(perhaps the interval is shorter than the frequency of sampling of data points, ' + 
     155                'or collection of data for this feature was interrupted during the plotting interval).' 
    140156                ) 
    141157 
     
    344360        # Generate HTML with a list of CSML features contained in the station. 
    345361        # Currently, this is done simply by directly generating HTML (i.e. no template was used). 
     362        # The table column with links to CSML will appear only if that is allowed for the dataset in the config file. 
    346363        htmlRows = '' 
    347364        for stationFeature in wfsStation.stationFeatures: 
     
    350367                    self.servedFromUrl, dataset_id, station_name, stationFeature.featureId 
    351368                    ) 
    352                 htmlRow = '<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % ( 
     369                if dataset.isCsmlLinkVisible: 
     370                    htmlLinkToCsml = self._buildCsmlRequestUrl(dataset, station_name, stationFeature.featureId) 
     371                    htmlLinkToCsmlDataitem = '<td><a href="%s">%s</a></td>' % (htmlLinkToCsml, 'CSML') 
     372                else: 
     373                    htmlLinkToCsmlDataitem = '' 
     374                htmlRow = '<tr><td>%s</td>%s<td>%s</td><td>%s</td></tr>' % ( 
    353375                    '<a href="%s">%s</a>' % (htmlLinkToGrapher, stationFeature.featureId), 
     376                    htmlLinkToCsmlDataitem, 
    354377                    self._datetimeTo1Jan1970(stationFeature.collectBeginDate), 
    355378                    self._datetimeTo1Jan1970(stationFeature.collectEndDate) 
    356379                    ) 
    357380                htmlRows = htmlRows + htmlRow 
    358         htmlTable = '<table border="1"><tr><th>Feature name</th><th>Data collected since</th><th>Data collected until</th></tr>%s</table>' % htmlRows 
     381        if dataset.isCsmlLinkVisible: 
     382            underlyingDataHeaderItem = '<th>Underlying data</th>' 
     383        else: 
     384            underlyingDataHeaderItem = '' 
     385        htmlTable = '<table border="1"><tr><th>Feature plot</th>%s<th>Data collected since*</th><th>Data collected until*</th></tr>%s</table>' % (underlyingDataHeaderItem, htmlRows) 
    359386        htmlHeading = 'List of CSML features for station ' + station_name 
    360         htmlUsage = '' 
    361         htmlBody = '<h2>%s</h2>%s<p>%s' % (htmlHeading, htmlUsage, htmlTable) 
     387        htmlUsage = '* The sampling frequencies vary between features and there may be no data points for the chosen plotting interval.' 
     388        htmlBody = '<h2>%s</h2>%s<p>%s' % (htmlHeading, htmlTable, htmlUsage) 
    362389        htmlTitle = htmlHeading 
    363390        html = '<html><title>%s</title><body>%s</body></html>' % (htmlTitle, htmlBody) 
Note: See TracChangeset for help on using the changeset viewer.