Changeset 3614


Ignore:
Timestamp:
14/03/08 17:33:41 (11 years ago)
Author:
mkochan
Message:

Added NPStationFeature class into Station.py. Removed dependency on the standard "datetime" module from StationConvertor?.py.

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

Legend:

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

    r3612 r3614  
    44 
    55from cElementTree import XML 
     6from pylab import dates     # a very good date/time module from matplotviz -- allows years < 1970 
    67 
    78npXmlNamespace = 'http://ndg.nerc.ac.uk/np'  # the namespace in which the Station element is defined 
     
    1112    Represents a ground meteorological station, identified by C{id}, with description C{desc}, 
    1213    located at (C{lon},C{lat}), and containing CSML features with identifiers C{csmlFeatureIds}. 
     14    @ivar id: Station identifier (e.g. "midas.station.1") 
     15    @type id: str 
     16    @ivar desc: Station description (e.g. "FAIR ISLE") 
     17    @type desc: str 
     18    @ivar lon: Station longitude 
     19    @type lon: float 
     20    @ivar lat: Station latitude 
     21    @type lat: float 
     22    @type features: C{NPStationFeature} list 
     23 
    1324    ''' 
    1425 
    15     def __init__(self, id = None, desc = None, lon = None, lat = None, csmlFeatureIds = None): 
     26    def __init__(self, id = None, desc = None, lon = None, lat = None, features = None): 
    1627        ''' 
    17         The initialiser. It is recommended not to pass any optional value (i.e. use only C{NPStation()}) 
    18         and later call C{parseString} or C{parseXML}. 
    19         @param id: Station identifier (e.g. "midas.station.1") 
    20         @type id: str 
    21         @param desc: Station description (e.g. "FAIR ISLE") 
    22         @type desc: str 
    23         @type lon: float 
    24         @type lat: float 
    25         @type csmlFeatureIds: str list 
     28        The initialiser (use empty call C{NPStation()} and later call the C{parseString} or C{parseXML} method). 
    2629        ''' 
    2730        self.id = id 
     
    6568            ) 
    6669 
     70class NPStationFeature: 
     71    ''' 
     72    Represents a I{<np:StationFeature>} element. 
     73    @ivar featureId: Unique ID of the feature 
     74    @type featureId: C{str} 
     75    @ivar collectBeginDate: Data when feature collection started. 
     76    @type collectBeginDate: C{pylab.dates.datetime.datetime} 
     77    @ivar collectEndDate: Data when feature collection started. 
     78    @type collectEndDate: C{pylab.dates.datetime.datetime} 
     79    ''' 
     80 
     81    def __init__(self, featureId = None, featureType = None, collectBeginDate = None, collectEndDate = None): 
     82        ''' 
     83        The initialiser (use empty call C{NPStationFeature()} and later call the C{parseXML} method). 
     84        ''' 
     85        self.featureId = featureId 
     86        self.featureType = featureType 
     87        self.collectBeginDate = collectBeginDate 
     88        self.collectEndDate = collectEndDate 
     89 
     90    def parseXML(self, stationFeatureElement): 
     91        ''' 
     92        Parse in the station directly from an C{cElementTree.Element} object. 
     93        @param stationFeatureElement: An element containing a station feature in XML form. 
     94        @type stationElement: C{cElementTree.Element} 
     95        ''' 
     96        (featureTypeElement, featureIdElement,  
     97         collectBeginDateElement, collectEndDateElement) = stationFeatureElement.getchildren() 
     98        if featureTypeElement != 'csml:PointSeriesFeature': 
     99            raise NotImplementedError('No other than "csml:PointSeriesFeature" feature type is supported') 
     100        self.featureID = featureIdElement.text 
     101        self.collectBeginDate = dates.dateutil.parser.parse(collectBeginDateElement.text) 
     102        self.collectEndDate = dates.dateutil.parser.parse(collectEndDateElement.text) 
     103 
    67104class WFSStationCollection: 
    68105    ''' 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/StationConvertor.py

    r3612 r3614  
    55from cElementTree import ElementTree, Element, SubElement, XML 
    66from pylab import * 
    7 from datetime import datetime, timedelta 
    87import re 
    98import csml 
Note: See TracChangeset for help on using the changeset viewer.