Changeset 3705 for DPPP


Ignore:
Timestamp:
31/03/08 15:20:47 (11 years ago)
Author:
mkochan
Message:

Added configurable formatting of URL queries to WFS for requesting CSML features.

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

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/csml2kmlpylon

    • Property svn:ignore
      •  

        old new  
        1 build\ 
        2 dist 
         1dist build 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/config/csml2kmlpylon.conf.xml

    r3703 r3705  
    11<GrapherWebService> 
    22  <DisplayIntervalStart>2006-6-1</DisplayIntervalStart> 
    3   <DisplayIntervalEnd>2006-8-1</DisplayIntervalEnd> 
     3  <DisplayIntervalEnd>2006-7-1</DisplayIntervalEnd> 
    44  <ServedFromURL>http://superglue.badc.rl.ac.uk:8084/csmlGrapher</ServedFromURL> 
    55  <Dataset id="midas" name="MIDAS"> 
    66    <GeoServerURL>http://bond.badc.rl.ac.uk:8084/geoserver/wfs</GeoServerURL> 
     7    <DatetimeQueryFormat>1-JAN-1970</DatetimeQueryFormat> 
    78  </Dataset> 
    89  <Dataset id="ecn" name="ECN"> 
    910    <GeoServerURL>http://dppp.nerc-lancaster.ac.uk:8080/geoserver/wfs</GeoServerURL> 
     11    <DatetimeQueryFormat>UTC_TIMESTAMP</DatetimeQueryFormat> 
    1012  </Dataset> 
    1113</GrapherWebService> 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/controllers/csmlGrapher.py

    r3702 r3705  
    2929        E.g. MIDAS and ECN are different datasets (each has a WFS URL from which it is being accessible). 
    3030        ''' 
    31         def __init__(self, id, name, geoServerUrl): 
     31        def __init__(self, id, name, geoServerUrl, datetimeQueryFormat): 
    3232            self.id = id 
    3333            self.name = name 
    3434            self.geoServerUrl = geoServerUrl 
     35            self.datetimeQueryFormat = datetimeQueryFormat 
    3536 
    3637    def __call__(self, environ, start_response): 
     
    5354        for datasetElement in datasetElements: 
    5455            id = datasetElement.get('id') 
    55             self.datasets[id] = self.Dataset(id, datasetElement.get('name'), datasetElement.find('GeoServerURL').text) 
     56            self.datasets[id] = self.Dataset( 
     57                id,  
     58                datasetElement.get('name'), 
     59                datasetElement.find('GeoServerURL').text, 
     60                datasetElement.find('DatetimeQueryFormat').text 
     61                ) 
    5662 
    5763        # Set other configurable variables 
     
    5965        self.displayIntervalEnd = dates.dateutil.parser.parse(grapherConfig.find('DisplayIntervalEnd').text) 
    6066        self.servedFromUrl = grapherConfig.find('ServedFromURL').text 
    61  
    6267        print 'Config file parse finished.' 
    6368 
     
    6570        return BaseController.__call__(self, environ, start_response) 
    6671 
    67     def _datetimeToGeoServerDate(self, datetime): 
    68         monthCodes = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] 
    69         return repr(datetime.day) + '-' + monthCodes[datetime.month-1] + '-' + repr(datetime.year) 
     72    def _datetimeToGeoServerDate(self, datetime, datetimeQueryFormat): 
     73        if datetimeQueryFormat == 'UTC_TIMESTAMP': 
     74            # Use the UTC timestamp format, generate timestamp. 
     75            # (would like to do this using the datetime.strftime() method but it only supplies years after 1900). 
     76            dt = datetime 
     77            return '%04d-%02d-%02dT%02d:%02d:%02d' % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) 
     78        elif datetimeQueryFormat == '1-JAN-1970': 
     79            # Use format e.g. "1-JAN-1970" or "31-MAR-2008". 
     80            monthCodes = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] 
     81            return repr(datetime.day) + '-' + monthCodes[datetime.month-1] + '-' + repr(datetime.year) 
     82        else: 
     83            raise ValueError('Wrong keyword in the <DatetimeQueryFormat> tag in the config file.') 
    7084 
    7185    def _retrieveCsmlPointSeriesFeature(self, dataset, station_name, feature_id): 
     
    7892       
    7993        # Prepare the request for the dataset's GeoServer 
    80         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) +'</ogc:Literal></ogc:LowerBoundary><ogc:UpperBoundary><ogc:Literal>'+ self._datetimeToGeoServerDate(self.displayIntervalEnd) +'</ogc:Literal></ogc:UpperBoundary></ogc:PropertyIsBetween></ogc:And></ogc:Filter>', '/._:?&=') 
     94        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>', '/._:?&=') 
    8195 
    8296        # Acquire the GeoServer response and parse it into a CSMLFeatureCollection object 
    8397        print geoServerRequestUrl 
    84         geoServerResponse = wget(geoServerRequestUrl) 
    85         if not geoServerResponse: 
     98        try: 
     99            geoServerResponse = wget(geoServerRequestUrl) 
     100        except URLError: 
    86101            raise LookupError('Cannot acquire response from server (wrong URL or server down)') 
    87102        csmlFeatureCollection = csml.parser.CSMLFeatureCollection() 
     
    136151            times = map(_enforce_UTC_timezone, times) 
    137152 
    138             # Make a list of times as float numbers being days passed since start of epoch (here 01-01-0001) 
    139             elapsed_times = map(datestr2num, times) 
     153            # Make a list of times as float numbers being days passed since start of epoch (here 01-01-0001). 
     154            # (We need to use the wrapping function csml2kml.utils.parseTimestamp() because unfortunately the matplotlib's 
     155            #  datetime parser cannot handle timestamps like "2004-02-17T24:00:00" directly.) 
     156            elapsed_times = map(date2num, 
     157                                map(csml2kml.utils.parseTimestamp, 
     158                                    times 
     159                                    ) 
     160                                ) 
    140161 
    141162            # Get values of the measured quantity 
Note: See TracChangeset for help on using the changeset viewer.