1 | import cElementTree as ET |
---|
2 | import elementtree.ElementTree as etree |
---|
3 | import parser_extra |
---|
4 | import sys |
---|
5 | '''CSML v2 Parser ''' |
---|
6 | |
---|
7 | #this map needs updating for V2 |
---|
8 | etree._namespace_map.update({'http://www.opengis.net/om': 'om', 'http://www.opengis.net/swe': 'swe', 'http://www.opengis.net/gml': 'gml','http://ndg.nerc.ac.uk/csml' : 'csml', 'http://www.w3.org/1999/xlink':'xlink'}) |
---|
9 | |
---|
10 | nsCSML = 'http://ndg.nerc.ac.uk/csml' |
---|
11 | nsGML = 'http://www.opengis.net/gml' |
---|
12 | nsOM = 'http://www.opengis.net/om' |
---|
13 | nsXLINK = 'http://www.w3.org/1999/xlink' |
---|
14 | nsXML = 'http://ndg.nerc.ac.uk/csml' |
---|
15 | nsMOLES='http://ndg.nerc.ac.uk/moles' |
---|
16 | nsSWE='http://www.opengis.net/swe' |
---|
17 | |
---|
18 | def myQName(uri,tag): |
---|
19 | return "{"+uri+"}"+tag |
---|
20 | |
---|
21 | def CSML(tag): |
---|
22 | return myQName(nsCSML,tag) |
---|
23 | |
---|
24 | def GML(tag): |
---|
25 | return myQName(nsGML,tag) |
---|
26 | |
---|
27 | def SWE(tag): |
---|
28 | return myQName(nsSWE,tag) |
---|
29 | |
---|
30 | def XLINK(tag): |
---|
31 | return myQName(nsXLINK,tag) |
---|
32 | |
---|
33 | def addchildren(obj, dict): |
---|
34 | ''' merges (adds) dictionary to existing self.CHILDREN dictionary ''' |
---|
35 | dict1 = dict |
---|
36 | if hasattr(obj, 'CHILDREN'): |
---|
37 | dict2=obj.CHILDREN |
---|
38 | else: |
---|
39 | dict2={} |
---|
40 | dict3={} |
---|
41 | for item in dict1: |
---|
42 | dict3[item] =dict1[item] |
---|
43 | for item in dict2: |
---|
44 | dict3[item] =dict2[item] |
---|
45 | obj.CHILDREN=dict3 |
---|
46 | |
---|
47 | |
---|
48 | def addatts(obj, atts): |
---|
49 | ''' merges self.ATTRIBUTES''' |
---|
50 | if hasattr(obj, 'ATTRIBUTES'): |
---|
51 | for att in atts: |
---|
52 | obj.ATTRIBUTES.append(att) |
---|
53 | else: |
---|
54 | obj.ATTRIBUTES=atts |
---|
55 | |
---|
56 | |
---|
57 | #Some variable definitions: these things are often repeated so store in variables. |
---|
58 | FILEFORMATS=[CSML('NetCDFExtract'),CSML('NASAAmesExtract'), CSML('GRIBExtract'),CSML('CDMLExtract'), CSML('RawFileExtract')] |
---|
59 | |
---|
60 | |
---|
61 | class csElement(object): |
---|
62 | ''' main csElement class - all other elements inherit from this baseclass |
---|
63 | all the from/to XML conversion is done by this class''' |
---|
64 | |
---|
65 | def __init__(self, **kwargs): |
---|
66 | if not hasattr(self, 'ATTRIBUTES'): |
---|
67 | self.ATTRIBUTES=[] |
---|
68 | |
---|
69 | |
---|
70 | def __removeURI(self, qname): |
---|
71 | try: |
---|
72 | attname = qname.split('}')[1] |
---|
73 | except IndexError: |
---|
74 | attname = qname |
---|
75 | return attname |
---|
76 | |
---|
77 | def _getSubstitutionType(self,tag): |
---|
78 | print 'splitting tag' |
---|
79 | return tag.split('}')[1] |
---|
80 | |
---|
81 | |
---|
82 | def _getReverseSubsType(self, typename): |
---|
83 | return typename |
---|
84 | |
---|
85 | def toXML(self, csmlfrag): |
---|
86 | #process self and convert to XML |
---|
87 | if hasattr(self, 'CONTENT'): |
---|
88 | if self.CONTENT is not None: csmlfrag.text=self.CONTENT |
---|
89 | if hasattr(self, 'ATTRIBUTES'): |
---|
90 | for item in self.__dict__: |
---|
91 | if item in self.ATTRIBUTES: |
---|
92 | csmlfrag.set(item, self.__dict__[item]) |
---|
93 | for item in self.__dict__: |
---|
94 | if GML(item) in self.ATTRIBUTES: |
---|
95 | csmlfrag.set(GML(item), self.__dict__[item]) |
---|
96 | # self.CHILDREN (recursive - calls the toXML method of children |
---|
97 | for att in self.__dict__: |
---|
98 | if att not in ['ATTRIBUTES', 'CHILDREN', 'CONTENT']: |
---|
99 | for child in self.CHILDREN: |
---|
100 | if child == att: |
---|
101 | parserobjects=[] |
---|
102 | if type(self.__dict__[att]) is list: |
---|
103 | for a in self.__dict__[att]: |
---|
104 | parserobjects.append(a) |
---|
105 | else: |
---|
106 | parserobjects.append(self.__dict__[att]) |
---|
107 | parentfrag=None |
---|
108 | if len(self.CHILDREN[child])>=3: |
---|
109 | ename2=self.CHILDREN[child][2] |
---|
110 | parentfrag=ET.Element(ename2) |
---|
111 | for po in parserobjects: |
---|
112 | if type(self.CHILDREN[child][0]) is not list: |
---|
113 | ename=self.CHILDREN[child][0] |
---|
114 | else: |
---|
115 | ename = self._getReverseSubsType(type(po).__name__) |
---|
116 | if len(self.CHILDREN[child])==3: |
---|
117 | frag=ET.Element(ename) |
---|
118 | po.toXML(frag) |
---|
119 | parentfrag.append(frag) |
---|
120 | appendLater=True |
---|
121 | elif len(self.CHILDREN[child])>=4: |
---|
122 | if self.CHILDREN[child][3]==1: |
---|
123 | frag=ET.Element(ename) |
---|
124 | po.toXML(frag) |
---|
125 | parentfrag.append(frag) |
---|
126 | csmlfrag.append(parentfrag) |
---|
127 | parentfrag=ET.Element(parentfrag.tag) |
---|
128 | appendLater=False |
---|
129 | else: |
---|
130 | frag=ET.Element(ename) |
---|
131 | po.toXML(frag) |
---|
132 | csmlfrag.append(frag) |
---|
133 | appendLater=True |
---|
134 | if appendLater==True and parentfrag != None: |
---|
135 | csmlfrag.append(parentfrag) |
---|
136 | return csmlfrag |
---|
137 | |
---|
138 | def fromXML(self,csmlfrag): |
---|
139 | # deal with attributes, e.g. gml id's |
---|
140 | if csmlfrag.text is not None: |
---|
141 | self.CONTENT = csmlfrag.text |
---|
142 | for item in csmlfrag.items(): |
---|
143 | if item[0] in self.ATTRIBUTES: |
---|
144 | setattr(self, item[0], item[1]) |
---|
145 | # self.CHILDREN (recursive - calls the fromXML method of children |
---|
146 | for frag in csmlfrag[:]: |
---|
147 | #for each child element |
---|
148 | #iterate through expected CHILDREN |
---|
149 | for child in self.CHILDREN: |
---|
150 | #get element name |
---|
151 | if len(self.CHILDREN[child])>=3: |
---|
152 | ename = self.CHILDREN[child][2] |
---|
153 | ename2 = self.CHILDREN[child][0] |
---|
154 | |
---|
155 | else: |
---|
156 | ename = self.CHILDREN[child][0] |
---|
157 | ename2=None |
---|
158 | #if there are options, then find the name that matches the frag |
---|
159 | if ename2 is not None: |
---|
160 | if frag[:] != []: |
---|
161 | for subfrag in frag[:]: |
---|
162 | etype=None |
---|
163 | if type(ename2) is list: |
---|
164 | if subfrag.tag in ename2: |
---|
165 | etype=self._getSubstitutionType(subfrag.tag) |
---|
166 | if subfrag.tag==ename2: |
---|
167 | etype=self.CHILDREN[child][1] |
---|
168 | if etype: |
---|
169 | childobj=eval(etype)() |
---|
170 | if len(self.CHILDREN[child])>=3: |
---|
171 | if frag[:] != []: |
---|
172 | childobj.fromXML(subfrag) |
---|
173 | else: |
---|
174 | childobj.fromXML(frag) |
---|
175 | #set this object to be an attribute of the 'parent' (self) object |
---|
176 | if hasattr(self, child): |
---|
177 | if type(self.__dict__[child]) is not list: |
---|
178 | tmp=self.__dict__[child] |
---|
179 | setattr(self, child, [tmp]) #convert to list |
---|
180 | self.__dict__[child].append(childobj) |
---|
181 | else: |
---|
182 | setattr(self, child, childobj) |
---|
183 | else: |
---|
184 | etype=None |
---|
185 | if type(ename) is list: |
---|
186 | if frag.tag in ename: |
---|
187 | etype=self._getSubstitutionType(frag.tag) |
---|
188 | elif frag.tag==ename: |
---|
189 | etype=self.CHILDREN[child][1] |
---|
190 | if etype: |
---|
191 | childobj=eval(etype)() |
---|
192 | if len(self.CHILDREN[child])>=3: |
---|
193 | if frag[:] != []: |
---|
194 | childobj.fromXML(frag[0]) |
---|
195 | else: |
---|
196 | childobj.fromXML(frag) |
---|
197 | #set this object to be an attribute of the 'parent' (self) object |
---|
198 | if hasattr(self, child): |
---|
199 | if type(self.__dict__[child]) is not list: |
---|
200 | tmp=self.__dict__[child] |
---|
201 | setattr(self, child, [tmp]) #convert to list |
---|
202 | self.__dict__[child].append(childobj) |
---|
203 | else: |
---|
204 | setattr(self, child, childobj) |
---|
205 | |
---|
206 | |
---|
207 | class csString(csElement): |
---|
208 | def __init__(self, **kwargs): |
---|
209 | children={} |
---|
210 | addchildren(self,children) |
---|
211 | |
---|
212 | class AbstractGML(csElement): |
---|
213 | def __init__(self, **kwargs): |
---|
214 | a=[GML('id'), GML('description'), GML('name'), GML('MetaDataProperty')] |
---|
215 | addatts(self,a) |
---|
216 | |
---|
217 | class AssociationAttributeGroup(csElement): |
---|
218 | def __init__(self, **kwargs): |
---|
219 | a =[XLINK('href'),XLINK('role'), XLINK('arcrole'),XLINK('title'), XLINK('show'), XLINK('actuate')] |
---|
220 | addatts(self,a) |
---|
221 | |
---|
222 | class SRSReferenceGroup(csElement): |
---|
223 | def __init__(self, **kwargs): |
---|
224 | a =['srsName','srsDimension'] |
---|
225 | addatts(self,a) |
---|
226 | |
---|
227 | class SRSInformationGroup(csElement): |
---|
228 | def __init__(self, **kwargs): |
---|
229 | a =['uomLabels','axisLabels'] |
---|
230 | addatts(self,a) |
---|
231 | |
---|
232 | class ArrayDescriptor(AbstractGML, csElement): |
---|
233 | def __init__(self,**kwargs): |
---|
234 | AbstractGML.__init__(self,**kwargs) |
---|
235 | children={'arraySize':[CSML('arraySize'), 'csString'], 'uom':[CSML('uom'),'csString'], 'numericType':[CSML('numericType'),'csString'], 'regExpTransform':[CSML('regExpTransform'),'csString'], 'numericTransform':[CSML('numericTransform'),'csString']} |
---|
236 | addchildren(self,children) |
---|
237 | |
---|
238 | class DirectPosition(AbstractGML, SRSReferenceGroup,SRSInformationGroup,csElement): |
---|
239 | def __init__(self, **kwargs): |
---|
240 | AbstractGML.__init__(self,**kwargs) |
---|
241 | |
---|
242 | |
---|
243 | class Envelope(AbstractGML,SRSReferenceGroup, csElement): |
---|
244 | def __init__(self, **kwargs): |
---|
245 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
246 | AbstractGML.__init__(self,**kwargs) |
---|
247 | children={'lowerCorner':[GML('lowerCorner'), 'DirectPosition'],'upperCorner':[GML('upperCorner'), 'DirectPosition']} |
---|
248 | addchildren(self,children) |
---|
249 | |
---|
250 | |
---|
251 | class AbstractFeature(AbstractGML,csElement): |
---|
252 | def __init__(self, **kwargs): |
---|
253 | AbstractGML.__init__(self,**kwargs) |
---|
254 | children={'boundedBy':[GML('boundedBy'), 'Envelope']} |
---|
255 | addchildren(self,children) |
---|
256 | |
---|
257 | class AbstractFeatureCollection(AbstractFeature,csElement): |
---|
258 | def __init__(self, **kwargs): |
---|
259 | AbstractFeature.__init__(self,**kwargs) |
---|
260 | |
---|
261 | class DomainSet(AbstractGML,AssociationAttributeGroup,csElement): |
---|
262 | def __init__(self, **kwargs): |
---|
263 | AbstractGML.__init__(self,**kwargs) |
---|
264 | addchildren(self,{}) |
---|
265 | |
---|
266 | class AggregatedArray(ArrayDescriptor,csElement): |
---|
267 | def __init__(self, **kwargs): |
---|
268 | ArrayDescriptor.__init__(self,**kwargs) |
---|
269 | children={'aggType':[CSML('aggType'),'csString'], 'aggIndex':[CSML('aggIndex'),'csString'],'components':[FILEFORMATS, 'ArrayDescriptor',CSML('component')]} |
---|
270 | addchildren(self,children) |
---|
271 | #'component':[CSML:('component'), 'ArrayDescriptor', CSML('component')], |
---|
272 | class MeasureOrNullList(AbstractGML,csElement): |
---|
273 | def __init__(self, **kwargs): |
---|
274 | AbstractGML.__init__(self,**kwargs) |
---|
275 | children={} |
---|
276 | addchildren(self,children) |
---|
277 | |
---|
278 | class CompositeValue(AbstractGML,csElement): |
---|
279 | def __init__(self, **kwargs): |
---|
280 | AbstractGML.__init__(self,**kwargs) |
---|
281 | children={'measures':[GML('measure'),'csString',GML('valueComponents')]} |
---|
282 | addchildren(self,children) |
---|
283 | |
---|
284 | class DataBlock(AbstractGML,csElement): |
---|
285 | #THIS IS INCOMPLETE |
---|
286 | def __init__(self, **kwargs): |
---|
287 | AbstractGML.__init__(self,**kwargs) |
---|
288 | children={'doubleOrNullTupleList':[GML('doubleOrNullTupleList'),'csString'],'rangeParameters':[GML('CompositeValue'), 'CompositeValue', GML('rangeParameters')]} |
---|
289 | addchildren(self,children) |
---|
290 | |
---|
291 | class RangeSet(AbstractGML,AssociationAttributeGroup,csElement): |
---|
292 | def __init__(self, **kwargs): |
---|
293 | AbstractGML.__init__(self,**kwargs) |
---|
294 | children={'quantityList':[GML('QuantityList'), 'MeasureOrNullList'], 'dataBlock':[GML('DataBlock'),'DataBlock'],'arrayDescriptor':[FILEFORMATS, 'ArrayDescriptor'], 'aggregatedArray':[CSML('AggregatedArray'), 'AggregatedArray']} |
---|
295 | addchildren(self,children) |
---|
296 | |
---|
297 | class MultiPoint(AbstractGML, SRSReferenceGroup,csElement): |
---|
298 | def __init__(self, **kwargs): |
---|
299 | AbstractGML.__init__(self,**kwargs) |
---|
300 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
301 | children={'pointMember':[GML('pointMember'), 'csString'],'pointMembers':[GML('pointMember'), 'csString']} |
---|
302 | addchildren(self,children) |
---|
303 | |
---|
304 | class Point(AbstractGML,SRSReferenceGroup,csElement): |
---|
305 | def __init__(self, **kwargs): |
---|
306 | AbstractGML.__init__(self,**kwargs) |
---|
307 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
308 | children={'pos':[GML('pos'), 'csString'],'coordinates':[GML('coordinates'), 'csString']} |
---|
309 | addchildren(self,children) |
---|
310 | |
---|
311 | class PointDomain(DomainSet, MultiPoint,csElement): |
---|
312 | def __init__(self, **kwargs): |
---|
313 | DomainSet.__init__(self,**kwargs) |
---|
314 | MultiPoint.__init__(self,**kwargs) |
---|
315 | children={} |
---|
316 | addchildren(self,children) |
---|
317 | |
---|
318 | class ProfileDomain(DomainSet, MultiPoint,csElement): |
---|
319 | def __init__(self, **kwargs): |
---|
320 | DomainSet.__init__(self,**kwargs) |
---|
321 | MultiPoint.__init__(self,**kwargs) |
---|
322 | children={} |
---|
323 | addchildren(self,children) |
---|
324 | |
---|
325 | |
---|
326 | |
---|
327 | class AbstractCoverage(AbstractFeature, csElement): |
---|
328 | def __init__(self, **kwargs): |
---|
329 | AbstractFeature.__init__(self,**kwargs) |
---|
330 | |
---|
331 | class AbstractDiscreteCoverage(AbstractCoverage, csElement): |
---|
332 | def __init__(self, **kwargs): |
---|
333 | AbstractCoverage.__init__(self,**kwargs) |
---|
334 | addchildren(self,{}) |
---|
335 | |
---|
336 | class Definition(AbstractGML): |
---|
337 | def __init__(self, **kwargs): |
---|
338 | AbstractGML.__init__(self,**kwargs) |
---|
339 | addchildren(self,{}) |
---|
340 | |
---|
341 | class Phenomenon(Definition,AssociationAttributeGroup): |
---|
342 | def __init__(self, **kwargs): |
---|
343 | Definition.__init__(self,**kwargs) |
---|
344 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
345 | children = {'':[CSML(''), '']} |
---|
346 | addchildren(self,children) |
---|
347 | |
---|
348 | class SpatialOrTemporalPositionList(AbstractGML,csElement): |
---|
349 | def __init__(self, **kwargs): |
---|
350 | AbstractGML.__init__(self,**kwargs) |
---|
351 | children={'coordinateList':[CSML('coordinateList'),'csString'], 'timePositionList':[CSML('timePositionList'),'csString']} |
---|
352 | addchildren(self,children) |
---|
353 | |
---|
354 | class GridOrdinateDescription(AbstractGML,csElement): |
---|
355 | def __init__(self, **kwargs): |
---|
356 | AbstractGML.__init__(self,**kwargs) |
---|
357 | children={'coordAxisLabel':[CSML('coordAxisLabel'), 'csString'], 'coordAxisValues':[CSML('SpatialOrTemporalPositionList'),'SpatialOrTemporalPositionList',CSML('coordAxisValues')], 'gridAxesSpanned':[CSML('gridAxesSpanned'), 'csString'], 'sequenceRule':[CSML('sequenceRule'),'SequenceRuleType']} |
---|
358 | addchildren(self,children) |
---|
359 | |
---|
360 | class SequenceRuleType(csElement): |
---|
361 | def __init__(self, **kwargs): |
---|
362 | a=['axisOrder'] |
---|
363 | addatts(self,a) |
---|
364 | children={} |
---|
365 | addchildren(self,children) |
---|
366 | |
---|
367 | class GridPointDescription(AbstractGML,csElement): |
---|
368 | def __init__(self, **kwargs): |
---|
369 | AbstractGML.__init__(self,**kwargs) |
---|
370 | children={'posList':[CSML('posList'),'csString'],'sequenceRule':[CSML('sequenceRule'),'SequenceRuleType']} |
---|
371 | addchildren(self,children) |
---|
372 | |
---|
373 | |
---|
374 | class TimePositionList(AbstractGML,csElement): |
---|
375 | def __init__(self,**kwargs): |
---|
376 | a=['frame', 'calendarEraName','indeterminatePosition'] |
---|
377 | addatts(self,a) |
---|
378 | |
---|
379 | |
---|
380 | class GridCoordinatesTable(AbstractGML,csElement): |
---|
381 | def __init__(self,**kwargs): |
---|
382 | '''the additional value '1' in the children dictionary is used to signify that the elements must be nested as: |
---|
383 | <gml:ordinate> |
---|
384 | <gml:GridOrdinateDescription> |
---|
385 | </gml:ordinate> |
---|
386 | <gml:ordinate> |
---|
387 | <gml:GridOrdinateDescription> |
---|
388 | </gml:ordinate> |
---|
389 | |
---|
390 | not as: |
---|
391 | <gml:ordinate> |
---|
392 | <gml:GridOrdinateDescription> |
---|
393 | <gml:GridOrdinateDescription> |
---|
394 | </gml:ordinate> ''' |
---|
395 | AbstractGML.__init__(self,**kwargs) |
---|
396 | children={'gridOrdinates':[CSML('GridOrdinateDescription'), 'GridOrdinateDescription',CSML('gridOrdinate'),1], 'gridPoints':[CSML('GridPointDescription'),'GridPointDescription',CSML('gridPoints')]} |
---|
397 | addchildren(self,children) |
---|
398 | |
---|
399 | class ReferenceableGrid(AbstractGML, AssociationAttributeGroup, csElement): |
---|
400 | def __init__(self, **kwargs): |
---|
401 | AbstractGML.__init__(self,**kwargs) |
---|
402 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
403 | children={'coordTransformTable':[CSML('GridCoordinatesTable'), 'GridCoordinatesTable', CSML('coordTransformTable')]} |
---|
404 | addchildren(self,children) |
---|
405 | a=['dimension'] |
---|
406 | addatts(self,a) |
---|
407 | |
---|
408 | class ReferenceableGridCoverage(AbstractDiscreteCoverage, csElement): |
---|
409 | def __init__(self, **kwargs): |
---|
410 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
411 | children={'referenceableGridDomain':[CSML('ReferenceableGrid'),'ReferenceableGrid' ,CSML('referenceableGridDomain') ]} |
---|
412 | addchildren(self,children) |
---|
413 | |
---|
414 | class AlternatePointCoverage(AbstractDiscreteCoverage, csElement): |
---|
415 | def __init__(self, **kwargs): |
---|
416 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
417 | children={'alternatePointDomain':[GML('Point'),'Point', CSML('alternatePointDomain')], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
418 | addchildren(self,children) |
---|
419 | print self.CHILDREN |
---|
420 | |
---|
421 | |
---|
422 | class ProfileCoverage(AbstractDiscreteCoverage, csElement): |
---|
423 | def __init__(self, **kwargs): |
---|
424 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
425 | children={'profileDomain':[CSML('ProfileDomain'),'ProfileDomain' ,CSML('profileDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
426 | addchildren(self,children) |
---|
427 | |
---|
428 | class PointCoverage(AbstractDiscreteCoverage, csElement): |
---|
429 | def __init__(self, **kwargs): |
---|
430 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
431 | children={'pointDomain':[CSML('PointDomain'),'PointDomain' ,CSML('pointDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
432 | addchildren(self,children) |
---|
433 | |
---|
434 | class TimeSeriesDomain(AbstractGML, csElement): |
---|
435 | def __init__(self, **kwargs): |
---|
436 | AbstractGML.__init__(self,**kwargs) |
---|
437 | children={'time':[CSML('time'), 'csString']} |
---|
438 | addchildren(self,children) |
---|
439 | |
---|
440 | |
---|
441 | class PointSeriesCoverage(AbstractDiscreteCoverage, csElement): |
---|
442 | def __init__(self, **kwargs): |
---|
443 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
444 | children={'pointSeriesDomain':[CSML('TimeSeriesDomain'),'TimeSeriesDomain' ,CSML('pointSeriesDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
445 | addchildren(self,children) |
---|
446 | |
---|
447 | class ProfileSeriesDomain(ReferenceableGrid, DomainSet, csElement): |
---|
448 | def __init__(self, **kwargs): |
---|
449 | DomainSet.__init__(self,**kwargs) |
---|
450 | ReferenceableGrid.__init__(self,**kwargs) |
---|
451 | children={} |
---|
452 | addchildren(self,children) |
---|
453 | |
---|
454 | class ProfileSeriesCoverage(AbstractDiscreteCoverage,csElement): |
---|
455 | def __init__(self, **kwargs): |
---|
456 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
457 | children={'profileSeriesDomain':[CSML('ProfileSeriesDomain'),'ProfileSeriesDomain' ,CSML('profileSeriesDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
458 | addchildren(self,children) |
---|
459 | |
---|
460 | class SectionDomain(ReferenceableGrid, DomainSet, csElement): |
---|
461 | def __init__(self, **kwargs): |
---|
462 | DomainSet.__init__(self,**kwargs) |
---|
463 | ReferenceableGrid.__init__(self,**kwargs) |
---|
464 | children={} |
---|
465 | addchildren(self,children) |
---|
466 | |
---|
467 | class SectionCoverage(AbstractDiscreteCoverage,csElement): |
---|
468 | def __init__(self, **kwargs): |
---|
469 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
470 | children={'sectionDomain':[CSML('SectionDomain'),'SectionDomain' ,CSML('sectionDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
471 | addchildren(self,children) |
---|
472 | |
---|
473 | class TrajectoryDomain(ReferenceableGrid, DomainSet, csElement): |
---|
474 | def __init__(self, **kwargs): |
---|
475 | DomainSet.__init__(self,**kwargs) |
---|
476 | ReferenceableGrid.__init__(self,**kwargs) |
---|
477 | children={} |
---|
478 | addchildren(self,children) |
---|
479 | |
---|
480 | class TrajectoryCoverage(AbstractDiscreteCoverage,csElement): |
---|
481 | def __init__(self, **kwargs): |
---|
482 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
483 | children={'trajectoryDomain':[CSML('TrajectoryDomain'),'TrajectoryDomain' ,CSML('trajectoryDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
484 | addchildren(self,children) |
---|
485 | |
---|
486 | |
---|
487 | class ScanningRadarDomain(ReferenceableGrid, DomainSet, csElement): |
---|
488 | def __init__(self, **kwargs): |
---|
489 | DomainSet.__init__(self,**kwargs) |
---|
490 | ReferenceableGrid.__init__(self,**kwargs) |
---|
491 | children={} |
---|
492 | addchildren(self,children) |
---|
493 | |
---|
494 | class ScanningRadarCoverage(AbstractDiscreteCoverage,csElement): |
---|
495 | def __init__(self, **kwargs): |
---|
496 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
497 | children={'scanningRadarDomain':[CSML('ScanningRadarDomain'),'ScanningRadarDomain' ,CSML('scanningRadarDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
498 | addchildren(self,children) |
---|
499 | |
---|
500 | |
---|
501 | class GridSeriesDomain(ReferenceableGrid, DomainSet, csElement): |
---|
502 | def __init__(self, **kwargs): |
---|
503 | DomainSet.__init__(self,**kwargs) |
---|
504 | ReferenceableGrid.__init__(self,**kwargs) |
---|
505 | children={} |
---|
506 | addchildren(self,children) |
---|
507 | |
---|
508 | class GridSeriesCoverage(AbstractDiscreteCoverage,csElement): |
---|
509 | def __init__(self, **kwargs): |
---|
510 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
511 | children={'gridSeriesDomain':[CSML('GridSeriesDomain'),'GridSeriesDomain' ,CSML('gridSeriesDomain') ], 'rangeSet':[GML('rangeSet'), 'RangeSet'],'coverageFunction':[GML('coverageFunction'),'csString']} |
---|
512 | addchildren(self,children) |
---|
513 | |
---|
514 | class AlternatePointFeature(AbstractFeature, csElement): |
---|
515 | def __init__(self, **kwargs): |
---|
516 | AbstractFeature.__init__(self,**kwargs) |
---|
517 | children={'location':[CSML('location'), 'csString'],'time':[CSML('time'), 'csString'], 'value':[CSML('AlternatePointCoverage'), 'AlternatePointCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
518 | addchildren(self,children) |
---|
519 | |
---|
520 | class PointFeature(AbstractFeature, csElement): |
---|
521 | def __init__(self, **kwargs): |
---|
522 | AbstractFeature.__init__(self,**kwargs) |
---|
523 | children={'location':[CSML('location'), 'csString'],'time':[CSML('time'), 'csString'], 'value':[CSML('PointCoverage'), 'PointCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
524 | addchildren(self,children) |
---|
525 | |
---|
526 | class PointCollectionFeature(AbstractFeature, csElement): |
---|
527 | def __init__(self, **kwargs): |
---|
528 | AbstractFeature.__init__(self,**kwargs) |
---|
529 | children={'time':[CSML('time'), 'csString'], 'value':[CSML('MultiPointCoverage'), 'MultiPointCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
530 | addchildren(self,children) |
---|
531 | |
---|
532 | |
---|
533 | class PointSeriesFeature(AbstractFeature, csElement): |
---|
534 | def __init__(self, **kwargs): |
---|
535 | AbstractFeature.__init__(self,**kwargs) |
---|
536 | children={'location':[CSML('location'), 'csString'], 'value':[CSML('PointSeriesCoverage'), 'PointSeriesCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
537 | addchildren(self,children) |
---|
538 | |
---|
539 | |
---|
540 | class GridFeature(AbstractFeature, csElement): |
---|
541 | def __init__(self, **kwargs): |
---|
542 | AbstractFeature.__init__(self,**kwargs) |
---|
543 | children={'time':[CSML('time'), 'csString'], 'value':[CSML('ReferenceableGridCoverage'), 'ReferenceableGridCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
544 | addchildren(self,children) |
---|
545 | |
---|
546 | class GridSeriesFeature(AbstractFeature, csElement): |
---|
547 | def __init__(self, **kwargs): |
---|
548 | AbstractFeature.__init__(self,**kwargs) |
---|
549 | children={'value':[CSML('GridSeriesCoverage'), 'GridSeriesCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
550 | addchildren(self,children) |
---|
551 | |
---|
552 | class ProfileFeature(AbstractFeature, csElement): |
---|
553 | def __init__(self, **kwargs): |
---|
554 | AbstractFeature.__init__(self,**kwargs) |
---|
555 | children={'time':[CSML('time'), 'csString'],'location':[CSML('location'), 'csString'], 'value':[CSML('ProfileCoverage'), 'ProfileCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
556 | addchildren(self,children) |
---|
557 | |
---|
558 | class ProfileSeriesFeature(AbstractFeature, csElement): |
---|
559 | def __init__(self, **kwargs): |
---|
560 | AbstractFeature.__init__(self,**kwargs) |
---|
561 | children={'location':[CSML('location'), 'csString'], 'value':[CSML('ProfileSeriesCoverage'), 'ProfileSeriesCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
562 | addchildren(self,children) |
---|
563 | |
---|
564 | class RaggedProfileSeriesFeature(AbstractFeature, csElement): |
---|
565 | def __init__(self, **kwargs): |
---|
566 | AbstractFeature.__init__(self,**kwargs) |
---|
567 | children={'location':[CSML('location'), 'csString'], 'profileLength':[CSML('profileLength'), 'csString'],'value':[CSML('ProfileSeriesCoverage'), 'ProfileSeriesCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
568 | addchildren(self,children) |
---|
569 | |
---|
570 | class RaggedSectionFeature(AbstractFeature, csElement): |
---|
571 | def __init__(self, **kwargs): |
---|
572 | AbstractFeature.__init__(self,**kwargs) |
---|
573 | children={'stationLocations':[CSML('stationLocations'), 'csString'], 'stationTimes':[CSML('stationTimes'), 'csString'],'profileLength':[CSML('profileLength'),'csString'],'value':[CSML('SectionCoverage'), 'SectionCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
574 | addchildren(self,children) |
---|
575 | |
---|
576 | class SectionFeature(AbstractFeature, csElement): |
---|
577 | def __init__(self, **kwargs): |
---|
578 | AbstractFeature.__init__(self,**kwargs) |
---|
579 | children={'stationLocations':[CSML('stationLocations'), 'csString'], 'stationTimes':[CSML('stationTimes'), 'TimePositionList'],'value':[CSML('SectionCoverage'), 'SectionCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
580 | addchildren(self,children) |
---|
581 | |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | class ScanningRadarFeature(AbstractFeature, csElement): |
---|
586 | def __init__(self, **kwargs): |
---|
587 | AbstractFeature.__init__(self,**kwargs) |
---|
588 | children={'elevation':[CSML('elevation'), 'csString'], 'value':[CSML('ScanningRadarCoverage'), 'ScanningRadarCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
589 | addchildren(self,children) |
---|
590 | |
---|
591 | class SwathFeature(AbstractFeature, csElement): |
---|
592 | def __init__(self, **kwargs): |
---|
593 | AbstractFeature.__init__(self,**kwargs) |
---|
594 | children={'eqCrossLon':[CSML('eqCrossLon'), 'csString'],'eqCrossTime':[CSML('eqCrossTime'), 'csString'], 'value':[CSML('ReferenceableGridCoverage'), 'ReferenceableGridCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
595 | addchildren(self,children) |
---|
596 | |
---|
597 | class TrajectoryFeature(AbstractFeature, csElement): |
---|
598 | def __init__(self, **kwargs): |
---|
599 | AbstractFeature.__init__(self,**kwargs) |
---|
600 | children={'value':[CSML('TrajectoryCoverage'), 'TrajectoryCoverage', CSML('value')], 'parameter':[CSML('parameter'), 'Phenomenon']} |
---|
601 | addchildren(self,children) |
---|
602 | |
---|
603 | class FileExtract(ArrayDescriptor, csElement): |
---|
604 | def __init__(self,**kwargs): |
---|
605 | ArrayDescriptor.__init__(self,**kwargs) |
---|
606 | children= {'fileName':[CSML('fileName'), 'csString']} |
---|
607 | addchildren(self,children) |
---|
608 | |
---|
609 | class NetCDFExtract(FileExtract, csElement): |
---|
610 | def __init__(self,**kwargs): |
---|
611 | FileExtract.__init__(self, **kwargs) |
---|
612 | children={'variableName':[CSML('variableName'), 'csString']} |
---|
613 | addchildren(self,children) |
---|
614 | |
---|
615 | class NASAAmesExtract(FileExtract, csElement): |
---|
616 | def __init__(self,**kwargs): |
---|
617 | FileExtract.__init__(self, **kwargs) |
---|
618 | children={'variableName':[CSML('variableName'), 'csString'], 'index':[CSML('index'),'csString']} |
---|
619 | addchildren(self,children) |
---|
620 | |
---|
621 | class FeatureCollection(AbstractFeatureCollection,csElement): |
---|
622 | def __init__(self,**kwargs): |
---|
623 | AbstractFeatureCollection.__init__(self,**kwargs) |
---|
624 | children={'members':[[CSML('GridFeature'), CSML('GridSeriesFeature'),CSML('PointFeature'),CSML('TrajectoryFeature'),CSML('ProfileFeature'),CSML('ProfileSeriesFeature'),CSML('RaggedProfileSeriesFeature'),CSML('RaggedSectionFeature'),CSML('SectionFeature'),CSML('ScanningRadarFeature'),CSML('PointSeriesFeature'),CSML('AlternatePointFeature')], 'AbstractFeature', GML('featureMembers')]} |
---|
625 | addchildren(self,children) |
---|
626 | def _getSubstitutionType(self,tag): |
---|
627 | if tag==CSML('GridFeature'): |
---|
628 | return 'GridFeature' |
---|
629 | elif tag==CSML('GridSeriesFeature'): |
---|
630 | return 'GridSeriesFeature' |
---|
631 | elif tag==CSML('PointFeature'): |
---|
632 | return 'PointFeature' |
---|
633 | elif tag==CSML('TrajectoryFeature'): |
---|
634 | return 'TrajectoryFeature' |
---|
635 | elif tag==CSML('PointSeriesFeature'): |
---|
636 | return 'PointSeriesFeature' |
---|
637 | elif tag==CSML('ProfileFeature'): |
---|
638 | return 'ProfileFeature' |
---|
639 | elif tag==CSML('ProfileSeriesFeature'): |
---|
640 | return 'ProfileSeriesFeature' |
---|
641 | elif tag==CSML('RaggedProfileSeriesFeature'): |
---|
642 | return 'RaggedProfileSeriesFeature' |
---|
643 | elif tag==CSML('RaggedSectionFeature'): |
---|
644 | return 'RaggedSectionFeature' |
---|
645 | elif tag==CSML('SectionFeature'): |
---|
646 | return 'SectionFeature' |
---|
647 | elif tag==CSML('ScanningRadarFeature'): |
---|
648 | return 'ScanningRadarFeature' |
---|
649 | elif tag==CSML('AlternatePointFeature'): |
---|
650 | return 'AlternatePointFeature' |
---|
651 | else: return 'AbstractFeature' |
---|
652 | def _getReverseSubsType(self, typename): |
---|
653 | if typename== 'GridFeature': |
---|
654 | return CSML('GridFeature') |
---|
655 | elif typename == 'GridSeriesFeature': |
---|
656 | return CSML('GridSeriesFeature') |
---|
657 | elif typename == 'PointSeriesFeature': |
---|
658 | return CSML('PointSeriesFeature') |
---|
659 | elif typename == 'ProfileFeature': |
---|
660 | return CSML('ProfileFeature') |
---|
661 | elif typename == 'ProfileSeriesFeature': |
---|
662 | return CSML('ProfileSeriesFeature') |
---|
663 | elif typename == 'SectionFeature': |
---|
664 | return CSML('SectionFeature') |
---|
665 | elif typename == 'ScanningRadarFeature': |
---|
666 | return CSML('ScanningRadarFeature') |
---|
667 | elif typename == 'RaggedSectionFeature': |
---|
668 | return CSML('RaggedSectionFeature') |
---|
669 | elif typename == 'RaggedProfileSeriesFeature': |
---|
670 | return CSML('RaggedProfileSeriesFeature') |
---|
671 | elif typename == 'PointFeature': |
---|
672 | return CSML('PointFeature') |
---|
673 | elif typename == 'TrajectoryFeature': |
---|
674 | return CSML('TrajectoryFeature') |
---|
675 | elif typename == 'AlternatePointFeature': |
---|
676 | return CSML('AlternatePointFeature') |
---|
677 | else: return CSML('AbstractFeature') |
---|
678 | |
---|
679 | |
---|
680 | class Dataset(AbstractGML, csElement): |
---|
681 | ''' Dataset class, needed as root of tree''' |
---|
682 | def __init__(self, **kwargs): |
---|
683 | AbstractGML.__init__(self,**kwargs) |
---|
684 | children = {'featureCollection':[GML('FeatureCollection') ,'FeatureCollection'],'fileExtracts':[FILEFORMATS, 'ArrayDescriptor']} |
---|
685 | addchildren(self,children) |
---|
686 | def toXML(self): |
---|
687 | csmlfrag=ET.Element(CSML('Dataset')) |
---|
688 | csElement.toXML(self, csmlfrag) |
---|
689 | return csmlfrag |
---|
690 | def _getSubstitutionType(self,tag): |
---|
691 | if tag==CSML('NetCDFExtract'): |
---|
692 | return 'NetCDFExtract' |
---|
693 | elif tag==CSML('NASAAmesExtract'): |
---|
694 | return 'NASAAmesExtract' |
---|
695 | else: return 'ArrayDescriptor' |
---|
696 | def _getReverseSubsType(self, typename): |
---|
697 | if typename== 'NetCDFExtract': |
---|
698 | return CSML('NetCDFExtract') |
---|
699 | elif typename == 'NASAAmesExtract': |
---|
700 | return CSML('NASAAmesExtract') |
---|
701 | else: return CSML('ArrayDescriptor') |
---|
702 | |
---|
703 | return typename |
---|
704 | |
---|
705 | def main(): |
---|
706 | '''round trip for testing purposes:''' |
---|
707 | print '\n' |
---|
708 | tree=ET.ElementTree(file='test.xml') |
---|
709 | ds=Dataset() |
---|
710 | ds.fromXML(tree.getroot()) |
---|
711 | csmltree=ds.toXML() |
---|
712 | #print csmltree |
---|
713 | |
---|
714 | csmlout=parser_extra.PrettyPrint(csmltree) |
---|
715 | csmlout=parser_extra.removeInlineNS(csmlout) |
---|
716 | print '\n %s'% csmlout |
---|
717 | #for member in ds.featureCollection.members: |
---|
718 | #print dir(member.value) |
---|
719 | |
---|
720 | |
---|
721 | if __name__=='__main__': |
---|
722 | main() |
---|