source: TI02-CSML/trunk/parser/csmldoc.py @ 953

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/parser/csmldoc.py@953
Revision 953, 3.7 KB checked in by domlowe, 13 years ago (diff)

Alterations to testMethods

Line 
1'''csmldoc.py
2Contains Parser high level  api to enable reading of csml document/features etc
3Note - All class names are prefixed with 'CSML' to avoid conflict with Parser classes
4of similar names.
5'''
6
7from Parser import * #import parser into same namespace
8import parser_extra
9
10class CSMLDataset:
11    def __init__(self,csmlfile):
12        #must be provided with csmlfile
13        #parse the csmlfile into self.dataset
14        self.dataset=Dataset()
15        tree = ElementTree(file=csmlfile)
16        self.dataset.fromXML(tree.getroot())
17        self.dataset =parser_extra.ParserPostProcessor(self.dataset).resolveReferences()
18   
19    #other Dataset methods go here:
20    ############
21    #def getFeaturelist:
22    #def getArrayDescriptors
23    #etc...
24
25    def getFeature(self, featureID):
26        #returns a single feature object, which can be accessed by both the high-level api and the Parser API
27        for member in self.dataset.featureCollection.members:
28                if member.id == featureID:
29                    if  isinstance(member,PointFeature):
30                        return CSMLPointFeature(member)
31                    elif isinstance(member,PointSeriesFeature):
32                        return CSMLPointSeriesFeature(member)
33                    elif  isinstance(member,ProfileFeature):
34                        return CSMLProfileFeature(member)
35                    #elif etc... for all feature types
36
37class CSMLAbstractFeature: 
38        """Contains methods applicable to any feature but methods can be overwritten by individual feature types
39         - see testMethod for example.
40        """
41        def __init__(self,feature):
42            self.parsedFeature=feature
43            '''sets self.parsedFeature to contain the lower level parsed feature'''
44           
45            '''testMethod is the 'default' abstract testMethod - it will be overwritten by subclasses i.e. by specific features'''
46        def testMethod(self):
47            #default "testMethod" for all features
48            print 'underlying feature type:' + str(self.parsedFeature)
49            return 'abstract test method called and not overwritten'
50        def getOutputOptions(self):
51            #return generic output options for abstract features - this may in fact be none... and will be always overwritten within specific feature types
52            pass
53
54class CSMLPointFeature(CSMLAbstractFeature):
55    def __init__(self,feature):
56        CSMLAbstractFeature.__init__(self,feature)
57    def getOutputOptions(self):
58            #return output options for Point feature... not implemented
59        pass
60    def testMethod(self):
61        """Over writes abstract testMethod"""
62        print 'underlying feature type:' + str(self.parsedFeature)
63        return 'abstract test method overwritten by CSMLPointFeature class'
64
65class CSMLPointSeriesFeature(CSMLAbstractFeature):
66    def __init__(self,feature):
67        CSMLAbstractFeature.__init__(self,feature)
68    def getOutputOptions(self):
69            #return output options for PointSeries feature... not implemented
70        pass
71    def testMethod(self):
72        """Over writes abstract testMethod"""
73        print 'underlying feature type:' + str(self.parsedFeature)
74        return 'abstract test method overwritten by CSMLPointSeriesFeature class'
75   
76   
77class CSMLProfileFeature(CSMLAbstractFeature):
78    def __init__(self,feature):
79        CSMLAbstractFeature.__init__(self,feature)
80    def getOutputOptions(self):
81            #return output options for ProfileSeries feature... not implemented
82        pass
83    '''NOTE:this feature does not have a "testMethod" so default abstract testMethod is used from CSMLAbstractFeature'''
84    #def testMethod(self):
85    #   pass
86   
87   
88# etc.. do same for all features
Note: See TracBrowser for help on using the repository browser.