1 | ''' csmlfeaturewrap.py - wrapper functions for creating features''' |
---|
2 | |
---|
3 | import csml.parser |
---|
4 | import csml.parser_extra |
---|
5 | |
---|
6 | class 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 createProfileSeriesFeature(self,value, parameter=None,featureID=None,description=None): |
---|
51 | feat=csml.parser.ProfileSeriesFeature() |
---|
52 | if featureID: |
---|
53 | feat.id= featureID |
---|
54 | else: |
---|
55 | feat.id='No ID' |
---|
56 | if description: |
---|
57 | feat.description=description |
---|
58 | else: |
---|
59 | feat.description='No Description' |
---|
60 | feat.value=value |
---|
61 | #feat.parameter=parameter |
---|
62 | return feat |
---|
63 | |
---|
64 | def createGridSeriesFeature(self,value, parameter=None,featureID=None,description=None): |
---|
65 | feat=csml.parser.GridSeriesFeature() |
---|
66 | if featureID: |
---|
67 | feat.id= featureID |
---|
68 | else: |
---|
69 | feat.id='No ID' |
---|
70 | if description: |
---|
71 | feat.description=description |
---|
72 | else: |
---|
73 | feat.description='No Description' |
---|
74 | feat.value=value |
---|
75 | #feat.parameter=parameter |
---|
76 | return feat |
---|
77 | |
---|
78 | def addTrajectoryFeature(self): |
---|
79 | pass |
---|
80 | |
---|
81 | def createFileExtract(self,extractType, id, variableName=None,arraySize=None,fileName=None): |
---|
82 | #handles the addition of file extract classes (can probably get away with one method for all types of extracts for now) |
---|
83 | if extractType=='NetCDFExtract': |
---|
84 | ex=csml.parser.NetCDFExtract() |
---|
85 | if extractType=='NASAAmesExtract': |
---|
86 | ex=csml.parser.NASAAmesExtract() |
---|
87 | if extractType=='GRIBExtract': |
---|
88 | ex=csml.parser.GRIBExtract() |
---|
89 | if extractType=='PPExtract': |
---|
90 | ex=csml.parser.PPExtract() |
---|
91 | ex.id =id |
---|
92 | if arraySize: |
---|
93 | ex.arraySize=[arraySize] |
---|
94 | if fileName: |
---|
95 | ex.fileName=fileName |
---|
96 | if variableName: |
---|
97 | ex.variableName=variableName |
---|
98 | return ex |
---|
99 | |
---|
100 | |
---|
101 | def setBoundingEnvelope(self,lowerCorner,upperCorner,timePosition1,timePosition2): |
---|
102 | #set the bounding box envelope of the feature collection. |
---|
103 | # put this in container? |
---|
104 | etp = csml.parser.EnvelopeWithTimePeriod() |
---|
105 | etp.lowerCorner=lowerCorner |
---|
106 | etp.upperCorner=upperCorner |
---|
107 | etp.timePosition=timePosition1 |
---|
108 | etp.timePosition2=timePosition2 |
---|
109 | self.fc.boundedBy=etp |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | def consolidate(self): |
---|
114 | #when you have finished building the document, need to consolidate it and return a CSML document (string) |
---|
115 | self.ds.arrayDescriptors=self.ad |
---|
116 | self.ds.featureCollection=csml.parser.FeatureCollection(members=self.fm) |
---|
117 | csmlout=self.ds.toXML() |
---|
118 | #parse and pretty print the result |
---|
119 | strCSML=csml.parser_extra.PrettyPrint(csmlout) |
---|
120 | strCSML=csml.parser_extra.removeInlineNS(strCSML) |
---|
121 | return strCSML |
---|