1 | import cElementTree as ET |
---|
2 | import elementtree.ElementTree as etree |
---|
3 | import sys, traceback |
---|
4 | import csml |
---|
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 | |
---|
19 | def myQName(uri,tag): |
---|
20 | return "{"+uri+"}"+tag |
---|
21 | |
---|
22 | def CSML(tag): |
---|
23 | return myQName(nsCSML,tag) |
---|
24 | |
---|
25 | def GML(tag): |
---|
26 | return myQName(nsGML,tag) |
---|
27 | |
---|
28 | def SWE(tag): |
---|
29 | return myQName(nsSWE,tag) |
---|
30 | |
---|
31 | def XLINK(tag): |
---|
32 | return myQName(nsXLINK,tag) |
---|
33 | |
---|
34 | def MOLES(tag): |
---|
35 | return myQName(nsMOLES,tag) |
---|
36 | |
---|
37 | |
---|
38 | def addchildren(obj, dict): |
---|
39 | ''' merges (adds) dictionary to existing self.CHILDREN dictionary ''' |
---|
40 | dict1 = dict |
---|
41 | if hasattr(obj, 'CHILDREN'): |
---|
42 | dict2=obj.CHILDREN |
---|
43 | else: |
---|
44 | dict2={} |
---|
45 | dict3={} |
---|
46 | for item in dict1: |
---|
47 | dict3[item] =dict1[item] |
---|
48 | for item in dict2: |
---|
49 | dict3[item] =dict2[item] |
---|
50 | obj.CHILDREN=dict3 |
---|
51 | |
---|
52 | |
---|
53 | def addatts(obj, atts): |
---|
54 | ''' merges self.ATTRIBUTES of inherited classes''' |
---|
55 | if hasattr(obj, 'ATTRIBUTES'): |
---|
56 | for att in atts: |
---|
57 | obj.ATTRIBUTES.append(att) |
---|
58 | else: |
---|
59 | obj.ATTRIBUTES=atts |
---|
60 | |
---|
61 | def addelems(obj, elems): |
---|
62 | ''' merges self.elems of inherited classes''' |
---|
63 | if hasattr(obj, 'ELEMORDER'): |
---|
64 | for elem in elems: |
---|
65 | obj.ELEMORDER.append(elem) |
---|
66 | else: |
---|
67 | obj.ELEMORDER=elems |
---|
68 | |
---|
69 | |
---|
70 | #Some variable definitions: these things are often repeated so store in variables. |
---|
71 | FILEFORMATS=[CSML('NetCDFExtract'),CSML('NASAAmesExtract'), CSML('GRIBExtract'),CSML('CDMLExtract'), CSML('RawFileExtract'), CSML('ImageFileExtract'), CSML('AggregatedArray')] |
---|
72 | |
---|
73 | |
---|
74 | class csElement(object): |
---|
75 | ''' main csElement class - all other elements inherit from this baseclass |
---|
76 | all the from/to XML conversion is done by this class''' |
---|
77 | |
---|
78 | def __init__(self, **kwargs): |
---|
79 | for kw in kwargs: |
---|
80 | self.__setattr__(kw, kwargs[kw]) |
---|
81 | if not hasattr(self, 'ATTRIBUTES'): |
---|
82 | self.__dict__['ATTRIBUTES']=[] |
---|
83 | if not hasattr(self, 'ELEMORDER'): |
---|
84 | self.__dict__['ELEMORDER']=[] |
---|
85 | if not hasattr(self, 'CHILDREN'): |
---|
86 | self.__dict__['CHILDREN']={} |
---|
87 | #The __setattr__ and __getattribute__ special methods have been overridden. |
---|
88 | #This is so that attributes can be called by their fully qualified name internally |
---|
89 | #while being referenced by their short name externally. |
---|
90 | # so 'id' and {'http://www.opengis.net/gml'}id always have the same value |
---|
91 | #you can set either of them at any time and the other will be kept in sync. |
---|
92 | |
---|
93 | def __setattr__(self, name, value): |
---|
94 | if hasattr(self, CSML(name)): |
---|
95 | object.__setattr__(self, CSML(name), value) |
---|
96 | object.__setattr__(self, name, value) |
---|
97 | elif hasattr(self,GML(name)): |
---|
98 | object.__setattr__(self, GML(name), value) |
---|
99 | object.__setattr__(self, name, value) |
---|
100 | elif hasattr(self,XLINK(name)): |
---|
101 | object.__setattr__(self, XLINK(name), value) |
---|
102 | object.__setattr__(self, name, value) |
---|
103 | else: |
---|
104 | if hasattr(self, 'ATTRIBUTES'): |
---|
105 | if CSML(name) in self.__dict__['ATTRIBUTES']: |
---|
106 | object.__setattr__(self, CSML(name), value) |
---|
107 | object.__setattr__(self, name, value) |
---|
108 | elif GML(name) in self.__dict__['ATTRIBUTES']: |
---|
109 | object.__setattr__(self, GML(name), value) |
---|
110 | object.__setattr__(self, name, value) |
---|
111 | elif XLINK(name) in self.__dict__['ATTRIBUTES']: |
---|
112 | object.__setattr__(self, XLINK(name), value) |
---|
113 | object.__setattr__(self, name, value) |
---|
114 | elif name in self.__dict__['ATTRIBUTES']: |
---|
115 | object.__setattr__(self, name, value) |
---|
116 | try: |
---|
117 | name=name.split('}')[1] |
---|
118 | except IndexError: |
---|
119 | pass |
---|
120 | object.__setattr__(self, name, value) |
---|
121 | else: |
---|
122 | object.__setattr__(self, name, value) |
---|
123 | else: |
---|
124 | object.__setattr__(self, name, value) |
---|
125 | |
---|
126 | def __getattribute__(self, name): |
---|
127 | if CSML(name) in object.__dict__: |
---|
128 | return object.__getattribute__(self,CSML(name)) |
---|
129 | elif GML(name) in object.__dict__: |
---|
130 | return object.__getattribute__(self,GML(name)) |
---|
131 | elif XLINK(name) in object.__dict__: |
---|
132 | return object.__getattribute__(self,XLINK(name)) |
---|
133 | else: |
---|
134 | return object.__getattribute__(self,name) |
---|
135 | |
---|
136 | def __removeURI(self, qname): |
---|
137 | try: |
---|
138 | attname = qname.split('}')[1] |
---|
139 | except IndexError: |
---|
140 | attname = qname |
---|
141 | return attname |
---|
142 | |
---|
143 | def _getSubstitutionType(self,tag): |
---|
144 | return tag.split('}')[1] |
---|
145 | |
---|
146 | |
---|
147 | def _getReverseSubsType(self, typename): |
---|
148 | return typename |
---|
149 | |
---|
150 | def addChildElem(self, childname, childobj): |
---|
151 | #sometimes you want to add a child element but don't know if there is one already. In which case you want to create a list of child objects. |
---|
152 | if hasattr(self, childname): |
---|
153 | currentattribute=getattr(self,childname) |
---|
154 | if type(getattr(self,childname)) is list: |
---|
155 | currentattribute.append(childobj) |
---|
156 | else: |
---|
157 | newlist=[currentattribute] |
---|
158 | newlist.append(childobj) |
---|
159 | setattr(self,childname, newlist) |
---|
160 | else: |
---|
161 | setattr(self,childname, childobj) |
---|
162 | |
---|
163 | def toXML(self, csmlfrag, **kwargs): |
---|
164 | #process self and convert to XML |
---|
165 | if hasattr(self, 'CONTENT'): |
---|
166 | if self.CONTENT is not None: csmlfrag.text=self.CONTENT |
---|
167 | if hasattr(self, 'ATTRIBUTES'): |
---|
168 | for item in self.__dict__: |
---|
169 | if item in self.ATTRIBUTES: |
---|
170 | csmlfrag.set(item, self.__dict__[item]) |
---|
171 | # self.CHILDREN (recursive - calls the toXML method of children |
---|
172 | for child in self.ELEMORDER: |
---|
173 | if not self.__dict__.has_key(child): |
---|
174 | continue |
---|
175 | appendLater=False |
---|
176 | parserobjects=[] |
---|
177 | if type(self.__dict__[child]) is list: |
---|
178 | for a in self.__dict__[child]: |
---|
179 | parserobjects.append(a) |
---|
180 | else: |
---|
181 | parserobjects.append(self.__dict__[child]) |
---|
182 | parentfrag=None |
---|
183 | if len(self.CHILDREN[child])>=3: |
---|
184 | ename2=self.CHILDREN[child][2] |
---|
185 | parentfrag=ET.Element(ename2) |
---|
186 | for po in parserobjects: |
---|
187 | if type(self.CHILDREN[child][0]) is not list: |
---|
188 | ename=self.CHILDREN[child][0] |
---|
189 | else: |
---|
190 | ename = self._getReverseSubsType(type(po).__name__) |
---|
191 | if len(self.CHILDREN[child])==3: |
---|
192 | frag=ET.Element(ename) |
---|
193 | po.toXML(frag) |
---|
194 | parentfrag.append(frag) |
---|
195 | appendLater=True |
---|
196 | elif len(self.CHILDREN[child])>=4: |
---|
197 | if self.CHILDREN[child][3]==1: |
---|
198 | frag=ET.Element(ename) |
---|
199 | po.toXML(frag) |
---|
200 | parentfrag.append(frag) |
---|
201 | csmlfrag.append(parentfrag) |
---|
202 | parentfrag=ET.Element(parentfrag.tag) |
---|
203 | appendLater=False |
---|
204 | else: |
---|
205 | frag=ET.Element(ename) |
---|
206 | try: |
---|
207 | po.toXML(frag) |
---|
208 | except: |
---|
209 | print 'PARSING ERROR - could not convert %s to XML'%frag |
---|
210 | print dir(ename) |
---|
211 | raise |
---|
212 | csmlfrag.append(frag) |
---|
213 | appendLater=True |
---|
214 | |
---|
215 | if appendLater==True and parentfrag != None: |
---|
216 | csmlfrag.append(parentfrag) |
---|
217 | |
---|
218 | return csmlfrag |
---|
219 | |
---|
220 | def fromXML(self,csmlfrag): |
---|
221 | # deal with attributes, e.g. gml id's |
---|
222 | if csmlfrag.text is not None: |
---|
223 | self.CONTENT = csmlfrag.text |
---|
224 | for item in csmlfrag.items(): |
---|
225 | if item[0] in self.ATTRIBUTES: |
---|
226 | setattr(self, item[0], item[1]) |
---|
227 | #self.CHILDREN (recursive - calls the fromXML method of children |
---|
228 | for frag in csmlfrag[:]: |
---|
229 | #for each child element |
---|
230 | #iterate through expected CHILDREN to find match |
---|
231 | for child in self.CHILDREN: |
---|
232 | if len(self.CHILDREN[child])>=3: |
---|
233 | ename = self.CHILDREN[child][2] |
---|
234 | ename2 = self.CHILDREN[child][0] |
---|
235 | else: |
---|
236 | ename = self.CHILDREN[child][0] |
---|
237 | ename2=None |
---|
238 | #if there are options, then find the name that matches the frag |
---|
239 | if ename2 is not None: |
---|
240 | if frag[:] != []: |
---|
241 | for subfrag in frag[:]: |
---|
242 | etype=None |
---|
243 | if type(ename2) is list: |
---|
244 | if subfrag.tag in ename2: |
---|
245 | etype=self._getSubstitutionType(subfrag.tag) |
---|
246 | if subfrag.tag==ename2: |
---|
247 | etype=self.CHILDREN[child][1] |
---|
248 | if etype: |
---|
249 | childobj=eval(etype)() |
---|
250 | if len(self.CHILDREN[child])>=3: |
---|
251 | if frag[:] != []: |
---|
252 | childobj.fromXML(subfrag) |
---|
253 | else: |
---|
254 | childobj.fromXML(frag) |
---|
255 | #set this object to be an attribute of the 'parent' (self) object |
---|
256 | if hasattr(self, child): |
---|
257 | if type(self.__dict__[child]) is not list: |
---|
258 | tmp=self.__dict__[child] |
---|
259 | setattr(self, child, [tmp]) #convert to list |
---|
260 | self.__dict__[child].append(childobj) |
---|
261 | else: |
---|
262 | setattr(self, child, childobj) |
---|
263 | else: |
---|
264 | etype=None |
---|
265 | if type(ename) is list: |
---|
266 | if frag.tag in ename: |
---|
267 | etype=self._getSubstitutionType(frag.tag) |
---|
268 | elif frag.tag==ename: |
---|
269 | etype=self.CHILDREN[child][1] |
---|
270 | if etype: |
---|
271 | childobj=eval(etype)() |
---|
272 | if len(self.CHILDREN[child])>=3: |
---|
273 | if frag[:] != []: |
---|
274 | childobj.fromXML(frag[0]) |
---|
275 | else: |
---|
276 | childobj.fromXML(frag) |
---|
277 | |
---|
278 | #set this object to be an attribute of the 'parent' (self) object |
---|
279 | if hasattr(self, child): |
---|
280 | if type(self.__dict__[child]) is not list: |
---|
281 | tmp=self.__dict__[child] |
---|
282 | setattr(self, child, [tmp]) #convert to list |
---|
283 | self.__dict__[child].append(childobj) |
---|
284 | else: |
---|
285 | setattr(self, child, childobj) |
---|
286 | |
---|
287 | |
---|
288 | |
---|
289 | class AbstractGML(csElement): |
---|
290 | def __init__(self, **kwargs): |
---|
291 | a=[GML('id')] |
---|
292 | addatts(self,a) |
---|
293 | elems=['metaDataProperty', 'description','name'] |
---|
294 | addelems(self,elems) |
---|
295 | children={elems[0]:[GML('metaDataProperty'),'csString'],elems[1]:[GML('description'),'csString'],elems[2]:[GML('name'),'csString']} |
---|
296 | addchildren(self,children) |
---|
297 | csElement.__init__(self,**kwargs) |
---|
298 | |
---|
299 | class AssociationAttributeGroup(csElement): |
---|
300 | def __init__(self, **kwargs): |
---|
301 | a =[XLINK('href'),XLINK('role'), XLINK('arcrole'),XLINK('title'), XLINK('show'), XLINK('actuate')] |
---|
302 | addatts(self,a) |
---|
303 | csElement.__init__(self,**kwargs) |
---|
304 | |
---|
305 | class csString(AssociationAttributeGroup, csElement): |
---|
306 | def __init__(self, text=None,**kwargs): |
---|
307 | #Needed so it can use xlink |
---|
308 | addelems(self,[]) |
---|
309 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
310 | if text != None: |
---|
311 | if type(text) is not str: |
---|
312 | text=str(text) |
---|
313 | self.CONTENT=text |
---|
314 | children={} |
---|
315 | addchildren(self,children) |
---|
316 | csElement.__init__(self,**kwargs) |
---|
317 | |
---|
318 | class SRSReferenceGroup(csElement): |
---|
319 | def __init__(self, **kwargs): |
---|
320 | a =['srsName','srsDimension'] |
---|
321 | addatts(self,a) |
---|
322 | csElement.__init__(self,**kwargs) |
---|
323 | |
---|
324 | class SRSInformationGroup(csElement): |
---|
325 | def __init__(self, **kwargs): |
---|
326 | a =['uomLabels','axisLabels'] |
---|
327 | addatts(self,a) |
---|
328 | csElement.__init__(self,**kwargs) |
---|
329 | |
---|
330 | class ArrayDescriptor(csElement): |
---|
331 | def __init__(self,**kwargs): |
---|
332 | a=['id'] |
---|
333 | addatts(self,a) |
---|
334 | elems=['arraySize', 'uom', 'numericType','regExpTransform','numericTransform'] |
---|
335 | addelems(self,elems) |
---|
336 | children={elems[0]:[CSML('arraySize'), 'csString'], elems[1]:[CSML('uom'),'csString'], elems[2]:[CSML('numericType'),'csString'], elems[3]:[CSML('regExpTransform'),'csString'], elems[4]:[CSML('numericTransform'),'csString']} |
---|
337 | addchildren(self,children) |
---|
338 | csElement.__init__(self,**kwargs) |
---|
339 | |
---|
340 | class GridEnvelope(AbstractGML,SRSReferenceGroup, csElement): |
---|
341 | def __init__(self, **kwargs): |
---|
342 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
343 | AbstractGML.__init__(self,**kwargs) |
---|
344 | elems=['low', 'high'] |
---|
345 | addelems(self,elems) |
---|
346 | children={elems[0]:[GML('low'), 'csString'],elems[1]:[GML('high'), 'csString']} |
---|
347 | addchildren(self,children) |
---|
348 | csElement.__init__(self,**kwargs) |
---|
349 | |
---|
350 | class Envelope(AbstractGML,SRSReferenceGroup, csElement): |
---|
351 | def __init__(self, **kwargs): |
---|
352 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
353 | AbstractGML.__init__(self,**kwargs) |
---|
354 | elems=['lowerCorner','upperCorner'] |
---|
355 | addelems(self,elems) |
---|
356 | children={elems[0]:[GML('lowerCorner'), 'csString'],elems[1]:[GML('upperCorner'), 'csString']} |
---|
357 | addchildren(self,children) |
---|
358 | csElement.__init__(self,**kwargs) |
---|
359 | |
---|
360 | class EnvelopeWithTimePeriod(Envelope): |
---|
361 | def __init__(self, **kwargs): |
---|
362 | Envelope.__init__(self,**kwargs) |
---|
363 | elems=['beginPosition', 'endPosition'] |
---|
364 | addelems(self,elems) |
---|
365 | children={elems[0]:[GML('beginPosition'), 'csString'], elems[1]:[GML('endPosition'), 'csString']} |
---|
366 | addchildren(self,children) |
---|
367 | csElement.__init__(self,**kwargs) |
---|
368 | |
---|
369 | class AbstractFeature(AbstractGML,csElement): |
---|
370 | def __init__(self, **kwargs): |
---|
371 | AbstractGML.__init__(self,**kwargs) |
---|
372 | elems=['boundedBy'] |
---|
373 | addelems(self,elems) |
---|
374 | #this pattern works but can only accept EnvelopeWithTimePeriod for the boundedBy, |
---|
375 | #which is probably ok |
---|
376 | children={elems[0]:[GML('EnvelopeWithTimePeriod'), 'EnvelopeWithTimePeriod', GML('boundedBy')]} |
---|
377 | addchildren(self,children) |
---|
378 | csElement.__init__(self,**kwargs) |
---|
379 | |
---|
380 | class AbstractFeatureCollection(AbstractFeature,csElement): |
---|
381 | def __init__(self, **kwargs): |
---|
382 | AbstractFeature.__init__(self,**kwargs) |
---|
383 | csElement.__init__(self,**kwargs) |
---|
384 | |
---|
385 | class DomainSet(AbstractGML,AssociationAttributeGroup,csElement): |
---|
386 | def __init__(self, **kwargs): |
---|
387 | AbstractGML.__init__(self,**kwargs) |
---|
388 | addchildren(self,{}) |
---|
389 | csElement.__init__(self,**kwargs) |
---|
390 | |
---|
391 | class AggregatedArray(ArrayDescriptor,csElement): |
---|
392 | def __init__(self, **kwargs): |
---|
393 | ArrayDescriptor.__init__(self,**kwargs) |
---|
394 | elems=['aggType', 'aggIndex', 'components'] |
---|
395 | addelems(self,elems) |
---|
396 | children={elems[0]:[CSML('aggType'),'csString'], elems[1]:[CSML('aggIndex'),'csString'],elems[2]:[FILEFORMATS, 'ArrayDescriptor',CSML('component')]} |
---|
397 | addchildren(self,children) |
---|
398 | csElement.__init__(self,**kwargs) |
---|
399 | #'component':[CSML:('component'), 'ArrayDescriptor', CSML('component')], |
---|
400 | |
---|
401 | class MeasureOrNullList(AbstractGML,AssociationAttributeGroup, csElement): |
---|
402 | def __init__(self, **kwargs): |
---|
403 | AbstractGML.__init__(self,**kwargs) |
---|
404 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
405 | elems=['insertedExtract'] |
---|
406 | addelems(self,elems) |
---|
407 | #note insertedExtract is used in resolving xlinks and shouldn't be written to directly (except by the code which handles the xlink resolutions) |
---|
408 | children={elems[0]:[FILEFORMATS,'FileExtract',CSML('insertedExtract')]} |
---|
409 | addchildren(self,children) |
---|
410 | a =['uom'] |
---|
411 | addatts(self,a) |
---|
412 | csElement.__init__(self,**kwargs) |
---|
413 | |
---|
414 | |
---|
415 | class CompositeValue(AbstractGML,csElement): |
---|
416 | def __init__(self, **kwargs): |
---|
417 | AbstractGML.__init__(self,**kwargs) |
---|
418 | elems=['measures'] |
---|
419 | addelems(self,elems) |
---|
420 | children={elems[0]:[GML('measure'),'csString',GML('valueComponents')]} |
---|
421 | addchildren(self,children) |
---|
422 | csElement.__init__(self,**kwargs) |
---|
423 | |
---|
424 | class DataBlock(AbstractGML,csElement): |
---|
425 | #THIS IS INCOMPLETE |
---|
426 | def __init__(self, **kwargs): |
---|
427 | AbstractGML.__init__(self,**kwargs) |
---|
428 | elems=['doubleOrNullTupleList','rangeParameters'] |
---|
429 | addelems(self,elems) |
---|
430 | children={elems[0]:[GML('doubleOrNullTupleList'),'csString'],elems[1]:[GML('CompositeValue'), 'CompositeValue', GML('rangeParameters')]} |
---|
431 | addchildren(self,children) |
---|
432 | csElement.__init__(self,**kwargs) |
---|
433 | |
---|
434 | class ValueArray(AbstractGML, csElement): |
---|
435 | def __init__(self, **kwargs): |
---|
436 | AbstractGML.__init__(self,**kwargs) |
---|
437 | elems=['valueComponent'] |
---|
438 | addelems(self,elems) |
---|
439 | children=children={elems[0]:[GML('QuantityList'), 'MeasureOrNullList', GML('valueComponent')]} |
---|
440 | addchildren(self,children) |
---|
441 | csElement.__init__(self,**kwargs) |
---|
442 | |
---|
443 | def toXML(self, csmlfrag, **kwargs): |
---|
444 | csmlfrag=AbstractGML.toXML(self, csmlfrag,**kwargs) |
---|
445 | #promote XLinks up from QuantityList |
---|
446 | #this all done at the elementtree level |
---|
447 | |
---|
448 | for frag in csmlfrag: |
---|
449 | if frag.tag ==GML('valueComponent'): |
---|
450 | try: |
---|
451 | frag.set(XLINK('href'),self.valueComponent.href) |
---|
452 | for subfrag in frag: |
---|
453 | del subfrag.attrib[XLINK('href')] |
---|
454 | except: |
---|
455 | pass |
---|
456 | try: |
---|
457 | frag.set(XLINK('show'),self.valueComponent.show) |
---|
458 | for subfrag in frag: |
---|
459 | del subfrag.attrib[XLINK('show')] |
---|
460 | except: |
---|
461 | pass |
---|
462 | try: |
---|
463 | frag.set(XLINK('role'),self.valueComponent.role) |
---|
464 | for subfrag in frag: |
---|
465 | del subfrag.attrib[XLINK('role')] |
---|
466 | except: |
---|
467 | pass |
---|
468 | try: |
---|
469 | frag.set(XLINK('arcrole'),self.valueComponent.arcrole) |
---|
470 | for subfrag in frag: |
---|
471 | del subfrag.attrib[XLINK('arcrole')] |
---|
472 | except: |
---|
473 | pass |
---|
474 | return csmlfrag |
---|
475 | |
---|
476 | def fromXML(self, csmlfrag): |
---|
477 | #promote xlinks up a level to the property element |
---|
478 | for frag in csmlfrag: |
---|
479 | if frag.tag == GML('valueComponent'): |
---|
480 | for att in ['href', 'show', 'role', 'arcrole']: |
---|
481 | try: |
---|
482 | for subfrag in frag[:]: |
---|
483 | subfrag.set(XLINK(att),frag.attrib[XLINK(att)]) |
---|
484 | except: |
---|
485 | pass |
---|
486 | csElement.fromXML(self, csmlfrag) |
---|
487 | |
---|
488 | class RangeSet(AbstractGML,AssociationAttributeGroup,csElement): |
---|
489 | def __init__(self, **kwargs): |
---|
490 | AbstractGML.__init__(self,**kwargs) |
---|
491 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
492 | elems=['quantityList', 'dataBlock', 'arrayDescriptor', 'valueArray'] |
---|
493 | addelems(self,elems) |
---|
494 | children={elems[0]:[GML('QuantityList'), 'MeasureOrNullList'], elems[1]:[GML('DataBlock'),'DataBlock'],elems[2]:[FILEFORMATS, 'ArrayDescriptor'], elems[3]:[CSML('AggregatedArray'), 'AggregatedArray'], |
---|
495 | elems[3]:[GML('ValueArray'),'ValueArray']} |
---|
496 | addchildren(self,children) |
---|
497 | csElement.__init__(self,**kwargs) |
---|
498 | |
---|
499 | class MultiPoint(AbstractGML, SRSReferenceGroup,csElement): |
---|
500 | def __init__(self, **kwargs): |
---|
501 | AbstractGML.__init__(self,**kwargs) |
---|
502 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
503 | elems=['pointMember','pointMembers'] |
---|
504 | addelems(self,elems) |
---|
505 | children={elems[0]:[GML('pointMember'), 'csString'],elems[1]:[GML('pointMembers'), 'csString']} |
---|
506 | addchildren(self,children) |
---|
507 | csElement.__init__(self,**kwargs) |
---|
508 | |
---|
509 | class Point(AbstractGML,SRSReferenceGroup,csElement): |
---|
510 | def __init__(self, **kwargs): |
---|
511 | AbstractGML.__init__(self,**kwargs) |
---|
512 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
513 | elems=['pos','coordinates'] |
---|
514 | addelems(self,elems) |
---|
515 | children={elems[0]:[GML('pos'), 'csString'],elems[1]:[GML('coordinates'), 'csString']} |
---|
516 | addchildren(self,children) |
---|
517 | csElement.__init__(self,**kwargs) |
---|
518 | |
---|
519 | class PointDomain(DomainSet, MultiPoint,csElement): |
---|
520 | def __init__(self, **kwargs): |
---|
521 | DomainSet.__init__(self,**kwargs) |
---|
522 | MultiPoint.__init__(self,**kwargs) |
---|
523 | children={} |
---|
524 | addchildren(self,children) |
---|
525 | csElement.__init__(self,**kwargs) |
---|
526 | |
---|
527 | class ProfileDomain(DomainSet, MultiPoint,csElement): |
---|
528 | def __init__(self, **kwargs): |
---|
529 | DomainSet.__init__(self,**kwargs) |
---|
530 | MultiPoint.__init__(self,**kwargs) |
---|
531 | children={} |
---|
532 | addchildren(self,children) |
---|
533 | csElement.__init__(self,**kwargs) |
---|
534 | |
---|
535 | |
---|
536 | class AbstractCoverage(AbstractFeature, csElement): |
---|
537 | def __init__(self, **kwargs): |
---|
538 | AbstractFeature.__init__(self,**kwargs) |
---|
539 | csElement.__init__(self,**kwargs) |
---|
540 | |
---|
541 | class AbstractDiscreteCoverage(AbstractCoverage, csElement): |
---|
542 | def __init__(self, **kwargs): |
---|
543 | AbstractCoverage.__init__(self,**kwargs) |
---|
544 | addchildren(self,{}) |
---|
545 | csElement.__init__(self,**kwargs) |
---|
546 | |
---|
547 | class Definition(AbstractGML): |
---|
548 | def __init__(self, **kwargs): |
---|
549 | AbstractGML.__init__(self,**kwargs) |
---|
550 | addchildren(self,{}) |
---|
551 | csElement.__init__(self,**kwargs) |
---|
552 | |
---|
553 | class Phenomenon(Definition,AssociationAttributeGroup): |
---|
554 | def __init__(self, **kwargs): |
---|
555 | Definition.__init__(self,**kwargs) |
---|
556 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
557 | children = {'':[CSML(''), '']} |
---|
558 | addchildren(self,children) |
---|
559 | csElement.__init__(self,**kwargs) |
---|
560 | |
---|
561 | class SpatialOrTemporalPositionList(AssociationAttributeGroup, AbstractGML, csElement): |
---|
562 | def __init__(self, **kwargs): |
---|
563 | AbstractGML.__init__(self,**kwargs) |
---|
564 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
565 | elems=['coordinateList', 'timePositionList','insertedExtract'] |
---|
566 | addelems(self,elems) |
---|
567 | children={elems[0]:[CSML('coordinateList'),'csString'], elems[1]:[CSML('timePositionList'),'TimePositionList'],elems[2]:[FILEFORMATS,'FileExtract',CSML('insertedExtract')]} |
---|
568 | addchildren(self,children) |
---|
569 | csElement.__init__(self,**kwargs) |
---|
570 | |
---|
571 | def toXML(self,csmlfrag,**kwargs): |
---|
572 | csmlfrag=csElement.toXML(self,csmlfrag, **kwargs) |
---|
573 | #This is mandatory even if empty when using xlink |
---|
574 | if not hasattr(self, 'timePositionList'): |
---|
575 | if not hasattr(self, 'coordinateList'): |
---|
576 | if csmlfrag.get(XLINK('arcrole')) is not None: |
---|
577 | if csmlfrag.get(XLINK('arcrole')).split('#')[1] == 'timePositionList': |
---|
578 | ET.SubElement(csmlfrag, CSML('timePositionList')) |
---|
579 | elif csmlfrag.get(XLINK('arcrole')).split('#')[1] =='coordinateList': |
---|
580 | ET.SubElement(csmlfrag, CSML('coordinateList')) |
---|
581 | return csmlfrag |
---|
582 | |
---|
583 | class GridOrdinateDescription(AbstractGML,csElement): |
---|
584 | def __init__(self, **kwargs): |
---|
585 | AbstractGML.__init__(self,**kwargs) |
---|
586 | elems=['coordAxisLabel', 'coordAxisValues', 'gridAxesSpanned', 'sequenceRule'] |
---|
587 | addelems(self,elems) |
---|
588 | children={elems[0]:[CSML('coordAxisLabel'), 'csString'], elems[1]:[CSML('SpatialOrTemporalPositionList'),'SpatialOrTemporalPositionList',CSML('coordAxisValues')], elems[2]:[CSML('gridAxesSpanned'), 'csString'], elems[3]:[CSML('sequenceRule'),'SequenceRule']} |
---|
589 | addchildren(self,children) |
---|
590 | csElement.__init__(self,**kwargs) |
---|
591 | def toXML(self, csmlfrag, **kwargs): |
---|
592 | csmlfrag=AbstractGML.toXML(self, csmlfrag,**kwargs) |
---|
593 | #promote XLinks up from SpatialOrTemporalPositionList |
---|
594 | #this all done at the elementtree level |
---|
595 | |
---|
596 | for frag in csmlfrag: |
---|
597 | if frag.tag ==CSML('coordAxisValues'): |
---|
598 | try: |
---|
599 | frag.set(XLINK('href'),self.coordAxisValues.href) |
---|
600 | for subfrag in frag: |
---|
601 | del subfrag.attrib[XLINK('href')] |
---|
602 | except: |
---|
603 | pass |
---|
604 | try: |
---|
605 | frag.set(XLINK('show'),self.coordAxisValues.show) |
---|
606 | for subfrag in frag: |
---|
607 | del subfrag.attrib[XLINK('show')] |
---|
608 | except: |
---|
609 | pass |
---|
610 | try: |
---|
611 | frag.set(XLINK('role'),self.coordAxisValues.role) |
---|
612 | for subfrag in frag: |
---|
613 | del subfrag.attrib[XLINK('role')] |
---|
614 | except: |
---|
615 | pass |
---|
616 | try: |
---|
617 | frag.set(XLINK('arcrole'),self.coordAxisValues.arcrole) |
---|
618 | for subfrag in frag: |
---|
619 | del subfrag.attrib[XLINK('arcrole')] |
---|
620 | except: |
---|
621 | pass |
---|
622 | |
---|
623 | |
---|
624 | return csmlfrag |
---|
625 | |
---|
626 | def fromXML(self, csmlfrag): |
---|
627 | #promote xlinks up a level to the coordAxisValues property element |
---|
628 | for frag in csmlfrag: |
---|
629 | if frag.tag == CSML('coordAxisValues'): |
---|
630 | for att in ['href', 'show', 'role', 'arcrole']: |
---|
631 | try: |
---|
632 | for subfrag in frag[:]: |
---|
633 | subfrag.set(XLINK(att),frag.attrib[XLINK(att)]) |
---|
634 | except: |
---|
635 | pass |
---|
636 | |
---|
637 | csElement.fromXML(self, csmlfrag) |
---|
638 | |
---|
639 | |
---|
640 | |
---|
641 | class SequenceRule(csElement): |
---|
642 | def __init__(self, **kwargs): |
---|
643 | a=['axisOrder'] |
---|
644 | addatts(self,a) |
---|
645 | children={} |
---|
646 | addchildren(self,children) |
---|
647 | csElement.__init__(self,**kwargs) |
---|
648 | |
---|
649 | class GridPointDescription(AbstractGML,csElement): |
---|
650 | def __init__(self, **kwargs): |
---|
651 | AbstractGML.__init__(self,**kwargs) |
---|
652 | elems=['posList', 'sequenceRule'] |
---|
653 | addelems(self,elems) |
---|
654 | children={elems[0]:[CSML('posList'),'csString'],elems[1]:[CSML('sequenceRule'),'SequenceRule']} |
---|
655 | addchildren(self,children) |
---|
656 | csElement.__init__(self,**kwargs) |
---|
657 | |
---|
658 | class TimePositionList(AbstractGML,csString,csElement): |
---|
659 | def __init__(self, **kwargs): |
---|
660 | AbstractGML.__init__(self,**kwargs) |
---|
661 | csString.__init__(self, **kwargs) |
---|
662 | elems=[] |
---|
663 | addelems(self,elems) |
---|
664 | a=['frame', 'calendarEraName','indeterminatePosition'] |
---|
665 | addatts(self,a) |
---|
666 | addchildren(self,{}) |
---|
667 | csElement.__init__(self,**kwargs) |
---|
668 | |
---|
669 | class GridCoordinatesTable(AbstractGML,csElement): |
---|
670 | def __init__(self,**kwargs): |
---|
671 | '''the additional value '1' in the children dictionary is used to signify that the elements must be nested as: |
---|
672 | <gml:ordinate> |
---|
673 | <gml:GridOrdinateDescription> |
---|
674 | </gml:ordinate> |
---|
675 | <gml:ordinate> |
---|
676 | <gml:GridOrdinateDescription> |
---|
677 | </gml:ordinate> |
---|
678 | |
---|
679 | not as: |
---|
680 | <gml:ordinate> |
---|
681 | <gml:GridOrdinateDescription> |
---|
682 | <gml:GridOrdinateDescription> |
---|
683 | </gml:ordinate> ''' |
---|
684 | AbstractGML.__init__(self,**kwargs) |
---|
685 | elems=['gridOrdinates' , 'gridPoints'] |
---|
686 | addelems(self,elems) |
---|
687 | children={elems[0]:[CSML('GridOrdinateDescription'), 'GridOrdinateDescription',CSML('gridOrdinate'),1], elems[1]:[CSML('GridPointDescription'),'GridPointDescription',CSML('gridPoints')]} |
---|
688 | addchildren(self,children) |
---|
689 | csElement.__init__(self,**kwargs) |
---|
690 | |
---|
691 | class Grid(AbstractGML, AssociationAttributeGroup, SRSInformationGroup, SRSReferenceGroup, csElement): |
---|
692 | def __init__(self, **kwargs): |
---|
693 | AbstractGML.__init__(self,**kwargs) |
---|
694 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
695 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
696 | SRSInformationGroup.__init__(self,**kwargs) |
---|
697 | a=['dimension'] |
---|
698 | addatts(self,a) |
---|
699 | elems=['limits', 'aLabels','axisName'] |
---|
700 | addelems(self, elems) |
---|
701 | children = {elems[1]:[CSML('axisLabels'),'csString'],elems[2]:[CSML('axisName'),'csString'], elems[0]:[GML('GridEnvelope'),'GridEnvelope',CSML('limits')]} |
---|
702 | addchildren(self,children) |
---|
703 | csElement.__init__(self,**kwargs) |
---|
704 | |
---|
705 | class ReferenceableGrid(Grid, csElement): |
---|
706 | def __init__(self, **kwargs): |
---|
707 | Grid.__init__(self,**kwargs) |
---|
708 | elems=['coordTransformTable'] |
---|
709 | addelems(self,elems) |
---|
710 | children={elems[0]:[CSML('GridCoordinatesTable'), 'GridCoordinatesTable', CSML('coordTransformTable')]} |
---|
711 | addchildren(self,children) |
---|
712 | csElement.__init__(self,**kwargs) |
---|
713 | |
---|
714 | class ReferenceableGridCoverage(AbstractDiscreteCoverage, csElement): |
---|
715 | def __init__(self, **kwargs): |
---|
716 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
717 | elems=[referenceableGridDomain] |
---|
718 | addelems(self,elems) |
---|
719 | children={elems[0]:[CSML('ReferenceableGrid'),'ReferenceableGrid' ,CSML('referenceableGridDomain') ]} |
---|
720 | addchildren(self,children) |
---|
721 | csElement.__init__(self,**kwargs) |
---|
722 | |
---|
723 | class AlternatePointCoverage(AbstractDiscreteCoverage, csElement): |
---|
724 | def __init__(self, **kwargs): |
---|
725 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
726 | elems=['alternatePointDomain','rangeSet','coverageFunction'] |
---|
727 | addelems(self,elems) |
---|
728 | children={elems[0]:[GML('Point'),'Point', CSML('alternatePointDomain')], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
729 | addchildren(self,children) |
---|
730 | csElement.__init__(self,**kwargs) |
---|
731 | |
---|
732 | class ProfileCoverage(AbstractDiscreteCoverage, csElement): |
---|
733 | def __init__(self, **kwargs): |
---|
734 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
735 | elems=['profileDomain', 'rangeSet' ,'coverageFunction'] |
---|
736 | addelems(self,elems) |
---|
737 | children={elems[0]:[CSML('ProfileDomain'),'ProfileDomain' ,CSML('profileDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
738 | addchildren(self,children) |
---|
739 | csElement.__init__(self,**kwargs) |
---|
740 | |
---|
741 | class PointCoverage(AbstractDiscreteCoverage, csElement): |
---|
742 | def __init__(self, **kwargs): |
---|
743 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
744 | elems=['pointDomain','rangeSet', 'coverageFunction'] |
---|
745 | addelems(self,elems) |
---|
746 | children={elems[0]:[CSML('PointDomain'),'PointDomain' ,CSML('pointDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
747 | addchildren(self,children) |
---|
748 | csElement.__init__(self,**kwargs) |
---|
749 | |
---|
750 | class TimeSeries(AbstractGML, csElement): |
---|
751 | def __init__(self, **kwargs): |
---|
752 | AbstractGML.__init__(self,**kwargs) |
---|
753 | elems=['timePositionList'] |
---|
754 | addelems(self,elems) |
---|
755 | children={elems[0]:[CSML('timePositionList'), 'csString']} |
---|
756 | addchildren(self,children) |
---|
757 | csElement.__init__(self,**kwargs) |
---|
758 | |
---|
759 | class PointSeriesCoverage(AbstractDiscreteCoverage, csElement): |
---|
760 | def __init__(self, **kwargs): |
---|
761 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
762 | elems=['pointSeriesDomain','rangeSet','coverageFunction'] |
---|
763 | addelems(self,elems) |
---|
764 | children={elems[0]:[CSML('TimeSeries'),'TimeSeries' ,CSML('pointSeriesDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
765 | addchildren(self,children) |
---|
766 | csElement.__init__(self,**kwargs) |
---|
767 | |
---|
768 | class ProfileSeriesDomain(ReferenceableGrid, DomainSet, csElement): |
---|
769 | def __init__(self, **kwargs): |
---|
770 | DomainSet.__init__(self,**kwargs) |
---|
771 | ReferenceableGrid.__init__(self,**kwargs) |
---|
772 | children={} |
---|
773 | addchildren(self,children) |
---|
774 | csElement.__init__(self,**kwargs) |
---|
775 | |
---|
776 | class ProfileSeriesCoverage(AbstractDiscreteCoverage,csElement): |
---|
777 | def __init__(self, **kwargs): |
---|
778 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
779 | elems=['profileSeriesDomain', 'rangeSet', 'coverageFunction'] |
---|
780 | addelems(self,elems) |
---|
781 | children={elems[0]:[CSML('ProfileSeriesDomain'),'ProfileSeriesDomain' ,CSML('profileSeriesDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
782 | addchildren(self,children) |
---|
783 | csElement.__init__(self,**kwargs) |
---|
784 | |
---|
785 | class SectionDomain(ReferenceableGrid, DomainSet, csElement): |
---|
786 | def __init__(self, **kwargs): |
---|
787 | DomainSet.__init__(self,**kwargs) |
---|
788 | ReferenceableGrid.__init__(self,**kwargs) |
---|
789 | children={} |
---|
790 | addchildren(self,children) |
---|
791 | csElement.__init__(self,**kwargs) |
---|
792 | |
---|
793 | class SectionCoverage(AbstractDiscreteCoverage,csElement): |
---|
794 | def __init__(self, **kwargs): |
---|
795 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
796 | elems=['sectionDomain', 'rangeSet' , 'coverageFunction'] |
---|
797 | addelems(self,elems) |
---|
798 | children={elems[0]:[CSML('SectionDomain'),'SectionDomain' ,CSML('sectionDomain') ],elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
799 | addchildren(self,children) |
---|
800 | csElement.__init__(self,**kwargs) |
---|
801 | |
---|
802 | class TrajectoryDomain(ReferenceableGrid, DomainSet, csElement): |
---|
803 | def __init__(self, **kwargs): |
---|
804 | DomainSet.__init__(self,**kwargs) |
---|
805 | ReferenceableGrid.__init__(self,**kwargs) |
---|
806 | children={} |
---|
807 | addchildren(self,children) |
---|
808 | csElement.__init__(self,**kwargs) |
---|
809 | |
---|
810 | class TrajectoryCoverage(AbstractDiscreteCoverage,csElement): |
---|
811 | def __init__(self, **kwargs): |
---|
812 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
813 | elems=['trajectoryDomain', 'rangeSet', 'coverageFunction'] |
---|
814 | addelems(self,elems) |
---|
815 | children={elems[0]:[CSML('TrajectoryDomain'),'TrajectoryDomain' ,CSML('trajectoryDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
816 | addchildren(self,children) |
---|
817 | csElement.__init__(self,**kwargs) |
---|
818 | |
---|
819 | class ScanningRadarDomain(ReferenceableGrid, DomainSet, csElement): |
---|
820 | def __init__(self, **kwargs): |
---|
821 | DomainSet.__init__(self,**kwargs) |
---|
822 | ReferenceableGrid.__init__(self,**kwargs) |
---|
823 | children={} |
---|
824 | addchildren(self,children) |
---|
825 | csElement.__init__(self,**kwargs) |
---|
826 | |
---|
827 | class ScanningRadarCoverage(AbstractDiscreteCoverage,csElement): |
---|
828 | def __init__(self, **kwargs): |
---|
829 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
830 | elems=['scanningRadarDomain', 'rangeSet','coverageFunction'] |
---|
831 | addelems(self,elems) |
---|
832 | children={elems[0]:[CSML('ScanningRadarDomain'),'ScanningRadarDomain' ,CSML('scanningRadarDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
833 | addchildren(self,children) |
---|
834 | csElement.__init__(self,**kwargs) |
---|
835 | |
---|
836 | |
---|
837 | class GridSeriesDomain(ReferenceableGrid, csElement): |
---|
838 | def __init__(self, **kwargs): |
---|
839 | #DomainSet.__init__(self,**kwargs) |
---|
840 | ReferenceableGrid.__init__(self,**kwargs) |
---|
841 | children={} |
---|
842 | addchildren(self,children) |
---|
843 | csElement.__init__(self,**kwargs) |
---|
844 | |
---|
845 | class GridSeriesCoverage(AbstractDiscreteCoverage,csElement): |
---|
846 | def __init__(self, **kwargs): |
---|
847 | elems=['gridSeriesDomain', 'rangeSet', 'coverageFunction'] |
---|
848 | addelems(self,elems) |
---|
849 | children={elems[0]:[CSML('GridSeriesDomain'),'GridSeriesDomain' ,CSML('gridSeriesDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} |
---|
850 | addchildren(self,children) |
---|
851 | AbstractDiscreteCoverage.__init__(self,**kwargs) |
---|
852 | csElement.__init__(self,**kwargs) |
---|
853 | |
---|
854 | class AlternatePointFeature(AbstractFeature, csElement): |
---|
855 | def __init__(self, **kwargs): |
---|
856 | AbstractFeature.__init__(self,**kwargs) |
---|
857 | elems=['location', 'time', 'value','parameter'] |
---|
858 | addelems(self,elems) |
---|
859 | children={elems[0]:[CSML('location'), 'csString'],elems[1]:[CSML('time'), 'csString'], elems[2]:[CSML('AlternatePointCoverage'), 'AlternatePointCoverage', CSML('value')],elems[3]:[CSML('parameter'), 'Phenomenon']} |
---|
860 | addchildren(self,children) |
---|
861 | csElement.__init__(self,**kwargs) |
---|
862 | |
---|
863 | class DirectPositionList(SRSReferenceGroup, csElement): |
---|
864 | def __init__(self, **kwargs): |
---|
865 | SRSReferenceGroup.__init__(self,**kwargs) |
---|
866 | children=[] |
---|
867 | addchildren(self,children) |
---|
868 | csElement.__init__(self,**kwargs) |
---|
869 | |
---|
870 | class PointFeature(AbstractFeature, csElement): |
---|
871 | def __init__(self, **kwargs): |
---|
872 | AbstractFeature.__init__(self,**kwargs) |
---|
873 | elems=['location', 'time', 'value','parameter'] |
---|
874 | addelems(self,elems) |
---|
875 | children={elems[0]:[CSML('location'), 'DirectPositionList'],elems[1]:[CSML('time'), 'csString'], elems[2]:[CSML('PointCoverage'), 'PointCoverage', CSML('value')], elems[3]:[CSML('parameter'), 'Phenomenon']} |
---|
876 | addchildren(self,children) |
---|
877 | csElement.__init__(self,**kwargs) |
---|
878 | |
---|
879 | class PointCollectionFeature(AbstractFeature, csElement): |
---|
880 | def __init__(self, **kwargs): |
---|
881 | AbstractFeature.__init__(self,**kwargs) |
---|
882 | elems=['time', 'value', 'parameter'] |
---|
883 | addelems(self,elems) |
---|
884 | children={elems[0]:[CSML('time'), 'csString'], elems[1]:[CSML('MultiPointCoverage'), 'MultiPointCoverage', CSML('value')], elems[2]:[CSML('parameter'), 'Phenomenon']} |
---|
885 | addchildren(self,children) |
---|
886 | csElement.__init__(self,**kwargs) |
---|
887 | |
---|
888 | |
---|
889 | class PointSeriesFeature(AbstractFeature, csElement): |
---|
890 | def __init__(self, **kwargs): |
---|
891 | AbstractFeature.__init__(self,**kwargs) |
---|
892 | elems=['location','value','parameter'] |
---|
893 | addelems(self,elems) |
---|
894 | children={elems[0]:[CSML('location'), 'csString'], elems[1]:[CSML('PointSeriesCoverage'), 'PointSeriesCoverage', CSML('value')], elems[2]:[CSML('parameter'), 'Phenomenon']} |
---|
895 | addchildren(self,children) |
---|
896 | csElement.__init__(self,**kwargs) |
---|
897 | |
---|
898 | |
---|
899 | class GridFeature(AbstractFeature, csElement): |
---|
900 | def __init__(self, **kwargs): |
---|
901 | AbstractFeature.__init__(self,**kwargs) |
---|
902 | elems=['time', 'value', 'parameter'] |
---|
903 | addelems(self,elems) |
---|
904 | children={elems[0]:[CSML('time'), 'csString'], elems[1]:[CSML('ReferenceableGridCoverage'), 'ReferenceableGridCoverage', CSML('value')], elems[2]:[CSML('parameter'), 'Phenomenon']} |
---|
905 | addchildren(self,children) |
---|
906 | csElement.__init__(self,**kwargs) |
---|
907 | |
---|
908 | class GridSeriesFeature(AbstractFeature, csElement): |
---|
909 | def __init__(self, **kwargs): |
---|
910 | AbstractFeature.__init__(self,**kwargs) |
---|
911 | elems=['value','parameter'] |
---|
912 | addelems(self,elems) |
---|
913 | children={elems[0]:[CSML('GridSeriesCoverage'), 'GridSeriesCoverage', CSML('value')],elems[1]:[CSML('parameter'), 'Phenomenon']} |
---|
914 | addchildren(self,children) |
---|
915 | csElement.__init__(self,**kwargs) |
---|
916 | |
---|
917 | class ProfileFeature(AbstractFeature, csElement): |
---|
918 | def __init__(self, **kwargs): |
---|
919 | AbstractFeature.__init__(self,**kwargs) |
---|
920 | elems=['location', 'time','value', 'parameter'] |
---|
921 | addelems(self,elems) |
---|
922 | children={elems[0]:[CSML('location'), 'csString'],elems[1]:[CSML('time'), 'csString'], elems[2]:[CSML('ProfileCoverage'), 'ProfileCoverage', CSML('value')], elems[3]:[CSML('parameter'), 'Phenomenon']} |
---|
923 | addchildren(self,children) |
---|
924 | csElement.__init__(self,**kwargs) |
---|
925 | |
---|
926 | class ProfileSeriesFeature(AbstractFeature, csElement): |
---|
927 | def __init__(self, **kwargs): |
---|
928 | AbstractFeature.__init__(self,**kwargs) |
---|
929 | elems=['location', 'value', 'parameter'] |
---|
930 | addelems(self,elems) |
---|
931 | children={elems[0]:[CSML('location'), 'csString'], elems[1]:[CSML('ProfileSeriesCoverage'), 'ProfileSeriesCoverage', CSML('value')], elems[2]:[CSML('parameter'), 'Phenomenon']} |
---|
932 | addchildren(self,children) |
---|
933 | csElement.__init__(self,**kwargs) |
---|
934 | |
---|
935 | class RaggedProfileSeriesFeature(AbstractFeature, csElement): |
---|
936 | def __init__(self, **kwargs): |
---|
937 | AbstractFeature.__init__(self,**kwargs) |
---|
938 | elems=['location', 'profileLength', 'value', 'parameter'] |
---|
939 | addelems(self,elems) |
---|
940 | children={elems[0]:[CSML('location'), 'csString'], elems[1]:[CSML('profileLength'), 'csString'],elems[2]:[CSML('ProfileSeriesCoverage'), 'ProfileSeriesCoverage', CSML('value')], elems[3]:[CSML('parameter'), 'Phenomenon']} |
---|
941 | addchildren(self,children) |
---|
942 | csElement.__init__(self,**kwargs) |
---|
943 | |
---|
944 | class RaggedSectionFeature(AbstractFeature, csElement): |
---|
945 | def __init__(self, **kwargs): |
---|
946 | AbstractFeature.__init__(self,**kwargs) |
---|
947 | elems=['stationLocations', 'stationTimes', 'profileLength' 'value','parameter'] |
---|
948 | addelems(self,elems) |
---|
949 | children={elems[0]:[CSML('stationLocations'), 'csString'], elems[1]:[CSML('stationTimes'), 'csString'],elems[2]:[CSML('profileLength'),'csString'],elems[3]:[CSML('SectionCoverage'), 'SectionCoverage', CSML('value')], elems[4]:[CSML('parameter'), 'Phenomenon']} |
---|
950 | addchildren(self,children) |
---|
951 | csElement.__init__(self,**kwargs) |
---|
952 | |
---|
953 | class SectionFeature(AbstractFeature, csElement): |
---|
954 | def __init__(self, **kwargs): |
---|
955 | AbstractFeature.__init__(self,**kwargs) |
---|
956 | elems=['stationLocations', 'stationTimes','value', 'parameter'] |
---|
957 | addelems(self,elems) |
---|
958 | children={elems[0]:[CSML('stationLocations'), 'csString'], elems[1]:[CSML('stationTimes'), 'TimePositionList'],elems[2]:[CSML('SectionCoverage'), 'SectionCoverage', CSML('value')], elems[3]:[CSML('parameter'), 'Phenomenon']} |
---|
959 | addchildren(self,children) |
---|
960 | csElement.__init__(self,**kwargs) |
---|
961 | |
---|
962 | class ScanningRadarFeature(AbstractFeature, csElement): |
---|
963 | def __init__(self, **kwargs): |
---|
964 | AbstractFeature.__init__(self,**kwargs) |
---|
965 | elems=['elevation','value', 'parameter'] |
---|
966 | addelems(self,elems) |
---|
967 | children={elems[0]:[CSML('elevation'), 'csString'], elems[1]:[CSML('ScanningRadarCoverage'), 'ScanningRadarCoverage', CSML('value')], elems[2]:[CSML('parameter'), 'Phenomenon']} |
---|
968 | addchildren(self,children) |
---|
969 | csElement.__init__(self,**kwargs) |
---|
970 | |
---|
971 | |
---|
972 | class SwathFeature(AbstractFeature, csElement): |
---|
973 | def __init__(self, **kwargs): |
---|
974 | AbstractFeature.__init__(self,**kwargs) |
---|
975 | elems=['eqCrossLon', 'eqCrossTime', 'value', 'parameter'] |
---|
976 | addelems(self,elems) |
---|
977 | children={elems[0]:[CSML('eqCrossLon'), 'csString'],elems[1]:[CSML('eqCrossTime'), 'csString'], elems[2]:[CSML('ReferenceableGridCoverage'), 'ReferenceableGridCoverage', CSML('value')], elems[3]:[CSML('parameter'), 'Phenomenon']} |
---|
978 | addchildren(self,children) |
---|
979 | csElement.__init__(self,**kwargs) |
---|
980 | |
---|
981 | class TrajectoryFeature(AbstractFeature, csElement): |
---|
982 | def __init__(self, **kwargs): |
---|
983 | AbstractFeature.__init__(self,**kwargs) |
---|
984 | elems=['value', 'parameter'] |
---|
985 | addelems(self,elems) |
---|
986 | children={elems[0]:[CSML('TrajectoryCoverage'), 'TrajectoryCoverage', CSML('value')], elems[1]:[CSML('parameter'), 'Phenomenon']} |
---|
987 | addchildren(self,children) |
---|
988 | csElement.__init__(self,**kwargs) |
---|
989 | |
---|
990 | class FileList(AssociationAttributeGroup,csElement): |
---|
991 | def __init__(self,**kwargs): |
---|
992 | AssociationAttributeGroup.__init__(self,**kwargs) |
---|
993 | a=['id'] |
---|
994 | addatts(self,a) |
---|
995 | elems=['fileNames'] |
---|
996 | addelems(self,elems) |
---|
997 | children= {elems[0]:[CSML('fileNames'), 'csString']} |
---|
998 | addchildren(self,children) |
---|
999 | csElement.__init__(self,**kwargs) |
---|
1000 | |
---|
1001 | class FileExtract(ArrayDescriptor, csElement): |
---|
1002 | def __init__(self,**kwargs): |
---|
1003 | ArrayDescriptor.__init__(self,**kwargs) |
---|
1004 | elems=['fileName', 'fileList', 'fileListXLINK'] |
---|
1005 | addelems(self,elems) |
---|
1006 | children= {elems[0]:[CSML('fileName'), 'csString'], elems[1]:[CSML('FileList'), 'FileList', CSML('fileList')],elems[2]:[CSML('fileList'), 'csString']} |
---|
1007 | addchildren(self,children) |
---|
1008 | csElement.__init__(self,**kwargs) |
---|
1009 | |
---|
1010 | class NetCDFExtract(FileExtract, csElement): |
---|
1011 | def __init__(self,**kwargs): |
---|
1012 | FileExtract.__init__(self, **kwargs) |
---|
1013 | elems=['variableName'] |
---|
1014 | addelems(self,elems) |
---|
1015 | children={elems[0]:[CSML('variableName'), 'csString']} |
---|
1016 | addchildren(self,children) |
---|
1017 | csElement.__init__(self,**kwargs) |
---|
1018 | |
---|
1019 | class NASAAmesExtract(FileExtract, csElement): |
---|
1020 | def __init__(self,**kwargs): |
---|
1021 | FileExtract.__init__(self, **kwargs) |
---|
1022 | elems=['variableName', 'index'] |
---|
1023 | addelems(self,elems) |
---|
1024 | children={elems[0]:[CSML('variableName'), 'csString'],elems[1]:[CSML('index'),'csString']} |
---|
1025 | addchildren(self,children) |
---|
1026 | csElement.__init__(self,**kwargs) |
---|
1027 | |
---|
1028 | class RawFileExtract(FileExtract, csElement): |
---|
1029 | |
---|
1030 | # Note: Unlike the other file extracts, this sets a self.dataInterface |
---|
1031 | # attribute, which is used by the overridden getData to determine which |
---|
1032 | # Data Interface is used to read the file. This is necessary because the |
---|
1033 | # getUnknownDataInterface() method determines which DI to use based on |
---|
1034 | # filename suffix (raw files could be called anything) or by inspecting |
---|
1035 | # the file (raw files have no magic numbers or other markers that could |
---|
1036 | # be used to unequivocally determine the file type). |
---|
1037 | def __init__(self,**kwargs): |
---|
1038 | FileExtract.__init__(self, **kwargs) |
---|
1039 | elems=['endianness', 'fillValue'] |
---|
1040 | addelems(self,elems) |
---|
1041 | children={elems[0]:[CSML('endianness'), 'csString'],elems[1]:[CSML('fillValue'), 'csString']} |
---|
1042 | addchildren(self,children) |
---|
1043 | csElement.__init__(self,**kwargs) |
---|
1044 | self.dataInterface = csml.csmllibs.csmldataiface.RawFileInterface |
---|
1045 | |
---|
1046 | class ImageFileExtract(RawFileExtract, csElement): |
---|
1047 | def __init__(self,**kwargs): |
---|
1048 | FileExtract.__init__(self, **kwargs) |
---|
1049 | elems=['fillValue'] |
---|
1050 | addelems(self,elems) |
---|
1051 | children={elems[0]:[CSML('fillValue'), 'csString']} |
---|
1052 | addchildren(self,children) |
---|
1053 | csElement.__init__(self,**kwargs) |
---|
1054 | self.dataInterface = csml.csmllibs.csmldataiface.ImageFileInterface |
---|
1055 | |
---|
1056 | |
---|
1057 | class SimpleCondition(csElement): |
---|
1058 | '''from moles''' |
---|
1059 | def __init__(self,**kwargs): |
---|
1060 | addatts(self, []) |
---|
1061 | elems= ['dgAttributeAuthority', 'attrauthRole'] |
---|
1062 | addelems(self,elems) |
---|
1063 | children={elems[0]:[MOLES('dgAttributeAuthority'), 'csString'],elems[1]:[MOLES('attrauthRole'), 'csString']} |
---|
1064 | addchildren(self,children) |
---|
1065 | csElement.__init__(self, **kwargs) |
---|
1066 | |
---|
1067 | |
---|
1068 | class ComplexCondition(csElement): |
---|
1069 | '''from moles (stub class)''' |
---|
1070 | def __init__(self,**kwargs): |
---|
1071 | addatts(self, []) |
---|
1072 | elems= [] |
---|
1073 | addelems(self,elems) |
---|
1074 | children={} |
---|
1075 | addchildren(self,children) |
---|
1076 | csElement.__init__(self, **kwargs) |
---|
1077 | |
---|
1078 | class DgSecurityCondition(csElement): |
---|
1079 | '''from moles''' |
---|
1080 | def __init__(self,**kwargs): |
---|
1081 | addatts(self, []) |
---|
1082 | elems=['effect', 'conditionExplanationText', 'simpleCondition', 'complexCondition'] |
---|
1083 | addelems(self,elems) |
---|
1084 | children={elems[0]:[MOLES('effect'), 'csString'],elems[1]:[MOLES('conditionExplanationText'),'csString'],elems[2]:[MOLES('simpleCondition'), 'SimpleCondition'],elems[3]:[MOLES('complexCondition'), 'ComplexCondition']} |
---|
1085 | addchildren(self,children) |
---|
1086 | csElement.__init__(self,**kwargs) |
---|
1087 | |
---|
1088 | class AccessControlPolicy(csElement): |
---|
1089 | def __init__(self,**kwargs): |
---|
1090 | addatts(self,[]) |
---|
1091 | elems=['accessControlPolicyURL', 'accessControlPolicyText', 'dgSecurityCondition'] |
---|
1092 | addelems(self,elems) |
---|
1093 | children={elems[0]:[CSML('accessControlPolicyURL'), 'csString'],elems[1]:[CSML('accessControlPolicyText'),'csString'],elems[2]:[MOLES('dgSecurityCondition'), 'DgSecurityCondition']} |
---|
1094 | addchildren(self,children) |
---|
1095 | csElement.__init__(self,**kwargs) |
---|
1096 | |
---|
1097 | class CSMLStorageDescriptor(csElement): |
---|
1098 | def __init__(self,**kwargs): |
---|
1099 | addatts(self,[]) |
---|
1100 | elems=['descriptors'] |
---|
1101 | addelems(self,elems) |
---|
1102 | children={elems[0]:[[CSML('NetCDFExtract'),CSML('AggregatedArray'), CSML('RawFileExtract')], 'FileExtract', CSML('descriptor'),1]} |
---|
1103 | addchildren(self,children) |
---|
1104 | csElement.__init__(self,**kwargs) |
---|
1105 | |
---|
1106 | class CSMLFeatureCollection(AbstractFeatureCollection,csElement,): |
---|
1107 | def __init__(self,**kwargs): |
---|
1108 | AbstractFeatureCollection.__init__(self,**kwargs) |
---|
1109 | elems=['featureMembers'] |
---|
1110 | addelems(self,elems) |
---|
1111 | children={elems[0]:[[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', CSML('featureMember'),1]} |
---|
1112 | addchildren(self,children) |
---|
1113 | csElement.__init__(self,**kwargs) |
---|
1114 | def _getSubstitutionType(self,tag): |
---|
1115 | if tag==CSML('GridFeature'): |
---|
1116 | return 'GridFeature' |
---|
1117 | elif tag==CSML('GridSeriesFeature'): |
---|
1118 | return 'GridSeriesFeature' |
---|
1119 | elif tag==CSML('PointFeature'): |
---|
1120 | return 'PointFeature' |
---|
1121 | elif tag==CSML('TrajectoryFeature'): |
---|
1122 | return 'TrajectoryFeature' |
---|
1123 | elif tag==CSML('PointSeriesFeature'): |
---|
1124 | return 'PointSeriesFeature' |
---|
1125 | elif tag==CSML('ProfileFeature'): |
---|
1126 | return 'ProfileFeature' |
---|
1127 | elif tag==CSML('ProfileSeriesFeature'): |
---|
1128 | return 'ProfileSeriesFeature' |
---|
1129 | elif tag==CSML('RaggedProfileSeriesFeature'): |
---|
1130 | return 'RaggedProfileSeriesFeature' |
---|
1131 | elif tag==CSML('RaggedSectionFeature'): |
---|
1132 | return 'RaggedSectionFeature' |
---|
1133 | elif tag==CSML('SectionFeature'): |
---|
1134 | return 'SectionFeature' |
---|
1135 | elif tag==CSML('ScanningRadarFeature'): |
---|
1136 | return 'ScanningRadarFeature' |
---|
1137 | elif tag==CSML('AlternatePointFeature'): |
---|
1138 | return 'AlternatePointFeature' |
---|
1139 | else: return 'AbstractFeature' |
---|
1140 | def _getReverseSubsType(self, typename): |
---|
1141 | if typename== 'GridFeature': |
---|
1142 | return CSML('GridFeature') |
---|
1143 | elif typename == 'GridSeriesFeature': |
---|
1144 | return CSML('GridSeriesFeature') |
---|
1145 | elif typename == 'PointSeriesFeature': |
---|
1146 | return CSML('PointSeriesFeature') |
---|
1147 | elif typename == 'ProfileFeature': |
---|
1148 | return CSML('ProfileFeature') |
---|
1149 | elif typename == 'ProfileSeriesFeature': |
---|
1150 | return CSML('ProfileSeriesFeature') |
---|
1151 | elif typename == 'SectionFeature': |
---|
1152 | return CSML('SectionFeature') |
---|
1153 | elif typename == 'ScanningRadarFeature': |
---|
1154 | return CSML('ScanningRadarFeature') |
---|
1155 | elif typename == 'RaggedSectionFeature': |
---|
1156 | return CSML('RaggedSectionFeature') |
---|
1157 | elif typename == 'RaggedProfileSeriesFeature': |
---|
1158 | return CSML('RaggedProfileSeriesFeature') |
---|
1159 | elif typename == 'PointFeature': |
---|
1160 | return CSML('PointFeature') |
---|
1161 | elif typename == 'TrajectoryFeature': |
---|
1162 | return CSML('TrajectoryFeature') |
---|
1163 | elif typename == 'AlternatePointFeature': |
---|
1164 | return CSML('AlternatePointFeature') |
---|
1165 | else: return CSML('AbstractFeature') |
---|
1166 | |
---|
1167 | |
---|
1168 | class Dataset(csElement): |
---|
1169 | ''' Dataset class, needed as root of tree''' |
---|
1170 | def __init__(self, **kwargs): |
---|
1171 | a=['id'] |
---|
1172 | addatts(self,a) |
---|
1173 | elems=['accessControlPolicy','featureCollection','storageDescriptor'] |
---|
1174 | addelems(self,elems) |
---|
1175 | children = {elems[0]:[CSML('AccessControlPolicy') ,'AccessControlPolicy'], elems[1]:[CSML('CSMLFeatureCollection') ,'CSMLFeatureCollection'],elems[2]:[CSML('CSMLStorageDescriptor'), 'CSMLStorageDescriptor']} |
---|
1176 | addchildren(self,children) |
---|
1177 | csElement.__init__(self,**kwargs) |
---|
1178 | |
---|
1179 | def toXML(self): |
---|
1180 | csmlfrag=ET.Element(CSML('Dataset')) |
---|
1181 | csElement.toXML(self, csmlfrag) |
---|
1182 | return csmlfrag |
---|
1183 | #def _getSubstitutionType(self,tag): |
---|
1184 | #if tag==CSML('NetCDFExtract'): |
---|
1185 | #return 'NetCDFExtract' |
---|
1186 | #elif tag==CSML('NASAAmesExtract'): |
---|
1187 | #return 'NASAAmesExtract' |
---|
1188 | #else: return 'ArrayDescriptor' |
---|
1189 | #def _getReverseSubsType(self, typename): |
---|
1190 | #if typename== 'NetCDFExtract': |
---|
1191 | #return CSML('NetCDFExtract') |
---|
1192 | #elif typename == 'NASAAmesExtract': |
---|
1193 | #return CSML('NASAAmesExtract') |
---|
1194 | #else: return CSML('ArrayDescriptor') |
---|
1195 | |
---|
1196 | return typename |
---|
1197 | |
---|
1198 | |
---|
1199 | def main(): |
---|
1200 | '''round trip for testing purposes:''' |
---|
1201 | import parser_extra |
---|
1202 | |
---|
1203 | print '\n' |
---|
1204 | tree=ET.ElementTree(file='../rsg_example_csml-2.0.xml') |
---|
1205 | ds=Dataset() |
---|
1206 | ds.fromXML(tree.getroot()) |
---|
1207 | csmltree=ds.toXML() |
---|
1208 | |
---|
1209 | csmlout=parser_extra.PrettyPrint(csmltree) |
---|
1210 | csmlout=parser_extra.removeInlineNS(csmlout) |
---|
1211 | print '\n %s'% csmlout |
---|
1212 | #for member in ds.featureCollection.members: |
---|
1213 | #print dir(member.value) |
---|
1214 | |
---|
1215 | |
---|
1216 | if __name__=='__main__': |
---|
1217 | main() |
---|