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

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

Basic structure of high-level CSML API added

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    #Dataset methods:
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 features
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           
47        def testMethod(self):
48            #default "testMethod" for all features
49            print 'underlying feature type:' + str(self.parsedFeature)
50            return 'abstract test method called and not overwritten'
51        def getOutputOptions(self):
52            #return generic output options for 'all' features - this may in fact be none...?
53            pass
54
55class CSMLPointFeature(CSMLAbstractFeature):
56    def __init__(self,feature):
57        CSMLAbstractFeature.__init__(self,feature)
58    def getOutputOptions(self):
59            #return output options for Point feature...
60        pass
61    def testMethod(self):
62        """Over writes abstract testMethod"""
63        print 'underlying feature type:' + str(self.parsedFeature)
64        return 'abstract test method overwritten by CSMLPointFeature class'
65
66class CSMLPointSeriesFeature(CSMLAbstractFeature):
67    def __init__(self,feature):
68        CSMLAbstractFeature.__init__(self,feature)
69    def getOutputOptions(self):
70            #return output options for PointSeries feature...
71        pass
72    def testMethod(self):
73        """Over writes abstract testMethod"""
74        print 'underlying feature type:' + str(self.parsedFeature)
75        return 'abstract test method overwritten by CSMLPointSeriesFeature class'
76   
77   
78class CSMLProfileFeature(CSMLAbstractFeature):
79    def __init__(self,feature):
80        CSMLAbstractFeature.__init__(self,feature)
81    def getOutputOptions(self):
82            #return output options for ProfileSeries feature...
83        pass
84    '''NOTE:this feature does not have a "testMethod" so default abstract testMethod is used'''
85   
86   
87   
88# etc.. do same for all features
Note: See TracBrowser for help on using the repository browser.