45
45
46
46
from datetime import datetime
47
47
import click
48
- import logging
49
48
50
- from geoalchemy2 import Geometry
49
+ import geoalchemy2
51
50
from sqlalchemy import (Column , create_engine , Date , DateTime , Integer , String ,
52
51
Time , UnicodeText )
53
52
from sqlalchemy .exc import OperationalError , ProgrammingError
54
53
from sqlalchemy .ext .declarative import declarative_base
55
54
56
55
from woudc_data_registry import util
57
56
58
- LOGGER = logging .getLogger (__name__ )
59
57
base = declarative_base ()
60
58
61
59
60
+ class Geometry (geoalchemy2 .types .Geometry ):
61
+ """
62
+ multi-geometry class workaround
63
+ TODO: remove when https://github.com/geoalchemy/geoalchemy2/issues/158
64
+ is fixed
65
+ """
66
+ def get_col_spec (self ):
67
+ if self .geometry_type == 'GEOMETRY' and self .srid == 0 :
68
+ return self .name
69
+ return '%s(%s,%d)' % (self .name , self .geometry_type , self .srid )
70
+
71
+
62
72
class DataRecord (base ):
63
73
"""Data Registry Data Record"""
64
74
@@ -72,19 +82,24 @@ class DataRecord(base):
72
82
content_category = Column (String , nullable = False )
73
83
content_level = Column (String , nullable = False )
74
84
content_form = Column (String , nullable = False )
85
+
75
86
data_generation_date = Column (Date , nullable = False )
76
87
data_generation_agency = Column (String , nullable = False )
77
88
data_generation_version = Column (String , nullable = False )
78
89
data_generation_scientific_authority = Column (String )
90
+
79
91
platform_type = Column (String , default = 'STN' , nullable = False )
80
92
platform_id = Column (String , nullable = False )
81
93
platform_name = Column (String , nullable = False )
82
94
platform_country = Column (String , nullable = False )
83
95
platform_gaw_id = Column (String )
96
+
84
97
instrument_name = Column (String , nullable = False )
85
98
instrument_model = Column (String , nullable = False )
86
99
instrument_number = Column (String , nullable = False )
87
- location = Column (Geometry (management = True , use_typemod = False , srid = 4326 ))
100
+
101
+ location = Column (Geometry (srid = 0 ))
102
+
88
103
timestamp_utcoffset = Column (String , nullable = False )
89
104
timestamp_date = Column (Date , nullable = False )
90
105
timestamp_time = Column (Time )
@@ -101,7 +116,6 @@ class DataRecord(base):
101
116
def __init__ (self , ecsv ):
102
117
"""serializer"""
103
118
104
- LOGGER .debug ('Serializing model' )
105
119
self .content_class = ecsv .extcsv ['CONTENT' ]['Class' ]
106
120
self .content_category = ecsv .extcsv ['CONTENT' ]['Category' ]
107
121
self .content_level = ecsv .extcsv ['CONTENT' ]['Level' ]
@@ -111,26 +125,32 @@ def __init__(self, ecsv):
111
125
self .data_generation_agency = ecsv .extcsv ['DATA_GENERATION' ]['Agency' ]
112
126
self .data_generation_version = \
113
127
ecsv .extcsv ['DATA_GENERATION' ]['Version' ]
114
- self .data_generation_scientific_authority = \
115
- ecsv .extcsv ['DATA_GENERATION' ]['ScientificAuthority' ]
128
+
129
+ if 'ScientificAuthority' in ecsv .extcsv ['DATA_GENERATION' ]:
130
+ self .data_generation_scientific_authority = \
131
+ ecsv .extcsv ['DATA_GENERATION' ]['ScientificAuthority' ]
116
132
117
133
self .platform_type = ecsv .extcsv ['PLATFORM' ]['Type' ]
118
134
self .platform_id = ecsv .extcsv ['PLATFORM' ]['ID' ]
119
135
self .platform_name = ecsv .extcsv ['PLATFORM' ]['Name' ]
120
136
self .platform_country = ecsv .extcsv ['PLATFORM' ]['Country' ]
121
- self .platform_gaw_id = ecsv .extcsv ['PLATFORM' ]['GAW_ID' ]
137
+
138
+ if 'GAW_ID' in ecsv .extcsv ['PLATFORM' ]:
139
+ self .platform_gaw_id = ecsv .extcsv ['PLATFORM' ]['GAW_ID' ]
122
140
123
141
self .instrument_name = ecsv .extcsv ['INSTRUMENT' ]['Name' ]
124
142
self .instrument_model = ecsv .extcsv ['INSTRUMENT' ]['Model' ]
125
143
self .instrument_number = ecsv .extcsv ['INSTRUMENT' ]['Number' ]
126
144
127
145
self .timestamp_utcoffset = ecsv .extcsv ['TIMESTAMP' ]['UTCOffset' ]
128
146
self .timestamp_date = ecsv .extcsv ['TIMESTAMP' ]['Date' ]
129
- self .timestamp_time = ecsv .extcsv ['TIMESTAMP' ]['Time' ]
130
147
131
- self .location = util .point2wkt (ecsv .extcsv ['LOCATION' ]['Longitude' ],
132
- ecsv .extcsv ['LOCATION' ]['Latitude' ],
133
- ecsv .extcsv ['LOCATION' ]['Height' ])
148
+ if 'Time' in ecsv .extcsv ['TIMESTAMP' ]:
149
+ self .timestamp_time = ecsv .extcsv ['TIMESTAMP' ]['Time' ]
150
+
151
+ self .location = util .point2ewkt (ecsv .extcsv ['LOCATION' ]['Longitude' ],
152
+ ecsv .extcsv ['LOCATION' ]['Latitude' ],
153
+ ecsv .extcsv ['LOCATION' ]['Height' ])
134
154
self .extcsv = ecsv .extcsv
135
155
self .raw = ecsv ._raw
136
156
0 commit comments