Changeset 3581


Ignore:
Timestamp:
11/03/08 12:22:22 (11 years ago)
Author:
mkochan
Message:

Added tabular formatting to the csmlGrapher lister. Added testing of existence of CSML features per station -- this is neccessary at the moment, due to a "feature" in GeoServer?.

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

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/tests/testStation.py

    r3558 r3581  
    55 
    66# Get XML response from a GeoServer via HTTP 
    7 #!geoServerUrl = 'http://bond.badc.rl.ac.uk:8089/dummyGeoServer/GetStationCSMLFeatures?gml_id=MIDAS_Stations_with_features' 
    87geoServerUrl = 'http://130.246.76.98:8084/geoserver/wfs?request=getfeature&service=wfs&version=1.1.0&typename=np:Station&filter=%3Cogc:Filter%20xmlns:ogc=%22http://ogc.org%22%20xmlns:gml=%22http://www.opengis.net/gml%22%3E%3Cogc:BBOX%3E%3Cogc:PropertyName%3Enp:location%3C/ogc:PropertyName%3E%3Cgml:Box%20srsName=%22http://www.opengis.net/gml/srs/epsg.xml%22%3E%3Cgml:coordinates%3E-75,40%20-68,45%3C/gml:coordinates%3E%3C/gml:Box%3E%3C/ogc:BBOX%3E%3C/ogc:Filter%3E' 
    98geoServerResponse = wget(geoServerUrl) 
  • DPPP/kml/csml2kml/python/pylonsstack/pylonsstack/controllers/csmlGrapher.py

    r3576 r3581  
    2424#        . Add configurable URL for the data source web service (preferably explicitly on localhost) 
    2525class CsmlgrapherController(BaseController): 
     26 
     27    def _retrieveCsmlPointSeriesFeature(self, station_name, feature_id): 
     28        ''' 
     29        @return: A PointSeriesFeature object representing the single CSML feature. 
     30        @throws: A LookupError exception on retrieval error. 
     31        ''' 
     32 
     33        # The time boundaries are hard-coded now, i.e. we run the service for demonstration purposes. 
     34        lowerTimeBoundary = '1-JAN-2003' 
     35        upperTimeBoundary = '31-JAN-2003' 
     36 
     37        # Prepare the request for the GeoServer. 
     38        geoServerRequestUrl = urllib.quote('http://130.246.76.98:8084/geoserver/wfs?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>'+ lowerTimeBoundary +'</ogc:Literal></ogc:LowerBoundary><ogc:UpperBoundary><ogc:Literal>'+ upperTimeBoundary +'</ogc:Literal></ogc:UpperBoundary></ogc:PropertyIsBetween></ogc:And></ogc:Filter>', '/._:?&=') 
     39 
     40        # Acquire the GeoServer response and parse it into a CSMLFeatureCollection object 
     41        geoServerResponse = wget(geoServerRequestUrl) 
     42        if not geoServerResponse: 
     43            raise LookupError('Cannot acquire response from server (wrong URL or server down)') 
     44        csmlFeatureCollection = csml.parser.CSMLFeatureCollection() 
     45        csmlFeatureCollection.fromXML( XML(geoServerResponse) ) 
     46 
     47        # Now, csmlFeatureCollection should only contain a single CSML feature (if the feature was found). 
     48        # Isolate that CSML feature. 
     49        try: 
     50            csmlFeature = csmlFeatureCollection.featureMembers 
     51        except AttributeError: 
     52            raise LookupError('No PointSeriesFeature with ID "' + feature_id + '" found in the collection.') 
     53 
     54        # Make sure that the feature is a PointSeriesFeature 
     55        if not isinstance(csmlFeature, csml.parser.PointSeriesFeature): 
     56            raise TypeError('CSML feature not a PointSeriesFeature') 
     57        csmlPointSeriesFeature = csmlFeature 
     58 
     59        return csmlPointSeriesFeature 
    2660 
    2761    def plot(self): 
     
    121155            raise HTTPBadRequest('Parameters "feature_id" and "station_name" must be supplied.') 
    122156 
    123         # Prepare the request for the GeoServer 
    124         lowerTimeBoundary = '1-JAN-2003'   # hard-coded for now 
    125         upperTimeBoundary = '31-JAN-2003'  # hard-coded for now 
    126         geoServerRequestUrl = urllib.quote('http://130.246.76.98:8084/geoserver/wfs?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>'+ lowerTimeBoundary +'</ogc:Literal></ogc:LowerBoundary><ogc:UpperBoundary><ogc:Literal>'+ upperTimeBoundary +'</ogc:Literal></ogc:UpperBoundary></ogc:PropertyIsBetween></ogc:And></ogc:Filter>', '/._:?&=') 
    127  
    128         # Acquire the GeoServer response and parse it into a CSMLFeatureCollection object 
    129         geoServerResponse = wget(geoServerRequestUrl) 
    130         if not geoServerResponse: 
    131             raise LookupError('Cannot acquire response from server (wrong URL or server down)') 
    132         csmlFeatureCollection = csml.parser.CSMLFeatureCollection() 
    133         csmlFeatureCollection.fromXML( XML(geoServerResponse) ) 
    134  
    135         # Now, csmlFeatureCollection should only contain a single CSML feature (if the feature was found). 
    136         # Isolate that CSML feature. 
    137         try: 
    138             csmlFeature = csmlFeatureCollection.featureMembers 
    139         except AttributeError: 
    140             raise LookupError('No PointSeriesFeature with ID "' + feature_id + '" found in the collection.') 
    141  
    142         # Make sure that the feature is a PointSeriesFeature 
    143         if not isinstance(csmlFeature, csml.parser.PointSeriesFeature): 
    144             raise TypeError('CSML feature not a PointSeriesFeature') 
    145         csmlPointSeriesFeature = csmlFeature 
     157        # Retrieve the csmlPointSeriesFeature object 
     158        csmlPointSeriesFeature = self._retrieveCsmlPointSeriesFeature(station_name, feature_id) 
    146159 
    147160        # Try to plot the feature into a temporary file, and put the contents of that file into the response 
     
    164177            raise HTTPBadRequest('Parameter "station_name" must be supplied.') 
    165178 
    166         # Prepare the request for the GeoServer 
     179        # Prepare the request for the GeoServer -- to return a collection of np:Station, containing a single np:Station, 
     180        # which contains a list of CSML features. 
    167181        geoServerRequestUrl = urllib.quote('http://130.246.76.98:8084/geoserver/wfs?request=getFeature&service=wfs&version=1.1.0&typename=np:Station&filter=<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:PropertyIsEqualTo><ogc:PropertyName>stationName</ogc:PropertyName><ogc:Literal>' + station_name + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>', '/._:?&=') 
    168182 
     
    177191        wfsStation = wfsStationCollection.stations[0] 
    178192 
     193        # Generate HTML with a list of CSML features contained in the station. 
    179194        htmlElement = Element('html') 
    180195        SubElement(htmlElement, 'title').text = 'List of CSML features for station ' + station_name 
    181196        bodyElement = SubElement(htmlElement, 'body') 
     197        SubElement(htmlElement, 'h2').text = 'List of CSML features for station ' + station_name 
     198        tableElement = SubElement(htmlElement, 'table') 
     199        tableElement.set('border', '1') 
    182200        for csmlFeatureId in wfsStation.csmlFeatureIds: 
    183             anchorElement = SubElement(bodyElement, 'a') 
    184             linkToGrapher = 'http://bond.badc.rl.ac.uk:8089/csmlGrapher/plot?station_name=' + station_name + '&feature_id=' + csmlFeatureId 
    185             anchorElement.set('href', linkToGrapher) 
    186             anchorElement.text = csmlFeatureId 
    187             SubElement(bodyElement, 'br') 
     201            try: 
     202                # Test whether the feature exists. Remove this if such test is no more necessary. 
     203                self._retrieveCsmlPointSeriesFeature(station_name, csmlFeatureId) 
     204 
     205                # If no LookupError exception has been caught, proceed with inluding the feature in the list. 
     206                rowElement = SubElement(tableElement, 'tr') 
     207                dataElement = SubElement(rowElement, 'td') 
     208                anchorElement = SubElement(dataElement, 'a') 
     209                linkToGrapher = 'http://bond.badc.rl.ac.uk:8089/csmlGrapher/plot?station_name=' + station_name + '&feature_id=' + csmlFeatureId 
     210                anchorElement.set('href', linkToGrapher) 
     211                anchorElement.text = csmlFeatureId 
     212            except LookupError: 
     213                pass 
     214 
    188215        htmlStringIO = StringIO() 
    189216        ElementTree(htmlElement).write(htmlStringIO) 
     
    191218        response.content_type = 'text/html' 
    192219        response.content = htmlStringIO.getvalue() 
    193          
Note: See TracChangeset for help on using the changeset viewer.