Changeset 3281


Ignore:
Timestamp:
28/01/08 17:00:25 (12 years ago)
Author:
mkochan
Message:

Modified csmlGrapher do read in a single PointSeries? feature only from GeoServer?. Also allows reading station XML, but this is only kept until it is decided whether it has a place in the framework.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/pylonsstack/pylonsstack/controllers/csmlGrapher.py

    r3278 r3281  
    2525    def plot(self): 
    2626        ''' 
    27         Handler for plotting a specific PointSeries feature (feature_id) of a specific station (station_id). 
     27        Handler for plotting a specific PointSeries feature given by URL parameter "feature_id". 
    2828        Retrieves the data from a web service, which should preferably run on the same machine.  
    2929 
    30         Request parameters:    station_id    Unique identifier of a requested station. 
     30        Request parameters:    EITHER "feature_id" OR "station_id" 
     31        where: 
    3132                               feature_id    Unique identifier of a requested CSML PointSeries feature. 
    32                   
    33         Response:              MIME-type: image/png; graph of the time series for the CSML PointSeries feature 
     33                               station_id    Unique identifier of a requested station. 
     34 
     35        Response:              If feature_id is supplied, an image/png of the time series for the CSML PointSeries feature; 
     36                               if station_id is supplied, nothing. 
    3437        ''' 
    3538        def _plot_feature(feature): 
     
    9497             
    9598        def wget(url): 
    96             socket = None 
    9799            content = None 
    98100            try: 
     
    100102                content = socket.read()                    # read the text in 
    101103            finally: 
    102                 if socket:  
     104                try: 
    103105                    socket.close() 
     106                except NameError: 
     107                    pass  # socket undefined -- no need to close 
    104108            return content 
    105109 
    106110        #------------------------------------------------------------------------------------------------------------------- 
    107111 
    108         feature_id = request.params['feature_id']              # get feature ID from HTTP request 
     112        # get feature ID from HTTP request 
     113        feature_id = None; station_id = None 
     114        try: 
     115            feature_id = request.params['feature_id'] 
     116            gml_id = feature_id 
     117        except KeyError: 
     118            try: 
     119                station_id = request.params['station_id'] 
     120                gml_id = station_id 
     121            except KeyError: 
     122                raise HTTPBadRequest('exactly one of the parameters "feature_id" and "station_id" must be supplied.') 
    109123 
    110         station_id = 'NA' 
    111         geoServerURL = 'http://bond.badc.rl.ac.uk:8089/dummyGeoServer/GetStationCSMLFeatures?station_id=' + station_id 
    112         geoSrResponse = wget(geoServerURL)                     # get response from GeoServer 
     124        # Get response from GeoServer and parse it into an ElementTree 
     125        geoServerURL = 'http://bond.badc.rl.ac.uk:8089/dummyGeoServer/GetStationCSMLFeatures?gml_id=' + gml_id 
     126        geoSrResponse = wget(geoServerURL) 
     127        tree = ElementTree(XML(geoSrResponse)) 
    113128 
    114         tree = ElementTree(XML(geoSrResponse))                 # parse in the feature collection 
    115         fc = csml.parser.CSMLFeatureCollection() 
    116         fc.fromXML(tree.getroot())         
    117         if not fc: 
    118             exit() 
     129        if station_id: 
    119130 
    120         feature = None                                         # find the requested feature 
    121         for any_feature in fc.featureMembers: 
    122             if any_feature.id == feature_id: 
    123                 feature = any_feature 
    124                 break 
    125         if feature: 
     131            # --- [NOTE] Keeping until ruled as obsolete --- 
     132 
     133            # Parse in the feature collection 
     134            fc = csml.parser.CSMLFeatureCollection() 
     135            fc.fromXML(tree.getroot()) 
     136 
     137        else: 
     138             
     139            # Parse in the feature directly 
     140            feature = csml.parser.PointSeriesFeature() 
     141            feature.fromXML(tree.getroot()) 
     142 
     143        if not feature: 
     144            raise HTTPNotFound('Feature not found') 
     145             
     146        try: 
     147            tempFile = _plot_feature(feature)              # plot the feature into a temporary file 
     148            _set_response(tempFile)                        # set WSGI response as an image containing the plot 
     149        finally: 
    126150            try: 
    127                 tempFile = _plot_feature(feature)              # plot the feature into a temporary file 
    128                 _set_response(tempFile)                        # set WSGI response as an image containing the plot 
    129             finally: 
    130                 try: 
    131                     tempFile.close() 
    132                 except NameError: 
    133                     pass  # tempFile undefined -- no need to close 
    134         else: 
    135             raise HTTPNotFound('Feature not found') 
     151                tempFile.close() 
     152            except NameError: 
     153                pass  # tempFile undefined -- no need to close 
Note: See TracChangeset for help on using the changeset viewer.