source: TI02-CSML/trunk/csml/csmllibs/csmlfeaturewrap.py @ 2105

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

Parser changes -  csml:id for Dataset, TimeSeriesDomain? to TimeSeries?, plus fixing description/id in subsetting code

Line 
1''' csmlfeaturewrap.py - wrapper functions for creating features'''
2
3import csml.parser
4import csml.parser_extra
5
6class CSMLWrapper(object):
7    def __init__(self):
8        pass
9   
10    def addPointFeature(self, id, description,domainReference,rangeSet, parameter):
11        #TO DO- this needs revising in line with addGridSeriesFeature
12        """ addPointFeature
13        domainReference = Position type
14        rangeSet = quantityList type,
15        parameter = Phenomenon type
16        """
17        feat=csml.parser.PointFeature()
18        feat.id=id
19        feat.description=csml.parser.Description(description)
20       
21        #Add the domain to the feature
22        p=csml.parser.Position()
23        p.srsName =domainReference[0]
24        p.axisLabels=domainReference[1]
25        p.uomLabels = domainReference[2]
26        p.location=domainReference[3]
27        p.time=domainReference[4]
28        ptd=csml.parser.PointDomain()
29        ptd.domainReference=p
30        feat.domain=ptd
31       
32        #Add the rangeSet to the feature
33        rs=csml.parser.RangeSet()
34        rs.quantityList=csml.parser.MeasureOrNullList(uom=rangeSet[0],val = rangeSet[1])
35        feat.rangeSet=rs
36       
37        #Add the parameter to the feature
38        feat.parameter=csml.parser.Phenomenon(href=parameter) 
39       
40        self.fm.append(feat)
41    def addProfileFeature(self):
42        pass
43
44    def addGridFeature(self):
45        pass
46           
47    def addPointSeriesFeature(self):
48        pass
49           
50    def addProfileSeriesFeature(self):
51        pass
52
53    def createGridSeriesFeature(self,value, parameter=None,featureID=None,description=None):
54        feat=csml.parser.GridSeriesFeature()
55        if featureID:
56            feat.id= featureID
57        else:
58            feat.id='No ID'
59        if description:
60            feat.description=description
61        else:
62            feat.description='No Description'
63        feat.value=value
64        #feat.parameter=parameter
65        return feat
66                       
67    def addTrajectoryFeature(self):
68        pass
69
70    def createFileExtract(self,extractType, id, variableName=None,arraySize=None,fileName=None):
71        #handles the addition of file extract classes (can probably get away with one method for all types of extracts for now)
72        if extractType=='NetCDFExtract':
73            ex=csml.parser.NetCDFExtract()
74        if extractType=='NASAAmesExtract':
75            ex=csml.parser.NASAAmesExtract() 
76        if extractType=='GRIBExtract':
77            ex=csml.parser.GRIBExtract() 
78        if extractType=='PPExtract':
79            ex=csml.parser.PPExtract() 
80        ex.id =id
81        if arraySize:
82            ex.arraySize=[arraySize]
83        if fileName:
84            ex.fileName=fileName
85        if variableName:
86            ex.variableName=variableName
87        return ex
88
89   
90    def setBoundingEnvelope(self,lowerCorner,upperCorner,timePosition1,timePosition2):
91        #set the bounding box envelope of the feature collection.
92        # put this in container?
93        etp = csml.parser.EnvelopeWithTimePeriod()
94        etp.lowerCorner=lowerCorner
95        etp.upperCorner=upperCorner
96        etp.timePosition=timePosition1
97        etp.timePosition2=timePosition2
98        self.fc.boundedBy=etp
99
100       
101       
102    def consolidate(self):
103        #when you have finished building the document, need to consolidate it and return a CSML document (string)
104        self.ds.arrayDescriptors=self.ad
105        self.ds.featureCollection=csml.parser.FeatureCollection(members=self.fm)
106        csmlout=self.ds.toXML()
107        #parse and pretty print the result
108        strCSML=csml.parser_extra.PrettyPrint(csmlout)
109        strCSML=csml.parser_extra.removeInlineNS(strCSML)
110        return strCSML
Note: See TracBrowser for help on using the repository browser.