-
Notifications
You must be signed in to change notification settings - Fork 1
/
WARMGIS_Tools.py
3598 lines (2320 loc) · 123 KB
/
WARMGIS_Tools.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
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 -*-
"""
/***************************************************************************
WARMGIS_Tools
A QGIS plugin
Water Management Tools
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2022-04-12
git sha : $Format:%H$
copyright : (C) 2022 by Rafael Kayser
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os, sys, datetime
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as dates
import numpy as np
from . import resources
from . import shapefile
from matplotlib.ticker import FuncFormatter
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QSettings, QTranslator, qVersion, QCoreApplication, QVariant, Qt, QVersionNumber, QObject, pyqtSignal
from qgis.core import *
from qgis.gui import *
from pylab import *
from qgis.gui import QgsMapToolEmitPoint
#from PyQt5.QtWidgets import QAction, QMainWindow, QApplication, QMessageBox, QFileDialog, QgsVectorLayer #, QgsProject ,
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtGui import QColor
from os import path
from PyQt5.QtWidgets import *
from csv import reader
from .WARMWidget import Widget
from .WARMWidget import wid_open_proj
from .WARMWidget import wid_run_balance
from .WARMWidget import wid_run_qual
from .WARMWidget import wid_ins_wit_pon
from .WARMWidget import wid_ins_wit_tab
from .WARMWidget import wid_ins_lan_pon
from .WARMWidget import wid_ins_lan_tab
from .WARMWidget import wid_ins_stream_data
from .WARMWidget import wid_qual_par
from .WARMWidget import wid_qual_obs
from .WARMWidget import wid_ins_res_pon
from .model_quality import Quality_Model
from .model_balance import Balance_Model
from .model_auxiliar import create_drl_from_iph, create_fields_wit, create_fields_efl, create_fields_res, read_streamflow_file, conf_drl_bho, save_parameters_drl
# Import the code for the DockWidget
from .WARMGIS_Tools_dockwidget import WARMGIS_ToolsDockWidget
import os.path
class WARMGIS_Tools:
"""QGIS Plugin Implementation."""
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
self.dockwidget = Widget() #main interface
self.canvas = self.iface.mapCanvas()
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'WARMGIS_Tools_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
QCoreApplication.installTranslator(self.translator)
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&WARM-GIS Tools')
# TODO: We are going to let the user set this up in a future iteration
#self.toolbar = self.iface.addToolBar(u'WARMGIS_Tools')
#self.toolbar.setObjectName(u'WARMGIS_Tools')
self.toolbar = self.iface.addToolBar('WARM-GIS Tools')
self.toolbar.setObjectName('WARM-GIS Tools')
#print "** INITIALIZING WARMGIS_Tools"
self.pluginIsActive = False
#self.dockwidget = None
#INICIALIZAR OPÇÕES DO WIDGET
self.dockwidget.treeWidget.activated.connect(self.process)
# TELA CREATE PROJECT
self.wid_open_proj = wid_open_proj() #auxiliar interface
self.wid_open_proj.btn_sel_drl.clicked.connect(self.fc_input_drl)
self.wid_open_proj.btn_sel_cat.clicked.connect(self.fc_input_cat)
self.wid_open_proj.btn_sel_efl.clicked.connect(self.fc_input_efl)
self.wid_open_proj.btn_sel_res.clicked.connect(self.fc_input_res)
self.wid_open_proj.btn_proj_save.clicked.connect(self.fc_proj_save)
self.wid_open_proj.btn_proj_open.clicked.connect(self.fc_proj_open)
self.wid_open_proj.btn_sel_mini.clicked.connect(self.fc_input_mini)
#WITHDRAWALS
self.wid_open_proj.btn_sel_wit.clicked.connect(self.fc_input_wit)
#WATER BALANCE MODULE
self.wid_run_balance = wid_run_balance() # auxiliar interface
self.wid_run_balance.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
self.wid_run_balance.btn_bal_sim.clicked.connect(self.fc_balmod_sim)
self.wid_run_balance.btn_plot_bal.clicked.connect(self.fc_plot_bal)
#WATER QUALITY MODEL
self.wid_run_qual = wid_run_qual() # auxiliar interface
self.wid_run_qual.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
self.wid_run_qual.btn_run.clicked.connect(self.fc_run_qual)
self.wid_run_qual.btn_plot.clicked.connect(self.fc_plot_qual)
self.wid_run_qual.psh_path_par.clicked.connect(self.fc_path_csv)
#self.wid_run_qual.psh_path_obs.clicked.connect(self.fc_path_folder)
self.wid_run_qual.psh_path_river.clicked.connect(self.fc_path_csv_river)
self.wid_run_qual.psh_river_codes.clicked.connect(self.fc_river_codes)
self.wid_run_qual.psh_path_shp.clicked.connect(self.fc_path_shp_est)
self.wid_run_qual.psh_path_data.clicked.connect(self.fc_path_data_est)
#INSERT USER
self.wid_ins_wit_pon = wid_ins_wit_pon()
self.wid_ins_wit_pon.psh_ins_wit.clicked.connect(self.fc_ins_wit_pon)
#INSERT EFFLUENT
self.wid_ins_lan_pon = wid_ins_lan_pon()
self.wid_ins_lan_pon.psh_ins_lan.clicked.connect(self.fc_ins_lan_pon)
#INSERT WIT TABLE
self.wid_ins_wit_tab = wid_ins_wit_tab()
self.wid_ins_wit_tab.psh_path_csv.clicked.connect(self.fc_path_csv2)
self.wid_ins_wit_tab.psh_ins_table.clicked.connect(self.fc_ins_wit_tab)
self.wid_ins_wit_tab.psh_ins_wit.clicked.connect(self.fc_ins_wit_tab_shape)
#INSERT EFFLUENT TABLE
self.wid_ins_lan_tab = wid_ins_lan_tab()
self.wid_ins_lan_tab.psh_path_csv.clicked.connect(self.fc_path_csv3)
self.wid_ins_lan_tab.psh_ins_table.clicked.connect(self.fc_ins_lan_tab)
self.wid_ins_lan_tab.psh_ins_lan.clicked.connect(self.fc_ins_lan_tab_shape)
#INSERT RESERVOIR
self.wid_ins_res_pon = wid_ins_res_pon()
self.wid_ins_res_pon.psh_ins_res.clicked.connect(self.fc_ins_res_pon)
#STREAMFLOW DATA
self.wid_ins_stream_data = wid_ins_stream_data()
self.wid_ins_stream_data.psh_sel_stream.clicked.connect(self.fc_path_stream)
self.wid_ins_stream_data.psh_ins_data.clicked.connect(self.fc_ins_stream)
#QUALITY PARAMETERS
self.wid_qual_par = wid_qual_par()
self.wid_qual_par.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
self.wid_qual_par.psh_confirm_par.clicked.connect(self.fc_config_par)
self.wid_qual_par.psh_save_file.clicked.connect(self.fc_save_par_file)
self.wid_qual_par.psh_sel_file_par.clicked.connect(self.fc_open_create_par_qual)
#WATER QUALITY STATIONS
self.wid_qual_obs = wid_qual_obs()
#self.wid_qual_obs.psh_path_obs_list.clicked.connect(self.fc_path_csv_list)
#self.wid_qual_obs.psh_path_obs_data.clicked.connect(self.fc_path_csv_data)
#self.wid_qual_obs.psh_confirm_obs.clicked.connect(self.fc_path_qual_obs)
self.wid_qual_obs.psh_path_csv.clicked.connect(self.fc_path_csv4)
self.wid_qual_obs.psh_ins_table.clicked.connect(self.fc_ins_monit_data_coords)
self.wid_qual_obs.psh_ins_lan.clicked.connect(self.fc_ins_monit_data_shape)
###############################################################################
# this QGIS tool emits as QgsPoint after each click on the map canvas
self.toolchso = QgsMapToolEmitPoint(self.canvas)
self.tool_effluent = QgsMapToolEmitPoint(self.canvas)
self.tool_reservoir = QgsMapToolEmitPoint(self.canvas)
os.chdir('C:')
self.dir = 'C:/'
self.plugdir = os.path.dirname(__file__)
for i in self.plugdir:
if i == '\\':
self.plugdir = self.plugdir.replace('\\', '/')
def fc_path_csv(self):
name2 = QFileDialog.getOpenFileName(parent=self.wid_run_qual, caption='Input', filter='CSV files (*.csv)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_run_qual.lin_path_par.setText(name2)
def fc_path_csv2(self):
name2 = QFileDialog.getOpenFileName(parent=self.wid_ins_wit_tab, caption='Input', filter='CSV files (*.csv)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_ins_wit_tab.lin_path.setText(name2)
def fc_path_csv3(self):
name2 = QFileDialog.getOpenFileName(parent=self.wid_ins_lan_tab, caption='Input', filter='CSV files (*.csv)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_ins_lan_tab.lin_path.setText(name2)
def fc_path_csv4(self):
name2 = QFileDialog.getOpenFileName(parent=self.wid_qual_obs, caption='Input', filter='CSV files (*.csv)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_qual_obs.lin_path.setText(name2)
############
'''
def fc_path_csv_list(self):
name2 = QFileDialog.getOpenFileName(parent=None, caption='Input', filter='CSV files (*.csv)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_qual_obs.lin_path_list.setText(name2)
'''
def fc_path_shp_est(self):
name2 = QFileDialog.getOpenFileName(parent=self.wid_open_proj, caption='Select shapefile with water quality stations (previously configured)', filter='Shapefiles (*.shp)')
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_run_qual.lin_path_shp.setText(name2)
def fc_path_data_est(self):
name2 = QFileDialog.getOpenFileName(parent=None, caption='Input', filter='CSV files (*.csv)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_run_qual.lin_path_data.setText(name2)
def fc_path_csv_river(self):
name2 = QFileDialog.getOpenFileName(parent=None, caption='Input', filter='text files (*.txt)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
rows=[]
self.rivernames=[]
self.upcods=[]
self.downcods=[]
with open(name2, 'r',encoding='utf-8') as read_obj:
csv_reader = reader(read_obj, delimiter=';')
header = next(csv_reader)
if header != None:
for row in csv_reader:
rows.append(row)
for i in range(len(rows)):
self.rivernames.append(str(rows[i][0]))
self.upcods.append(int(rows[i][1]))
self.downcods.append(int(rows[i][2]))
for rivername in self.rivernames:
self.wid_run_qual.cbx_rivername.addItem(rivername)
def fc_river_codes(self):
rivername_sel = self.wid_run_qual.cbx_rivername.currentText()
ind = np.array(np.where(np.array(self.rivernames) == rivername_sel))
pos=ind[0,0]
upcode_sel = self.upcods[pos]
downcode_sel = self.downcods[pos]
self.wid_run_qual.lin_ups_code.setText(str(upcode_sel))
self.wid_run_qual.lin_down_code.setText(str(downcode_sel))
def fc_path_stream(self):
name2 = QFileDialog.getOpenFileName(parent=self.wid_ins_wit_tab, caption='Input', filter='Text files (*.txt)', directory=self.dir)
name2=name2[0]
self.dir = os.path.dirname(name2) + '/'
for i in name2:
if i == '\\':
name2 = name2.replace('\\', '/')
self.wid_ins_stream_data.lin_path_str.setText(name2)
#####################################################################################################################3
def fc_path_folder(self):
#path = QFileDialog.getExistingDirectory(0, ("Select Output Folder"), QDir.currentPath());
path = QFileDialog.getExistingDirectory(parent=self.wid_run_qual, caption= "Select folder with observed quality data", directory=self.dir);
self.dir = os.path.dirname(path) + '/'
path =path + '/'
for i in path:
if i == '\\':
path = path.replace('\\', '/')
#self.wid_run_qual.lin_path_obs.setText(path)
# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.
We implement this ourselves since we do not inherit QObject.
:param message: String for translation.
:type message: str, QString
:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('WARMGIS_Tools', message)
def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:type icon_path: str
:param text: Text that should be shown in menu items for this action.
:type text: str
:param callback: Function to be called when the action is triggered.
:type callback: function
:param enabled_flag: A flag indicating if the action should be enabled
by default. Defaults to True.
:type enabled_flag: bool
:param add_to_menu: Flag indicating whether the action should also
be added to the menu. Defaults to True.
:type add_to_menu: bool
:param add_to_toolbar: Flag indicating whether the action should also
be added to the toolbar. Defaults to True.
:type add_to_toolbar: bool
:param status_tip: Optional text to show in a popup when mouse pointer
hovers over the action.
:type status_tip: str
:param parent: Parent widget for the new action. Defaults None.
:type parent: QWidget
:param whats_this: Optional text to show in the status bar when the
mouse pointer hovers over the action.
:returns: The action that was created. Note that the action is also
added to self.actions list.
:rtype: QAction
"""
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
self.toolbar.addAction(action)
if add_to_menu:
self.iface.addPluginToMenu(
self.menu,
action)
self.actions.append(action)
return action
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
self.action = QAction(QIcon(self.plugdir + '/icon.png'), 'WARM-GIS Tools', self.iface.mainWindow())
self.action.triggered.connect(self.run)
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu('&IPH - Plugins', self.action)
'''
icon_path = ':/plugins/WARMGIS_Tools/icon.png'
self.add_action(
icon_path,
text=self.tr(u''),
callback=self.run,
parent=self.iface.mainWindow())
'''
#clique no mapa
self.toolchso.canvasClicked.connect(self.clic_wit) #Certo
self.tool_effluent.canvasClicked.connect(self.clic_efl) #Certo
self.tool_reservoir.canvasClicked.connect(self.clic_res)
#--------------------------------------------------------------------------
def onClosePlugin(self):
"""Cleanup necessary items here when plugin dockwidget is closed"""
#print "** CLOSING WARMGIS_Tools"
# disconnects
self.dockwidget.closingPlugin.disconnect(self.onClosePlugin)
# remove this statement if dockwidget is to remain
# for reuse if plugin is reopened
# Commented next statement since it causes QGIS crashe
# when closing the docked window:
# self.dockwidget = None
self.pluginIsActive = False
def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
#print "** UNLOAD WARMGIS_Tools"
for action in self.actions:
self.iface.removePluginMenu(
self.tr(u'&WARM-GIS Tools'),
action)
self.iface.removeToolBarIcon(action)
# remove the toolbar
del self.toolbar
#--------------------------------------------------------------------------
def run(self):
"""Run method that loads and starts the plugin"""
if not self.pluginIsActive:
self.pluginIsActive = True
#print "** STARTING WARMGIS_Tools"
# dockwidget may not exist if:
# first run of plugin
# removed on close (see self.onClosePlugin method)
if self.dockwidget == None:
# Create the dockwidget (after translation) and keep reference
self.dockwidget = WARMGIS_ToolsDockWidget()
# connect to provide cleanup on closing of dockwidget
self.dockwidget.closingPlugin.connect(self.onClosePlugin)
# show the dockwidget
# TODO: fix to allow choice of dock location
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dockwidget)
self.dockwidget.show()
# A PARTIR DAQUI, DESENVOLVIMENTO PROPRIO -----------------------------------------------------------------
def process(self):
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Open / Create project', Qt.MatchRecursive,0)):
self.wid_open_proj.show()
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Withdrawals - Manual insertion', Qt.MatchRecursive,0)):
self.canvas.setMapTool(self.toolchso)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Withdrawals - Table insertion', Qt.MatchRecursive,0)):
self.wid_ins_wit_tab.show()
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Point effluent - Manual insertion', Qt.MatchRecursive,0)):
self.canvas.setMapTool(self.tool_effluent)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Point effluent - Table insertion', Qt.MatchRecursive,0)):
self.wid_ins_lan_tab.show()
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Insert reservoir data', Qt.MatchRecursive,0)):
self.canvas.setMapTool(self.tool_reservoir)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Water Balance Module', Qt.MatchRecursive,0)):
self.wid_run_balance.show()
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Insert water quality stations', Qt.MatchRecursive,0)):
self.wid_qual_obs.show()
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Model parameters', Qt.MatchRecursive,0)):
self.fc_config_qual_par()
self.wid_qual_par.show()
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Run simulation', Qt.MatchRecursive,0)):
self.wid_run_qual.show()
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Discharge data', Qt.MatchRecursive,0)):
self.wid_ins_stream_data.show()
# VISUALIZATION
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 1', Qt.MatchRecursive,0)):
self.fc_render_bal(1)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 2', Qt.MatchRecursive,0)):
self.fc_render_bal(2)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 3', Qt.MatchRecursive,0)):
self.fc_render_bal(3)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 4', Qt.MatchRecursive,0)):
self.fc_render_bal(4)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 5', Qt.MatchRecursive,0)):
self.fc_render_bal(5)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 6', Qt.MatchRecursive,0)):
self.fc_render_bal(6)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 7', Qt.MatchRecursive,0)):
self.fc_render_bal(7)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 8', Qt.MatchRecursive,0)):
self.fc_render_bal(8)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 9', Qt.MatchRecursive,0)):
self.fc_render_bal(9)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 10', Qt.MatchRecursive,0)):
self.fc_render_bal(10)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 11', Qt.MatchRecursive,0)):
self.fc_render_bal(11)
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Scenario 12', Qt.MatchRecursive,0)):
self.fc_render_bal(12)
# quality model
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('BOD', Qt.MatchRecursive,0)):
self.fc_render_qual('BOD')
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Dissolved Oxigen', Qt.MatchRecursive,0)):
self.fc_render_qual('DO')
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Total Phosphorus', Qt.MatchRecursive,0)):
self.fc_render_qual('Pt')
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Coliforms', Qt.MatchRecursive,0)):
self.fc_render_qual('Col')
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Ammon Nitrogen', Qt.MatchRecursive,0)):
self.fc_render_qual('Na')
if str('[' + str(self.dockwidget.treeWidget.currentItem()) + ']') == str(
self.dockwidget.treeWidget.findItems('Nitrate', Qt.MatchRecursive,0)):
self.fc_render_qual('Nn')
#--------------------------------------------------------------------------------
def fc_input_drl(self):
name = QFileDialog.getOpenFileName(parent=self.wid_open_proj, caption='Input', filter='Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
self.wid_open_proj.lin_path_drl.setText(name)
# ----------------------------------------------------------------------------
def fc_input_cat(self):
name = QFileDialog.getOpenFileName(parent=self.wid_open_proj, caption='Input', filter='Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
self.wid_open_proj.lin_path_cat.setText(name)
# ----------------------------------------------------------------------------
def fc_input_wit(self):
if self.wid_open_proj.rbt_wit_new.isChecked()==True:
name = QFileDialog.getSaveFileName(parent=self.wid_open_proj, caption='Create new input file', filter='.Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
fields = QgsFields()
fields = create_fields_wit(fields)
crs = QgsCoordinateReferenceSystem("EPSG:4326")
writer = QgsVectorFileWriter(name,
"Withdrawals",
fields,
QgsWkbTypes.Point, #### instead of QGis.WKBPoint
crs, #### instead of None
"ESRI Shapefile")
self.wid_open_proj.lin_path_wit.setText(name)
if self.wid_open_proj.rbt_wit_sel.isChecked()==True:
name = QFileDialog.getOpenFileName(parent=self.wid_open_proj, caption='Select input file previously configured', filter='Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
self.wid_open_proj.lin_path_wit.setText(name)
# ----------------------------------------------------------------------------
def fc_input_efl(self):
if self.wid_open_proj.rbt_efl_new.isChecked()==True:
name = QFileDialog.getSaveFileName(parent=self.wid_open_proj, caption='Create new input file', filter='.Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
fields = QgsFields()
fields = create_fields_efl(fields)
crs = QgsCoordinateReferenceSystem("EPSG:4326")
writer = QgsVectorFileWriter(name,
"Effluents",
fields,
QgsWkbTypes.Point, #### instead of QGis.WKBPoint
crs, #### instead of None
"ESRI Shapefile")
self.wid_open_proj.lin_path_efl.setText(name)
if self.wid_open_proj.rbt_efl_sel.isChecked()==True:
name = QFileDialog.getOpenFileName(parent=self.wid_open_proj, caption='Select input file previously configured', filter='Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
self.wid_open_proj.lin_path_efl.setText(name)
# ----------------------------------------------------------------------------
def fc_input_res(self):
if self.wid_open_proj.rbt_res_new.isChecked()==True:
name = QFileDialog.getSaveFileName(parent=self.wid_open_proj, caption='Create new input file', filter='.Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
fields = QgsFields()
fields = create_fields_res(fields)
crs = QgsCoordinateReferenceSystem("EPSG:4326")
writer = QgsVectorFileWriter(name,
"Reservoirs",
fields,
QgsWkbTypes.Point, #### instead of QGis.WKBPoint
crs, #### instead of None
"ESRI Shapefile")
self.wid_open_proj.lin_path_res.setText(name)
if self.wid_open_proj.rbt_res_sel.isChecked()==True:
name = QFileDialog.getOpenFileName(parent=self.wid_open_proj, caption='Select input file previously configured', filter='Shapefiles (*.shp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
self.wid_open_proj.lin_path_res.setText(name)
# ----------------------------------------------------------------------------
def fc_input_mini(self):
name = QFileDialog.getOpenFileName(parent=self.wid_open_proj, caption='Input', filter='MINI file (*.gtp)')
name = name[0]
self.dir = os.path.dirname(name) + '/'
for i in name:
if i == '\\':
name = name.replace('\\', '/')
self.wid_open_proj.lin_path_mini.setText(name)
# ----------------------------------------------------------------------------
def fc_proj_save(self):
try:
#TOPOLOGY
if self.wid_open_proj.rbt_new_arc.isChecked()==True:
mode = 'arc'
if self.wid_open_proj.rbt_new_iph.isChecked()==True:
mode = 'iph'
if self.wid_open_proj.rbt_new_ana.isChecked()==True:
mode = 'ana'
if self.wid_open_proj.rbt_defined.isChecked()==True:
mode = 'def'
#MODULE
if self.wid_open_proj.rbt_bal_module.isChecked()==True:
module = 'bal'
if self.wid_open_proj.rbt_qual_module.isChecked()==True:
module = 'qual'