This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate_config_test.py
162 lines (145 loc) · 5.1 KB
/
generate_config_test.py
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
# script to run in the Python console
import json
import psycopg2
from qgis.utils import iface
conn = psycopg2.connect("service=qgeologistest")
cur = conn.cursor()
cur.execute("select * from measure.measure_metadata")
def add_layer(source, name, provider, group=None):
layer = QgsVectorLayer(source, name, provider)
QgsProject.instance().addMapLayer(layer, addToLegend=group is None)
if group is not None:
group.addLayer(layer)
return layer
main_layer = add_layer(
"""service='qgeologistest' sslmode=disable key='id' srid=4326 type=Point checkPrimaryKeyUnicity='0' table="qgis"."station" (point)""",
"Stations",
"postgres",
)
root_group = iface.layerTreeView().layerTreeModel().rootGroup()
group = root_group.addGroup("Mesures")
strat_layer = add_layer(
"""service='qgeologistest' sslmode=disable key='depth_from,depth_to,station_id' srid=4326 type=Polygon checkPrimaryKeyUnicity='0' table="qgis"."measure_stratigraphic_logvalue" (geom)""",
"Stratigraphie",
"postgres",
group,
)
chem_layer = add_layer(
"""service='qgeologistest' sslmode=disable key='id' table="qgis"."measure_chemical_analysis_result" checkPrimaryKKeyUnicity='0'""",
"Analyse chimique",
"postgres",
group,
)
log_measures = []
timeseries = [
{
"source": chem_layer.id(),
"name": chem_layer.name(),
"uom_column": "measure_unit",
"feature_ref_column": "station_id",
"feature_filter_type": "unique_data_from_values",
"feature_filter_column": "chemical_element",
"type": "instantaneous",
"event_column": "measure_epoch",
"value_column": "measure_value",
}
]
imagery_data = []
for table_name, name, uom, x_type, storage_type in cur.fetchall():
schema, table = table_name.split(".")
layer = add_layer(
"""service='qgeologistest' sslmode=disable key='id' checkPrimaryKeyUnicity='0' table="qgis"."{}_{}" """.format(
schema, table
),
name,
"postgres",
group,
)
if x_type == "TimeAxis":
# time series
if storage_type == "Continuous":
timeseries.append(
{
"source": layer.id(),
"name": name,
"uom": uom,
"feature_ref_column": "station_id",
"type": storage_type.lower(),
"start_measure_column": "start_epoch",
"interval_column": "interval_s",
"values_column": "measures",
}
)
elif storage_type == "Instantaneous":
timeseries.append(
{
"source": layer.id(),
"name": name,
"uom": uom,
"feature_ref_column": "station_id",
"type": storage_type.lower(),
"event_column": "measure_epoch",
"value_column": "measure_value",
}
)
elif storage_type == "Cumulative":
timeseries.append(
{
"source": layer.id(),
"name": name,
"uom": uom,
"feature_ref_column": "station_id",
"type": storage_type.lower(),
"event_column": "measure_epoch",
"value_column": "measure_value",
}
)
elif x_type == "DepthAxis":
if storage_type == "Image":
imagery_data.append(
{
"name": name,
"source": "service=bdlhes",
"schema": "qgis",
"table": "measure_{}".format(table),
"feature_ref_column": "station_id",
}
)
else:
log_measures.append(
{
"source": layer.id(),
"name": name,
"uom": uom,
"feature_ref_column": "station_id",
"type": storage_type.lower(),
"start_measure_column": "start_measure_altitude",
"interval_column": "altitude_interval",
"values_column": "measures",
}
)
config = {
main_layer.id(): {
"layer_name": "Stations",
"id_column": "id",
"name_column": "name",
"stratigraphy_config": [
{
"source": strat_layer.id(),
"feature_ref_column": "station_id",
"depth_from_column": "depth_from",
"depth_to_column": "depth_to",
"formation_code_column": "formation_code",
"rock_code_column": "rock_code",
"formation_description_column": "formation_description",
"rock_description_column": "rock_description",
}
],
"log_measures": log_measures,
"timeseries": timeseries,
"imagery_data": imagery_data,
}
}
json = json.dumps(config)
print("config: ", json)
QgsProject.instance().writeEntry("QGeoloGIS", "config", json)