Changeset 3558


Ignore:
Timestamp:
06/03/08 17:40:37 (11 years ago)
Author:
mkochan
Message:

Changing the grapher (unfinished).

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

Legend:

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

    r3439 r3558  
    77 
    88from cElementTree import XML 
     9 
     10npXmlNamespace = 'http://ndg.nerc.ac.uk/np' 
    911 
    1012class NPStation: 
     
    3436        self.csmlFeatureIds = [] 
    3537        for stationsFeatureElement in featuresElement.getchildren(): 
    36             (featureIdElement, featureTypeElement) = stationsFeatureElement.getchildren() 
    37             self.csmlFeatureIds.append(featureIdElement.text) 
     38            (featureTypeElement, featureParameterElement) = stationsFeatureElement.getchildren() 
     39            if featureTypeElement.text != 'csml:PointSeriesFeature': 
     40                raise TypeError('Feature type not "csml:PointSeriesFeature"') 
     41            self.csmlFeatureIds.append(featureParameterElement.text) 
    3842 
    3943    def __repr__(self): 
    40         return '<np:Station> %s ("%s") located at (%f, %f) with %d features.' % ( 
    41             self.id, self.desc, self.lon, self.lat, len(self.csmlFeatureIds) 
     44        return '<np:Station> %s ("%s") located at (%f, %f) with %d features (%s).' % ( 
     45            self.id, self.desc, self.lon, self.lat, len(self.csmlFeatureIds), str(self.csmlFeatureIds) 
    4246            ) 
    4347 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/StationConvertor.py

    r3439 r3558  
    5252        featuresHtml = '' 
    5353        for featureId in npStation.csmlFeatureIds: 
    54             featuresHtml = featuresHtml + '<img src="' + self.grapherUrl + '?feature_id=' + featureId + '"><br>' 
     54            featuresHtml = featuresHtml + '<img src="%s?station_name=%s&feature_id=%s"><br>' % (self.grapherUrl, npStation.desc, featureId) 
    5555        return KMLPlacemark(npStation.id, npStation.desc, npStation.lon, npStation.lat, featuresHtml, 
    5656                            styleID = self.placemarkKmlStyle.id, data = self.stationData 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/tests/testStation.py

    r3439 r3558  
    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' 
     7#!geoServerUrl = 'http://bond.badc.rl.ac.uk:8089/dummyGeoServer/GetStationCSMLFeatures?gml_id=MIDAS_Stations_with_features' 
     8geoServerUrl = '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' 
    89geoServerResponse = wget(geoServerUrl) 
    910 
  • DPPP/kml/csml2kml/python/pylonsstack/pylonsstack/controllers/csmlGrapher.py

    r3319 r3558  
    1414from tempfile import NamedTemporaryFile 
    1515from cElementTree import Element, ElementTree, XML 
     16from utils import wget 
    1617 
    1718log = logging.getLogger(__name__) 
     
    107108            response.content = buf.getvalue() 
    108109             
    109         def _wget(url): 
    110             '''Auxiliary function, returns data read from an URL''' 
    111             content = None 
    112             try: 
    113                 socket = urllib.urlopen(url)               # open a socket (actually a file-like object) 
    114                 content = socket.read()                    # read the text in 
    115             finally: 
    116                 try: 
    117                     socket.close() 
    118                 except NameError: 
    119                     pass  # socket undefined -- no need to close 
    120             return content 
    121  
    122110        #------------------------------------------------------------------------------------------------------------------- 
    123111 
    124         # Get feature ID from HTTP request 
    125         feature_id = None; station_id = None 
     112        # Get parameters from the request object 
    126113        try: 
    127114            feature_id = request.params['feature_id'] 
    128             gml_id = feature_id 
     115            station_name = request.params['station_name'] 
    129116        except KeyError: 
    130             try: 
    131                 station_id = request.params['station_id'] 
    132                 gml_id = station_id 
    133             except KeyError: 
    134                 raise HTTPBadRequest('exactly one of the parameters "feature_id" and "station_id" must be supplied.') 
     117            raise HTTPBadRequest('Parameters "feature_id" and "station_id" must be supplied.') 
    135118 
    136119        # Get response from GeoServer and parse it into an ElementTree 
    137         geoServerURL = 'http://bond.badc.rl.ac.uk:8089/dummyGeoServer/GetStationCSMLFeatures?gml_id=' + gml_id 
    138         geoSrResponse = _wget(geoServerURL) 
    139         tree = ElementTree(XML(geoSrResponse)) 
     120        lowerTimeBoundary = '1-JAN-2003'  # hard-coded for now 
     121        upperTimeBoundary = '1-FEB-2004'  # hard-coded for now 
     122        geoServerRequestUrl = 'http://130.246.76.98:8084/geoserver/wfs?request=getfeature&service=wfs&version=1.1.0&typename=%20csml:PointSeriesFeature&filter=%3Cogc:Filter%20xmlns:ogc=%22http://www.opengis.net/ogc%22%20xmlns:gml=%22http://www.opengis.net/gml%22%3E%3Cogc:And%3E%3Cogc:PropertyIsEqualTo%3E%3Cogc:PropertyName%3Egml:description%3C/ogc:PropertyName%3E%3Cogc:Literal%3E%s%3C/ogc:Literal%3E%3C/ogc:PropertyIsEqualTo%3E%3Cogc:PropertyIsEqualTo%3E%3Cogc:PropertyName%3Ecsml:parameter/swe:Phenomenon/gml:name%3C/ogc:PropertyName%3E%3Cogc:Literal%3E%s%3C/ogc:Literal%3E%3C/ogc:PropertyIsEqualTo%3E%3Cogc:PropertyIsBetween%3E%3Cogc:PropertyName%3Ecsml:value/csml:PointSeriesCoverage/csml:pointSeriesDomain/csml:TimeSeries/csml:timePositionList%3C/ogc:PropertyName%3E%3Cogc:LowerBoundary%3E%3Cogc:Literal%3E%s%3C/ogc:Literal%3E%3C/ogc:LowerBoundary%3E%3Cogc:UpperBoundary%3E%3Cogc:Literal%3E%s%3C/ogc:Literal%3E%3C/ogc:UpperBoundary%3E%3C/ogc:PropertyIsBetween%3E%3C/ogc:And%3E%3C/ogc:Filter%3E' % (station_name, feature_id, lowerTimeBoundary, upperTimeBoundary) 
     123        geoServerResponse = wget(geoServerRequestUrl) 
     124        tree = ElementTree(XML(geoServerResponse)) 
    140125 
     126        # [TODO] Split this code into two separate service calls -- one for listing features per station 
     127        #        and another the actual grapher. 
    141128        if station_id: 
    142129 
Note: See TracChangeset for help on using the changeset viewer.