forked from swtools/WOFpy
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathWaterML.py
More file actions
6913 lines (6775 loc) · 336 KB
/
Copy pathWaterML.py
File metadata and controls
6913 lines (6775 loc) · 336 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#
# Generated Tue Feb 15 14:13:42 2011 by generateDS.py version 2.3b.
#
from __future__ import (absolute_import, division, print_function)
from six import string_types
import sys
import getopt
import re as re_
etree_ = None
Verbose_import_ = False
( XMLParser_import_none, XMLParser_import_lxml,
XMLParser_import_elementtree
) = range(3)
XMLParser_import_library = None
try:
# lxml
from lxml import etree as etree_
XMLParser_import_library = XMLParser_import_lxml
if Verbose_import_:
print("running with lxml.etree")
except ImportError:
try:
# cElementTree from Python 2.5+
import xml.etree.cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree on Python 2.5+")
except ImportError:
try:
# ElementTree from Python 2.5+
import xml.etree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree on Python 2.5+")
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree")
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree")
except ImportError:
raise ImportError("Failed to import ElementTree from any known place")
class GeneratedsSuper(object):
def gds_format_string(self, input_data, input_name=''):
return input_data
def gds_format_integer(self, input_data, input_name=''):
return '%d' % input_data
def gds_format_float(self, input_data, input_name=''):
return "{0}".format(input_data)
def gds_format_double(self, input_data, input_name=''):
return "{0}".format(input_data)
def gds_format_boolean(self, input_data, input_name=''):
return '%s' % input_data
def gds_str_lower(self, instring):
return instring.lower()
#
# Globals
#
ExternalEncoding = 'utf-8'
Tag_pattern_ = re_.compile(r'({.*})?(.*)')
STRING_CLEANUP_PAT = re_.compile(r"[\n\r\s]+")
#
# Support/utility functions.
#
def showIndent(outfile, level):
for idx in range(level):
outfile.write(u' ')
def quote_xml(inStr):
if not inStr:
return ''
s1 = (isinstance(inStr, str) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
return s1
def quote_attrib(inStr):
s1 = (isinstance(inStr, str) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
if '"' in s1:
if "'" in s1:
s1 = '"%s"' % s1.replace('"', """)
else:
s1 = "'%s'" % s1
else:
s1 = '"%s"' % s1
return s1
def quote_python(inStr):
s1 = inStr
if s1.find("'") == -1:
if s1.find('\n') == -1:
return "'%s'" % s1
else:
return "'''%s'''" % s1
else:
if s1.find('"') != -1:
s1 = s1.replace('"', '\\"')
if s1.find('\n') == -1:
return '"%s"' % s1
else:
return '"""%s"""' % s1
def get_all_text_(node):
if node.text is not None:
text = node.text
else:
text = ''
for child in node:
if child.tail is not None:
text += child.tail
return text
class GDSParseError(Exception):
pass
def raise_parse_error(node, msg):
if XMLParser_import_library == XMLParser_import_lxml:
msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, )
else:
msg = '%s (element %s)' % (msg, node.tag, )
raise GDSParseError(msg)
class MixedContainer:
# Constants for category:
CategoryNone = 0
CategoryText = 1
CategorySimple = 2
CategoryComplex = 3
# Constants for content_type:
TypeNone = 0
TypeText = 1
TypeString = 2
TypeInteger = 3
TypeFloat = 4
TypeDecimal = 5
TypeDouble = 6
TypeBoolean = 7
def __init__(self, category, content_type, name, value):
self.category = category
self.content_type = content_type
self.name = name
self.value = value
def getCategory(self):
return self.category
def getContenttype(self, content_type):
return self.content_type
def getValue(self):
return self.value
def getName(self):
return self.name
def export(self, outfile, level, name, namespace):
if self.category == MixedContainer.CategoryText:
# Prevent exporting empty content as empty lines.
if self.value.strip():
outfile.write(self.value)
elif self.category == MixedContainer.CategorySimple:
self.exportSimple(outfile, level, name)
else: # category == MixedContainer.CategoryComplex
self.value.export(outfile, level, namespace,name)
def exportSimple(self, outfile, level, name):
if self.content_type == MixedContainer.TypeString:
outfile.write(u'<%s>%s</%s>' % (self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeInteger or \
self.content_type == MixedContainer.TypeBoolean:
outfile.write(u'<%s>%d</%s>' % (self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeFloat or \
self.content_type == MixedContainer.TypeDecimal:
outfile.write(u'<%s>%f</%s>' % (self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeDouble:
outfile.write(u'<%s>%g</%s>' % (self.name, self.value, self.name))
def exportLiteral(self, outfile, level, name):
if self.category == MixedContainer.CategoryText:
showIndent(outfile, level)
outfile.write(u'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
(self.category, self.content_type, self.name, self.value))
elif self.category == MixedContainer.CategorySimple:
showIndent(outfile, level)
outfile.write(u'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
(self.category, self.content_type, self.name, self.value))
else: # category == MixedContainer.CategoryComplex
showIndent(outfile, level)
outfile.write(u'model_.MixedContainer(%d, %d, "%s",\n' % \
(self.category, self.content_type, self.name,))
self.value.exportLiteral(outfile, level + 1)
showIndent(outfile, level)
outfile.write(u')\n')
class MemberSpec_(object):
def __init__(self, name='', data_type='', container=0):
self.name = name
self.data_type = data_type
self.container = container
def set_name(self, name): self.name = name
def get_name(self): return self.name
def set_data_type(self, data_type): self.data_type = data_type
def get_data_type_chain(self): return self.data_type
def get_data_type(self):
if isinstance(self.data_type, list):
if len(self.data_type) > 0:
return self.data_type[-1]
else:
return 'xs:string'
else:
return self.data_type
def set_container(self, container): self.container = container
def get_container(self): return self.container
def _cast(typ, value):
if typ is None or value is None:
return value
return typ(value)
#
# Data representation classes.
#
class siteCode(GeneratedsSuper):
"""A <siteCode> is an identifier that this site is referred to
as. This Code used by organization that collects the data to
identify the site. A siteCode has a reference to it's source or
network as the @network. For waterWebServices, a site/location
is the network plus the value of the sitecode, eg
'@network:siteCode' siteCode identifiers often change, so
multiple siteCode elements are allowed There may be multiple
siteCode elements. Only one should be labeled as the default
using @defaultID (set attribute defaultID=true) Multiple
siteCode elements can utilize different observation networks may
refer to the same site with different identifiers. True if this
is the main identifier that this service uses to access this
site. default value is false. The abbreviation for the
datasource or observation network that this site code is
associated with. A siteCode has a reference to it's source or
network as the @network. For waterWebServices, a site/location
is the network plus the value of the sitecode, eg
'@network:siteCode'An internal numeric identifier of the site.
Code used to differentiate sites in a datasource. Agency codes
are specific to a data source, and are not required nor do they
need to be understood by a web service client.optional name to
provide more detail about an agency code"""
subclass = None
superclass = None
def __init__(self, agencyCode=None, defaultId=None, siteID=None, network=None, agencyName=None, valueOf_=None):
self.agencyCode = _cast(None, agencyCode)
self.defaultId = _cast(bool, defaultId)
self.siteID = _cast(None, siteID)
self.network = _cast(None, network)
self.agencyName = _cast(None, agencyName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if siteCode.subclass:
return siteCode.subclass(*args_, **kwargs_)
else:
return siteCode(*args_, **kwargs_)
factory = staticmethod(factory)
def get_agencyCode(self): return self.agencyCode
def set_agencyCode(self, agencyCode): self.agencyCode = agencyCode
def get_defaultId(self): return self.defaultId
def set_defaultId(self, defaultId): self.defaultId = defaultId
def get_siteID(self): return self.siteID
def set_siteID(self, siteID): self.siteID = siteID
def get_network(self): return self.network
def set_network(self, network): self.network = network
def get_agencyName(self): return self.agencyName
def set_agencyName(self, agencyName): self.agencyName = agencyName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def export(self, outfile, level, namespace_='', name_='siteCode', namespacedef_=''):
showIndent(outfile, level)
outfile.write(u'<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
self.exportAttributes(outfile, level, [], namespace_, name_='siteCode')
if self.hasContent_():
outfile.write(u'>')
outfile.write(u'%s' % self.valueOf_)
self.exportChildren(outfile, level + 1, namespace_, name_)
outfile.write(u'</%s%s>\n' % (namespace_, name_))
else:
outfile.write(u'/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='siteCode'):
if self.agencyCode is not None and 'agencyCode' not in already_processed:
already_processed.append('agencyCode')
outfile.write(u' agencyCode=%s' % (self.gds_format_string(quote_attrib(self.agencyCode), input_name='agencyCode'), ))
if self.defaultId is not None and 'defaultId' not in already_processed:
already_processed.append('defaultId')
outfile.write(u' defaultId="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.defaultId)), input_name='defaultId'))
if self.siteID is not None and 'siteID' not in already_processed:
already_processed.append('siteID')
outfile.write(u' siteID=%s' % (self.gds_format_string(quote_attrib(self.siteID), input_name='siteID'), ))
outfile.write(u' network=%s' % (self.gds_format_string(quote_attrib(self.network), input_name='network'), ))
if self.agencyName is not None and 'agencyName' not in already_processed:
already_processed.append('agencyName')
outfile.write(u' agencyName=%s' % (self.gds_format_string(quote_attrib(self.agencyName), input_name='agencyName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='siteCode'):
pass
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='siteCode'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write(u'valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.agencyCode is not None and 'agencyCode' not in already_processed:
already_processed.append('agencyCode')
showIndent(outfile, level)
outfile.write(u'agencyCode = "%s",\n' % (self.agencyCode,))
if self.defaultId is not None and 'defaultId' not in already_processed:
already_processed.append('defaultId')
showIndent(outfile, level)
outfile.write(u'defaultId = %s,\n' % (self.defaultId,))
if self.siteID is not None and 'siteID' not in already_processed:
already_processed.append('siteID')
showIndent(outfile, level)
outfile.write(u'siteID = "%s",\n' % (self.siteID,))
if self.network is not None and 'network' not in already_processed:
already_processed.append('network')
showIndent(outfile, level)
outfile.write(u'network = "%s",\n' % (self.network,))
if self.agencyName is not None and 'agencyName' not in already_processed:
already_processed.append('agencyName')
showIndent(outfile, level)
outfile.write(u'agencyName = "%s",\n' % (self.agencyName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
self.buildAttributes(node, node.attrib, [])
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = attrs.get('agencyCode')
if value is not None and 'agencyCode' not in already_processed:
already_processed.append('agencyCode')
self.agencyCode = value
value = attrs.get('defaultId')
if value is not None and 'defaultId' not in already_processed:
already_processed.append('defaultId')
if value in ('true', '1'):
self.defaultId = True
elif value in ('false', '0'):
self.defaultId = False
else:
raise_parse_error(node, 'Bad boolean attribute')
value = attrs.get('siteID')
if value is not None and 'siteID' not in already_processed:
already_processed.append('siteID')
self.siteID = value
value = attrs.get('network')
if value is not None and 'network' not in already_processed:
already_processed.append('network')
self.network = value
value = attrs.get('agencyName')
if value is not None and 'agencyName' not in already_processed:
already_processed.append('agencyName')
self.agencyName = value
def buildChildren(self, child_, nodeName_, from_subclass=False):
pass
# end class siteCode
class geoLocation(GeneratedsSuper):
"""The geoLocation speficies the details of the geographic location. It
contains two portions, a geographic locaiton
&lt;geogLocation&gt;, and a local location
&lt;localSiteXY&gt;. In order to be discovered
spatially, geogLocation is required. The geogLocation can be of
GeogLocationType, which at present is either a latLonPoint or a
latLongBox. There may be multiple localSiteXY, which might be
used by data sources to provide other coordinated system
information, like UTM and State Plane coordinates."""
subclass = None
superclass = None
def __init__(self, geogLocation=None, localSiteXY=None):
self.geogLocation = geogLocation
if localSiteXY is None:
self.localSiteXY = []
else:
self.localSiteXY = localSiteXY
def factory(*args_, **kwargs_):
if geoLocation.subclass:
return geoLocation.subclass(*args_, **kwargs_)
else:
return geoLocation(*args_, **kwargs_)
factory = staticmethod(factory)
def get_geogLocation(self): return self.geogLocation
def set_geogLocation(self, geogLocation): self.geogLocation = geogLocation
def get_localSiteXY(self): return self.localSiteXY
def set_localSiteXY(self, localSiteXY): self.localSiteXY = localSiteXY
def add_localSiteXY(self, value): self.localSiteXY.append(value)
def insert_localSiteXY(self, index, value): self.localSiteXY[index] = value
def export(self, outfile, level, namespace_='', name_='geoLocation', namespacedef_=''):
showIndent(outfile, level)
outfile.write(u'<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
self.exportAttributes(outfile, level, [], namespace_, name_='geoLocation')
if self.hasContent_():
outfile.write(u'>\n')
self.exportChildren(outfile, level + 1, namespace_, name_)
showIndent(outfile, level)
outfile.write(u'</%s%s>\n' % (namespace_, name_))
else:
outfile.write(u'/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='geoLocation'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='geoLocation'):
if self.geogLocation:
self.geogLocation.export(outfile, level, namespace_, name_='geogLocation', )
for localSiteXY_ in self.localSiteXY:
localSiteXY_.export(outfile, level, namespace_, name_='localSiteXY')
def hasContent_(self):
if (
self.geogLocation is not None or
self.localSiteXY
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='geoLocation'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.geogLocation is not None:
showIndent(outfile, level)
outfile.write(u'geogLocation=model_.GeogLocationType(\n')
self.geogLocation.exportLiteral(outfile, level, name_='geogLocation')
showIndent(outfile, level)
outfile.write(u'),\n')
showIndent(outfile, level)
outfile.write(u'localSiteXY=[\n')
level += 1
for localSiteXY_ in self.localSiteXY:
showIndent(outfile, level)
outfile.write(u'model_.localSiteXY(\n')
localSiteXY_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
def build(self, node):
self.buildAttributes(node, node.attrib, [])
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, nodeName_, from_subclass=False):
if nodeName_ == 'geogLocation':
obj_ = GeogLocationType.factory()
obj_.build(child_)
self.set_geogLocation(obj_)
elif nodeName_ == 'localSiteXY':
obj_ = localSiteXY.factory()
obj_.build(child_)
self.localSiteXY.append(obj_)
# end class geoLocation
class localSiteXY(GeneratedsSuper):
"""Site information can contain one or more other locations using the
localSiteXY element. The projection string should be stored in
projectionInformation. Lat or Northing = Y Lon or Easting = X
Spatial Reference System of the local coordinates. This should
use the PROJ4 projection string standard"""
subclass = None
superclass = None
def __init__(self, projectionInformation=None, X=None, Y=None, Z=None, note=None):
self.projectionInformation = _cast(None, projectionInformation)
self.X = X
self.Y = Y
self.Z = Z
if note is None:
self.note = []
else:
self.note = note
def factory(*args_, **kwargs_):
if localSiteXY.subclass:
return localSiteXY.subclass(*args_, **kwargs_)
else:
return localSiteXY(*args_, **kwargs_)
factory = staticmethod(factory)
def get_X(self): return self.X
def set_X(self, X): self.X = X
def get_Y(self): return self.Y
def set_Y(self, Y): self.Y = Y
def get_Z(self): return self.Z
def set_Z(self, Z): self.Z = Z
def get_note(self): return self.note
def set_note(self, note): self.note = note
def add_note(self, value): self.note.append(value)
def insert_note(self, index, value): self.note[index] = value
def get_projectionInformation(self): return self.projectionInformation
def set_projectionInformation(self, projectionInformation): self.projectionInformation = projectionInformation
def export(self, outfile, level, namespace_='', name_='localSiteXY', namespacedef_=''):
showIndent(outfile, level)
outfile.write(u'<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
self.exportAttributes(outfile, level, [], namespace_, name_='localSiteXY')
if self.hasContent_():
outfile.write(u'>\n')
self.exportChildren(outfile, level + 1, namespace_, name_)
showIndent(outfile, level)
outfile.write(u'</%s%s>\n' % (namespace_, name_))
else:
outfile.write(u'/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='localSiteXY'):
if self.projectionInformation is not None and 'projectionInformation' not in already_processed:
already_processed.append('projectionInformation')
outfile.write(u' projectionInformation=%s' % (self.gds_format_string(quote_attrib(self.projectionInformation), input_name='projectionInformation'), ))
def exportChildren(self, outfile, level, namespace_='', name_='localSiteXY'):
if self.X is not None:
showIndent(outfile, level)
outfile.write(u'<%sX>%s</%sX>\n' % (namespace_, self.gds_format_string(quote_xml(self.X), input_name='X'), namespace_))
if self.Y is not None:
showIndent(outfile, level)
outfile.write(u'<%sY>%s</%sY>\n' % (namespace_, self.gds_format_string(quote_xml(self.Y), input_name='Y'), namespace_))
if self.Z is not None:
showIndent(outfile, level)
outfile.write(u'<%sZ>%s</%sZ>\n' % (namespace_, self.gds_format_string(quote_xml(self.Z), input_name='Z'), namespace_))
for note_ in self.note:
note_.export(outfile, level, namespace_, name_='note')
def hasContent_(self):
if (
self.X is not None or
self.Y is not None or
self.Z is not None or
self.note
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='localSiteXY'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.projectionInformation is not None and 'projectionInformation' not in already_processed:
already_processed.append('projectionInformation')
showIndent(outfile, level)
outfile.write(u'projectionInformation = "%s",\n' % (self.projectionInformation,))
def exportLiteralChildren(self, outfile, level, name_):
if self.X is not None:
showIndent(outfile, level)
outfile.write(u'X=%s,\n' % quote_python(self.X))
if self.Y is not None:
showIndent(outfile, level)
outfile.write(u'Y=%s,\n' % quote_python(self.Y))
if self.Z is not None:
showIndent(outfile, level)
outfile.write(u'Z=%s,\n' % quote_python(self.Z))
showIndent(outfile, level)
outfile.write(u'note=[\n')
level += 1
for note_ in self.note:
showIndent(outfile, level)
outfile.write(u'model_.NoteType(\n')
note_.exportLiteral(outfile, level, name_='NoteType')
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
def build(self, node):
self.buildAttributes(node, node.attrib, [])
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = attrs.get('projectionInformation')
if value is not None and 'projectionInformation' not in already_processed:
already_processed.append('projectionInformation')
self.projectionInformation = value
def buildChildren(self, child_, nodeName_, from_subclass=False):
if nodeName_ == 'X':
X_ = child_.text
self.X = X_
elif nodeName_ == 'Y':
Y_ = child_.text
self.Y = Y_
elif nodeName_ == 'Z':
Z_ = child_.text
self.Z = Z_
elif nodeName_ == 'note':
obj_ = NoteType.factory()
obj_.build(child_)
self.note.append(obj_)
# end class localSiteXY
class TsValuesSingleVariableType(GeneratedsSuper):
"""TsValuesSingleVariableTypea aggregates the list of values and
associated metadata. It is the values element in the
timeSereisResponse Attributes are optional, but use @count is
encouraged. The atrributes @unitsAreConverted,
@untsCode,@unitsAbbreviation, and @unitsType were originally
included to allow for translation from orignal variable units.
Thier use is not encouraged. Get unit information from the
Variable element.If a webservice has transformed the time zone
from the original data.the measurment units of the value
elements in this values element True if a webservice has
transformed the data from the original units."""
subclass = None
superclass = None
def __init__(self, count=None, unitsAbbreviation=None, unitsType=None, timeZoneShiftApplied=None, unitsAreConverted=False, unitsCode=None, value=None, qualifier=None, qualityControlLevel=None, method=None, source=None, offset=None):
self.count = _cast(int, count)
self.unitsAbbreviation = _cast(None, unitsAbbreviation)
self.unitsType = _cast(None, unitsType)
self.timeZoneShiftApplied = _cast(bool, timeZoneShiftApplied)
self.unitsAreConverted = _cast(bool, unitsAreConverted)
self.unitsCode = _cast(None, unitsCode)
if value is None:
self.value = []
else:
self.value = value
if qualifier is None:
self.qualifier = []
else:
self.qualifier = qualifier
if qualityControlLevel is None:
self.qualityControlLevel = []
else:
self.qualityControlLevel = qualityControlLevel
if method is None:
self.method = []
else:
self.method = method
if source is None:
self.source = []
else:
self.source = source
if offset is None:
self.offset = []
else:
self.offset = offset
def factory(*args_, **kwargs_):
if TsValuesSingleVariableType.subclass:
return TsValuesSingleVariableType.subclass(*args_, **kwargs_)
else:
return TsValuesSingleVariableType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_value(self): return self.value
def set_value(self, value): self.value = value
def add_value(self, value): self.value.append(value)
def insert_value(self, index, value): self.value[index] = value
def get_qualifier(self): return self.qualifier
def set_qualifier(self, qualifier): self.qualifier = qualifier
def add_qualifier(self, value): self.qualifier.append(value)
def insert_qualifier(self, index, value): self.qualifier[index] = value
def get_qualityControlLevel(self): return self.qualityControlLevel
def set_qualityControlLevel(self, qualityControlLevel): self.qualityControlLevel = qualityControlLevel
def add_qualityControlLevel(self, value): self.qualityControlLevel.append(value)
def insert_qualityControlLevel(self, index, value): self.qualityControlLevel[index] = value
def get_method(self): return self.method
def set_method(self, method): self.method = method
def add_method(self, value): self.method.append(value)
def insert_method(self, index, value): self.method[index] = value
def get_source(self): return self.source
def set_source(self, source): self.source = source
def add_source(self, value): self.source.append(value)
def insert_source(self, index, value): self.source[index] = value
def get_offset(self): return self.offset
def set_offset(self, offset): self.offset = offset
def add_offset(self, value): self.offset.append(value)
def insert_offset(self, index, value): self.offset[index] = value
def get_count(self): return self.count
def set_count(self, count): self.count = count
def get_unitsAbbreviation(self): return self.unitsAbbreviation
def set_unitsAbbreviation(self, unitsAbbreviation): self.unitsAbbreviation = unitsAbbreviation
def get_unitsType(self): return self.unitsType
def set_unitsType(self, unitsType): self.unitsType = unitsType
def validate_UnitsTypeEnum(self, value):
# Validate type UnitsTypeEnum, a restriction on xsi:string.
pass
def get_timeZoneShiftApplied(self): return self.timeZoneShiftApplied
def set_timeZoneShiftApplied(self, timeZoneShiftApplied): self.timeZoneShiftApplied = timeZoneShiftApplied
def get_unitsAreConverted(self): return self.unitsAreConverted
def set_unitsAreConverted(self, unitsAreConverted): self.unitsAreConverted = unitsAreConverted
def get_unitsCode(self): return self.unitsCode
def set_unitsCode(self, unitsCode): self.unitsCode = unitsCode
def export(self, outfile, level, namespace_='', name_='TsValuesSingleVariableType', namespacedef_=''):
showIndent(outfile, level)
outfile.write(u'<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
self.exportAttributes(outfile, level, [], namespace_, name_='TsValuesSingleVariableType')
if self.hasContent_():
outfile.write(u'>\n')
self.exportChildren(outfile, level + 1, namespace_, name_)
showIndent(outfile, level)
outfile.write(u'</%s%s>\n' % (namespace_, name_))
else:
outfile.write(u'/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='TsValuesSingleVariableType'):
if self.count is not None and 'count' not in already_processed:
already_processed.append('count')
outfile.write(u' count="%s"' % self.gds_format_integer(self.count, input_name='count'))
if self.unitsAbbreviation is not None and 'unitsAbbreviation' not in already_processed:
already_processed.append('unitsAbbreviation')
outfile.write(u' unitsAbbreviation=%s' % (self.gds_format_string(quote_attrib(self.unitsAbbreviation), input_name='unitsAbbreviation'), ))
if self.unitsType is not None and 'unitsType' not in already_processed:
already_processed.append('unitsType')
outfile.write(u' unitsType=%s' % (quote_attrib(self.unitsType), ))
if self.timeZoneShiftApplied is not None and 'timeZoneShiftApplied' not in already_processed:
already_processed.append('timeZoneShiftApplied')
outfile.write(u' timeZoneShiftApplied="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.timeZoneShiftApplied)), input_name='timeZoneShiftApplied'))
if self.unitsAreConverted is not None and 'unitsAreConverted' not in already_processed:
already_processed.append('unitsAreConverted')
outfile.write(u' unitsAreConverted="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.unitsAreConverted)), input_name='unitsAreConverted'))
if self.unitsCode is not None and 'unitsCode' not in already_processed:
already_processed.append('unitsCode')
outfile.write(u' unitsCode=%s' % (self.gds_format_string(quote_attrib(self.unitsCode), input_name='unitsCode'), ))
def exportChildren(self, outfile, level, namespace_='', name_='TsValuesSingleVariableType'):
for value_ in self.value:
value_.export(outfile, level, namespace_, name_='value')
for qualifier_ in self.qualifier:
qualifier_.export(outfile, level, namespace_, name_='qualifier')
for qualityControlLevel_ in self.qualityControlLevel:
qualityControlLevel_.export(outfile, level, namespace_, name_='qualityControlLevel')
for method_ in self.method:
method_.export(outfile, level, namespace_, name_='method')
for source_ in self.source:
source_.export(outfile, level, namespace_, name_='source')
for offset_ in self.offset:
offset_.export(outfile, level, namespace_, name_='offset')
def hasContent_(self):
if (
self.value or
self.qualifier or
self.qualityControlLevel or
self.method or
self.source or
self.offset
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='TsValuesSingleVariableType'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.count is not None and 'count' not in already_processed:
already_processed.append('count')
showIndent(outfile, level)
outfile.write(u'count = %d,\n' % (self.count,))
if self.unitsAbbreviation is not None and 'unitsAbbreviation' not in already_processed:
already_processed.append('unitsAbbreviation')
showIndent(outfile, level)
outfile.write(u'unitsAbbreviation = "%s",\n' % (self.unitsAbbreviation,))
if self.unitsType is not None and 'unitsType' not in already_processed:
already_processed.append('unitsType')
showIndent(outfile, level)
outfile.write(u'unitsType = "%s",\n' % (self.unitsType,))
if self.timeZoneShiftApplied is not None and 'timeZoneShiftApplied' not in already_processed:
already_processed.append('timeZoneShiftApplied')
showIndent(outfile, level)
outfile.write(u'timeZoneShiftApplied = %s,\n' % (self.timeZoneShiftApplied,))
if self.unitsAreConverted is not None and 'unitsAreConverted' not in already_processed:
already_processed.append('unitsAreConverted')
showIndent(outfile, level)
outfile.write(u'unitsAreConverted = %s,\n' % (self.unitsAreConverted,))
if self.unitsCode is not None and 'unitsCode' not in already_processed:
already_processed.append('unitsCode')
showIndent(outfile, level)
outfile.write(u'unitsCode = "%s",\n' % (self.unitsCode,))
def exportLiteralChildren(self, outfile, level, name_):
showIndent(outfile, level)
outfile.write(u'value=[\n')
level += 1
for value_ in self.value:
showIndent(outfile, level)
outfile.write(u'model_.ValueSingleVariable(\n')
value_.exportLiteral(outfile, level, name_='ValueSingleVariable')
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
showIndent(outfile, level)
outfile.write(u'qualifier=[\n')
level += 1
for qualifier_ in self.qualifier:
showIndent(outfile, level)
outfile.write(u'model_.qualifier(\n')
qualifier_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
showIndent(outfile, level)
outfile.write(u'qualityControlLevel=[\n')
level += 1
for qualityControlLevel_ in self.qualityControlLevel:
showIndent(outfile, level)
outfile.write(u'model_.qualityControlLevel(\n')
qualityControlLevel_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
showIndent(outfile, level)
outfile.write(u'method=[\n')
level += 1
for method_ in self.method:
showIndent(outfile, level)
outfile.write(u'model_.MethodType(\n')
method_.exportLiteral(outfile, level, name_='MethodType')
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
showIndent(outfile, level)
outfile.write(u'source=[\n')
level += 1
for source_ in self.source:
showIndent(outfile, level)
outfile.write(u'model_.SourceType(\n')
source_.exportLiteral(outfile, level, name_='SourceType')
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
showIndent(outfile, level)
outfile.write(u'offset=[\n')
level += 1
for offset_ in self.offset:
showIndent(outfile, level)
outfile.write(u'model_.OffsetType(\n')
offset_.exportLiteral(outfile, level, name_='OffsetType')
showIndent(outfile, level)
outfile.write(u'),\n')
level -= 1
showIndent(outfile, level)
outfile.write(u'],\n')
def build(self, node):
self.buildAttributes(node, node.attrib, [])
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = attrs.get('count')
if value is not None and 'count' not in already_processed:
already_processed.append('count')
try:
self.count = int(value)
except ValueError as exp:
raise_parse_error(node, 'Bad integer attribute: %s' % exp)
if self.count < 0:
raise_parse_error(node, 'Invalid NonNegativeInteger')
value = attrs.get('unitsAbbreviation')
if value is not None and 'unitsAbbreviation' not in already_processed:
already_processed.append('unitsAbbreviation')
self.unitsAbbreviation = value
value = attrs.get('unitsType')
if value is not None and 'unitsType' not in already_processed:
already_processed.append('unitsType')
self.unitsType = value
value = attrs.get('timeZoneShiftApplied')
if value is not None and 'timeZoneShiftApplied' not in already_processed:
already_processed.append('timeZoneShiftApplied')
if value in ('true', '1'):
self.timeZoneShiftApplied = True
elif value in ('false', '0'):
self.timeZoneShiftApplied = False
else:
raise_parse_error(node, 'Bad boolean attribute')
value = attrs.get('unitsAreConverted')
if value is not None and 'unitsAreConverted' not in already_processed:
already_processed.append('unitsAreConverted')
if value in ('true', '1'):
self.unitsAreConverted = True
elif value in ('false', '0'):
self.unitsAreConverted = False
else:
raise_parse_error(node, 'Bad boolean attribute')
value = attrs.get('unitsCode')
if value is not None and 'unitsCode' not in already_processed:
already_processed.append('unitsCode')
self.unitsCode = value
self.unitsCode = ' '.join(self.unitsCode.split())
def buildChildren(self, child_, nodeName_, from_subclass=False):
if nodeName_ == 'value':
obj_ = ValueSingleVariable.factory()
obj_.build(child_)
self.value.append(obj_)
elif nodeName_ == 'qualifier':
obj_ = qualifier.factory()
obj_.build(child_)
self.qualifier.append(obj_)
elif nodeName_ == 'qualityControlLevel':
obj_ = qualityControlLevel.factory()
obj_.build(child_)
self.qualityControlLevel.append(obj_)
elif nodeName_ == 'method':
obj_ = MethodType.factory()
obj_.build(child_)
self.method.append(obj_)
elif nodeName_ == 'source':
obj_ = SourceType.factory()
obj_.build(child_)
self.source.append(obj_)
elif nodeName_ == 'offset':
obj_ = OffsetType.factory()
obj_.build(child_)
self.offset.append(obj_)
# end class TsValuesSingleVariableType
class VariableInfoType(GeneratedsSuper):
"""VariableInfoType is a complex type containting full descriptive
information about a variable, as described by the ODM. This
includes one or more variable codes, the short variable name, a
detailed variable description, and suggest It also extends the
ODM model, in several methods: - options contain extended
reuqest information. - note(s) are for generic extension. -
extension is an element where additional namespace information
should be placed. - related allows for parent and child
relationships between variables to be communicated."""
subclass = None
superclass = None
def __init__(self, metadataDateTime=None, oid=None, variableCode=None, variableName=None, variableDescription=None, valueType=None, dataType=None, generalCategory=None, sampleMedium=None, units=None, options=None, note=None, related=None, extension=None, NoDataValue=None, timeSupport=None):
self.metadataDateTime = _cast(None, metadataDateTime)
self.oid = _cast(None, oid)
if variableCode is None:
self.variableCode = []
else:
self.variableCode = variableCode
self.variableName = variableName
self.variableDescription = variableDescription
self.valueType = valueType
self.dataType = dataType
self.generalCategory = generalCategory
self.sampleMedium = sampleMedium
self.units = units
self.options = options
if note is None:
self.note = []
else:
self.note = note
self.related = related
self.extension = extension
self.NoDataValue = NoDataValue
self.timeSupport = timeSupport
def factory(*args_, **kwargs_):
if VariableInfoType.subclass:
return VariableInfoType.subclass(*args_, **kwargs_)
else:
return VariableInfoType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_variableCode(self): return self.variableCode
def set_variableCode(self, variableCode): self.variableCode = variableCode
def add_variableCode(self, value): self.variableCode.append(value)
def insert_variableCode(self, index, value): self.variableCode[index] = value
def get_variableName(self): return self.variableName
def set_variableName(self, variableName): self.variableName = variableName
def get_variableDescription(self): return self.variableDescription
def set_variableDescription(self, variableDescription): self.variableDescription = variableDescription