-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathloop_plugin_dialog.py
2623 lines (2463 loc) · 103 KB
/
loop_plugin_dialog.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 -*-
"""
/***************************************************************************
Loop_pluginDialog
A QGIS plugin
This plugin preprocess shapefile inputs to generate python script and json file that are used as input for map2loop
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2022-10-13
git sha : $Format:%H$
copyright : (C) 2022 by Michel M. Nzikou / CET - UWA
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. *
* *
***************************************************************************/
"""
from qgis.PyQt import uic, QtWidgets
from qgis.core import QgsProject
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt
import json
import os, glob, subprocess, time
from pathlib import Path
import os.path, shutil
from datetime import datetime
from .load_vectors import shape_file_loader, xlayer_reader, create_json_file
from .create_python_file import save_a_python_file, find_relative_path
from .help_function import sort_layer_param
from .feature_import import (
qpush_desactivator,
label_mover,
qline_and_label_mover,
qlineeditor_default_string,
welcoming_image,
save_activator,
icon_indexer,
list_all_layers,
activate_loader_checkbox,
activate_config_file,
reset_all_features,
set_to_tristate,
reset_after_run,
)
from .clear_features import (
clear_all_label,
clear_partially_combo_list,
combo_list,
hide_all_combo_list,
hide_dtm_feature,
reset_qgis_cbox,
hide_http,
disabled_qgis_chkbox,
retry_function,
)
from .layer_parameter_extractor import (
load_data_when_qgis_is_choosen,
three_push_activator,
)
from .hover_event import show_my_info, layer_show_tooltype
from .create_your_roi import (
create_scratch_layer,
select_your_roi_region,
saving_your_roi,
set_your_clip,
)
from .scripts.json_load.load_data_from_json import (
save_param_to_json,
select_load_json_file,
read_json,
print_keys_values,
)
from .scripts.json_load.activate_qt_feature import (
data_from_json_to_cbbox,
json_combbox_activate,
)
from .feature_import import welcoming_image, list_all_layers, update_file_path
from .save_to_shp_and_geojson import (
create_strip_shapefile,
create_geojson_file,
find_clip_files,
)
from .run_map2loop import hide_map2loop_features, run_client
from .stop_docker_container import switch_off_docker
from .scripts.loop.l2s_data_push import (
push_data_into_l2s_server,
push_processed_into_loopsource_data,
)
# from .scripts.loop.l2s_docker_info import get_my_docker_infos
from .scripts.loop.l2s_result_downloader import (
plot_block_model_with_surfaces_and_stratigraphy,
)
from .scripts.map.bbox_extract import extract_bbox
# This loads your .ui file so that PyQt can populate your plugin with the elements from Qt Designer
FORM_CLASS, _ = uic.loadUiType(
os.path.join(os.path.dirname(__file__), "loop_plugin_dialog_base.ui")
)
class Loop_pluginDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(Loop_pluginDialog, self).__init__(parent)
# Set up the user interface from Designer through FORM_CLASS.
# After self.setupUi() you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
#
self.setupUi(self)
hide_all_combo_list(self, 0), welcoming_image(self, 1), hide_dtm_feature(
self, 0
), hide_http(self, 0)
# plugin directory
self.plugin_dir = os.path.dirname(os.path.abspath(__file__))
# hide map2loop qlineeditor and label
self.map2loop_qline_list = [
self.map2loop_label_1,
self.map2loop_label_2,
self.map2loop_label_3,
self.map2loop_Ok_pushButton,
]
self.map2loop_label_list = [
self.map2loop_1,
self.map2loop_2,
self.map2loop_3,
self.map2loop_Ok_pushButton,
]
hide_map2loop_features(
self.map2loop_label_list, self.map2loop_qline_list, False
)
self.SearchFolder.setEnabled(False)
self.params_function_activator(False)
activate_loader_checkbox(self, 0)
icon_indexer(self)
"""
Connect button
"""
self.FolderSearch_Button.pressed.connect(self.select_folder)
self.GeolButton.clicked.connect(self.save_geol_param)
self.FaultButton.clicked.connect(self.save_fault_param)
self.StructButton.clicked.connect(self.save_struct_param)
self.DTMButton.clicked.connect(self.save_dtm_path)
self.Saveconfig_pushButton.clicked.connect(self.save_config_file)
self.ROIButton.clicked.connect(self.save_roi_layer)
self.Map2Loop_Button.clicked.connect(self.run_map2loop_module)
self.Reload_btnPush.clicked.connect(self.reset_all_pushbutton)
self.LoopStructural_Button.clicked.connect(self.run_loopstructural_module)
self.Loop3dviz_Button.clicked.connect(self.run_loop3d_viz)
"""
Enable button
"""
self.DTMButton.setEnabled(False) ### Set Enable DTM QPushButton
# check box
self.Orientation_checkBox.setEnabled(False) ### Activate Orientation Qcheckbox
self.ROI_checkBox.setEnabled(False) ### Activate ROI Qcheckbox
self.Drillhole_checkBox.setEnabled(False) ### Activate Drillhole Qcheckbox
self.Section_checkBox.setEnabled(False) ### Activate Section Qcheckbox
self.Folds_checkBox.setEnabled(False) ### Activate Fold Qcheckbox
self.Config_checkBox.setEnabled(False) ### Activate config Qcheckbox
# main qpush button
self.OrientationButton.setEnabled(
False
) ### Activate Drillhole main QPushButton
self.DrillholesButton.setEnabled(False) ### Activate Drillhole main QPushButton
self.SectionsButton.setEnabled(False) ### Activate Section main QPushButton
self.FoldButton.setEnabled(False) ### Activate Fold main QPushButton
self.ConfigButton.setEnabled(False) ### Activate Configuration main QPushButton
self.Saveconfig_pushButton.setEnabled(
False
) ### Activate Save Config File main QPushButton
layers = [
tree_layer.layer()
for tree_layer in QgsProject.instance().layerTreeRoot().findLayers()
]
if not layers:
self.ROIButton.setEnabled(False)
else:
self.ROIButton.setEnabled(True)
"""
Inactivate unnecessary tab
"""
self.Verbose1_radioButton.setEnabled(False) ### Activate Verbose 1 QPushButton
self.Verbose2_radioButton.setEnabled(False) ### Activate Verbose 2 QPushButton
self.Verbose3_radioButton.setEnabled(False) ### Activate Verbose 3 QPushButton
self.Overwrite_checkBox.setEnabled(
False
) ### Activate Overwrite checkBox QPushButton
self.Map2Loop_Button.setEnabled(False) ### Activate map2loop QPushButton
self.LoopStructural_Button.setEnabled(
False
) ### Activate LoopStructural QPushButton
self.Loop3dviz_Button.setEnabled(
False
) ### Activate 3D:: Visualization QPushButton
"""
Hide QPushButton at launch
"""
### Placeholder
self.OrientationButton.hide()
self.Orientation_checkBox.hide()
self.DrillholesButton.hide()
self.Drillhole_checkBox.hide()
self.SectionsButton.hide()
self.Section_checkBox.hide()
self.FoldButton.hide()
self.Folds_checkBox.hide()
self.ConfigButton.hide()
self.Config_checkBox.hide()
### Eend Placeholder
self.ShapeButton.hide() ### Save to Shapefile main QPushButton
self.GeojsonButton.hide() ### Save to Geojson main QPushButton
self.tableWidget.hide() ### table widget used to show layer data
self.PlaceHoldercomboBox.hide() ### placeholer 1
self.PlaceHolderQlineEdit.hide() ### placeholer 2
self.server_frame.hide() ### server frame
self.map2loop_log_TextEdit.hide() ### log text editor
self.map2loop_progressBar.hide() ### hide progressBar
self.Reload_btnPush.hide() ### Reload PushButton
self.Ok_ClipLayer.hide()
show_my_info(self)
# The docker_btnPush here is used to stop the docker
self.docker_btnPush.clicked.connect(self.docker_off)
def docker_off(self):
"""
This function switch off the docker from an external python file
"""
# flag to turn on and off docker
self.docker_switch_flag = self.sender().objectName()
docker_reply = QMessageBox.question(
self,
"Docker status",
str(
"Yes::::> To turn ON the docker \n\n\n"
+ "No::::> To turn OFF the docker"
),
QMessageBox.Yes | QMessageBox.No,
)
if docker_reply == QMessageBox.No:
container_name = "map2loop_local_qgis_server-map2loop-1"
switch_off_docker(container_name)
else:
self.run_local_docker()
return
def activate_server_info(self):
"""
This function activate the server info into the plugin front end
"""
# populate server frame and features
self.server_frame.setVisible(True)
self.server_frame.setGeometry(200, 80, 440, 440)
hide_map2loop_features(self.map2loop_label_list, self.map2loop_qline_list, True)
self.map2loop_2.setText("Enter your name here")
self.map2loop_1.setText(
"Enter 1- Remote machine ip OR 2-localhost if using local pc"
)
if self.sender().objectName() == "LoopStructural_Button":
self.map2loop_3.setText(str(8888))
else:
self.map2loop_3.setText(str(8000))
return
def run_map2loop_module(self):
"""
Transfert m2l data into the remote server
"""
self.map2loop_flag = self.sender().objectName()
self.run_flag = self.sender().objectName()
# disable map2loop and Loopstructural
self.Map2Loop_Button.setEnabled(False)
self.LoopStructural_Button.setEnabled(False)
map2loop_reply = self.create_local_remote_serverbutton(
"Execution Server!", "Local Server", "Remote Server"
)
if map2loop_reply == QMessageBox.No:
print("You chose Remote Server!")
# Here we are using remote machine
self.docker_remote_or_local_server_flag = "remote server "
# activate server info
self.activate_server_info()
# launch the remote calculation
self.map2loop_Ok_pushButton.clicked.connect(self.run_the_server_calculation)
else:
print("You chose Local Server!")
self.docker_remote_or_local_server_flag = "local server"
self.map2loop_msg = map2loop_reply
#
self.map2loop_log_TextEdit.setVisible(True)
self.map2loop_log_TextEdit.setGeometry(170, 150, 750, 300)
self.map2loop_log_TextEdit.append(
"==========================================================\n"
"=======================MAP2LOOP============================\n"
"\n \n"
+ " DOCKER IS BEING CREATED AND THEN TURN ON ************\n"
"\n \n"
+ " MAP2LOOP RUNNING LOCALLY \n \n"
+ "========================================================== \n \n"
)
# send data and run the calculation on the docker
self.run_the_server_calculation()
return
def run_loop3d_viz(self):
"""
This function call the show_3d_plot
"""
self.Loop3dviz_Button.setEnabled(False)
output_list = [
os.path.join(self.vtk_folder_path, key)
for key in list(self.dictionary.keys())
]
plot_block_model_with_surfaces_and_stratigraphy(output_list)
return
def run_loopstructural_module(self):
"""
Transfert l2s data into the remote server
"""
self.loopsctructural_flag = self.sender().objectName()
self.run_flag = self.sender().objectName()
self.loop3d_dict = push_data_into_l2s_server(
self.m2l_output_data, self.loop_data_source
)
# push dtm into loop folder locally
self.processed_data = (
self.data_folder + "/process_source_data_" + str(self.dt_string)
)
try:
push_processed_into_loopsource_data(
self.processed_data, self.loop_data_source
)
except:
pass
# hide log text
self.map2loop_log_TextEdit.hide()
# now send data into loop server
loop_msg = self.create_local_remote_serverbutton(
"Execution Server!", "Local Server", "Remote Server"
)
if loop_msg == QMessageBox.No:
# Here we are using remote machine
self.docker_remote_or_local_server_flag = "remote server"
# activate server info
self.activate_server_info()
# launch the remote calculation
self.map2loop_Ok_pushButton.clicked.connect(self.run_the_server_calculation)
else:
self.docker_remote_or_local_server_flag = "local server"
self.loop_msg = loop_msg
#
self.map2loop_log_TextEdit.setVisible(True)
self.map2loop_log_TextEdit.setGeometry(170, 150, 750, 300)
self.map2loop_log_TextEdit.append(
"==========================================================\n"
"====================LOOPSTRUCTURAL===========================\n"
"\n \n"
+ " DOCKER IS BEING CREATED AND THEN TURN ON ************\n"
"\n \n"
+ " LOOPSTRUCTURAL RUNNING LOCALLY \n \n"
+ "========================================================== \n \n"
)
# send data and run the calculation on the docker
self.run_the_server_calculation()
return
def run_local_docker(self):
"""
This function activate docker compose from an external python file
"""
if self.run_flag == "Map2Loop_Button":
# docker build file path
docker_build_file_path = (
str(self.plugin_dir)
+ "\\map2loop_local_qgis_server\\server\\build_docker_image.py"
)
# docker compose file path
docker_compose_file_path = (
str(self.plugin_dir)
+ "\\map2loop_local_qgis_server\\docker-compose.yml"
)
else:
# docker build file path
docker_build_file_path = (
str(self.plugin_dir)
+ "\\loopstructural_local_qgis_server\\server\\build_docker_image.py"
)
# docker compose file path
docker_compose_file_path = (
str(self.plugin_dir)
+ "\\loopstructural_local_qgis_server\\docker-compose.yml"
)
# Here we passing sys.argv[1] to the python file build_docker_image.py
# such as subprocess.run(['cmd','filepath',sys.argv[1]])
res = subprocess.run(
[
"python",
docker_build_file_path,
docker_compose_file_path,
],
capture_output=True,
text=True,
shell=True,
)
#
if res.returncode != 0:
print("Error:", res.stderr)
else:
try:
if self.docker_switch_flag == "docker_btnPush":
pass
except:
# wait for 5s for the server to fire up
time.sleep(5)
run_client(
self,
self.run_flag,
self.data_folder,
self.hostname,
self.username,
self.port_number,
self.docker_config,
)
#
self.loopstructural_activator(self.sender().objectName())
return
def loopstructural_activator(self, sender):
"""
This function activate the loopstructural function
sender : the qpushbutton activated
"""
# Check if vtk folder exist locally:
# Define the folder path
vtk_folder_path = str(self.loop_output_data) + "/vtk"
# Check if the folder exists
if not os.path.exists(vtk_folder_path):
# If it doesn't exist, create it
os.makedirs(vtk_folder_path)
print(f"Folder '{vtk_folder_path}' created.")
else:
print(f"Folder '{vtk_folder_path}' already exists.")
if sender == "Map2Loop_Button":
self.LoopStructural_Button.setEnabled(True)
print(
f"STATUS: Running Successfully <<{sender.split('_')[0]}>> server - JOB: completed"
)
else:
# create source_data and output_data from docker compose
self.LoopStructural_Button.setEnabled(False)
self.Loop3dviz_Button.setEnabled(True)
return
def run_the_server_calculation(self):
"""
This function run the modelling calculation on the server,
# 1- Activate the server API
# 2- Send the data to the server
# 3- run map2loop/loopstructural and push back the result
"""
self.docker_config = self.docker_config_file
try:
if (
self.sender().objectName() == "Map2Loop_Button"
and self.sender().text() == "Run map2loop"
):
self.docker_config = self.docker_config_file
except:
pass
try:
if self.docker_remote_or_local_server_flag == "local server":
if (
self.sender().objectName() == "LoopStructural_Button"
and self.sender().text() == "Run LoopStructural"
):
# This is for loopstructural data
# combine the two dictionanry
self.docker_config = {
**self.docker_config_file,
**{
"l2s_project_path": str(self.data_folder),
"LPFilename": "server_" + self.loop3d_dict["LPFilename"],
},
}
else:
print("Docker local server")
elif self.docker_remote_or_local_server_flag == "remote server":
if (
self.sender().objectName() == "map2loop_Ok_pushButton"
and self.run_flag == "LoopStructural_Button"
):
# This is for loopstructural data
# combine the two dictionanry
self.docker_config = {
**self.docker_config_file,
**{
"l2s_project_path": str(self.data_folder),
"LPFilename": "server_" + self.loop3d_dict["LPFilename"],
},
}
else:
print("Docker remote server")
else:
pass
except:
pass
# hide the map2loop details
hide_map2loop_features(
self.map2loop_label_list, self.map2loop_qline_list, False
)
# verify this space for next...
self.data_folder = str(self.first_parent_folder)
# disable server frame
self.server_frame.hide()
try:
# config path
if self.docker_remote_or_local_server_flag == "local server":
# running the local docker
self.username, self.hostname, self.port_number = self.pass_server_infos(
"local server"
)
self.run_local_docker()
else:
# run the remote docker
self.username, self.hostname, self.port_number = self.pass_server_infos(
"remote server"
)
run_client(
self,
self.run_flag,
self.data_folder,
self.hostname,
self.username,
self.port_number,
self.docker_config,
)
sender = self.run_flag
self.loopstructural_activator(sender=sender)
except:
print("Can't fire the docker server.....")
return
def pass_server_infos(self, server_info_flag):
"""
This code return the server info such as userId, hostname and port number
# server_info_flag: 'local server or remote server'
"""
if server_info_flag == "remote server":
self.username = str(self.map2loop_2.text())
self.hostname = str(self.map2loop_1.text())
self.port_number = str(self.map2loop_3.text())
else:
self.username = "*********"
self.hostname = "localhost"
if self.sender().objectName() == "Map2Loop_Button":
self.port_number = "8000"
elif self.sender().objectName() == "LoopStructural_Button":
self.port_number = "8888"
else:
print("Placeholder for future work")
pass
return self.username, self.hostname, self.port_number
def save_roi_layer(self):
"""
Once activated, this function is used to clip layer data, multiple process are required:
# creation of ROI via a temp scratch layer,
# then later, saved_clipped_layer is created from your region of interest.
"""
self.roi_status = self.sender().objectName()
# print('roi button is {}'.format(self.sender().objectName()) )
welcoming_image(self, 2)
self.CRS_LineEditor.hide() ### delete crs value
self.CRS_label.hide() ### hide crs label
# Check and disabled ROI
self.ROI_checkBox.setChecked(True)
self.ROIButton.setEnabled(False)
roi_msg = QMessageBox.question(
self,
"Region of interest (ROI)",
"Create your ROI? \n \n Yes:--> to create your ROI. \n \n No:--> to load your existing ROI.",
QMessageBox.Yes | QMessageBox.No,
)
if roi_msg == QMessageBox.Yes:
create_scratch_layer(self, 0)
else:
self.your_own_roi = True
self.No_flag = True
self.activate_layers(self.sender().text())
self.Ok_ClipLayer.setVisible(True)
set_your_clip(self, 140, 140)
self.Ok_ClipLayer.clicked.connect(self.save_clipped_layer)
self.QPushbutton_functionActivator(
False, self.GeolButton, self.FaultButton, self.StructButton
), self.DTMButton.setEnabled(False)
if not QgsProject.instance().mapLayers().values():
## This section deal with loading data if qgis panel is empty
load_msg = QMessageBox.question(
self,
"ROI Layer",
"No Layer available \n \n Load now to continue?",
QMessageBox.Yes | QMessageBox.No,
)
self.selected_layer = []
if load_msg == QMessageBox.Yes:
p, self.DTMPath = self.activate_layers(self.sender().text())
continue_msg = QMessageBox.question(
self,
"ROI Layer",
"Continue loading layer?",
QMessageBox.Yes | QMessageBox.No,
)
while continue_msg == QMessageBox.Yes:
p, self.DTMPath = self.activate_layers(self.sender().text())
continue_msg = QMessageBox.question(
self,
"ROI Layer",
"Continue loading layer?",
QMessageBox.Yes | QMessageBox.No,
)
if continue_msg == QMessageBox.Yes:
continue
else:
break
self.Ok_ClipLayer.clicked.connect(self.save_clipped_layer)
return
def save_clipped_layer(self):
"""
This code is called in save_roi_layer to create the clipped layer.
"""
self.clip_signal = self.sender().objectName()
# If existing ROI is loaded, run the below option
try:
if self.your_own_roi == True:
layers_list = QgsProject.instance().mapLayers().values()
excludedIndices = ["roi"]
layers_excl_roi = [
x
for i, x in enumerate(layers_list)
if x.name() not in excludedIndices
]
layer_name = []
for layer in layers_excl_roi:
if type(layer).__name__ == "QgsRasterLayer":
self.type_of_layer = 1
layer_name.append(layer.name())
else:
try:
if layer.name() == "temp_layer":
QgsProject.instance().removeMapLayers([layer.id()])
else:
self.type_of_layer = layer.wkbType()
layer_name.append(layer.name())
except:
pass
select_your_roi_region(self, layer, self.type_of_layer)
self.Ok_ClipLayer.disconnect()
text = "\n".join(layer_name)
QMessageBox.about(
self,
"ROI Staus",
str(text) + "\n \n" + "....Clipping Completed....",
)
else:
pass
except:
pass
try:
if self.draw_your_ROI == True: # QMessageBox.Yes:
layers_list = QgsProject.instance().mapLayers().values()
temp_layer = [a for a in layers_list if a.name() == "temp_layer"][0]
saving_your_roi(temp_layer, self.clip_path)
excludedIndices = ["roi"]
layers_excl_roi = [
x
for i, x in enumerate(layers_list)
if x.name() not in excludedIndices
]
layer_name = []
for layer in layers_excl_roi:
if type(layer).__name__ == "QgsRasterLayer":
self.type_of_layer = 1
layer_name.append(layer.name())
else:
if layer.name() == "temp_layer":
QgsProject.instance().removeMapLayers([layer.id()])
else:
self.type_of_layer = layer.wkbType()
layer_name.append(layer.name())
select_your_roi_region(self, layer, self.type_of_layer)
self.Ok_ClipLayer.disconnect()
text = "\n".join(layer_name)
QMessageBox.about(
self,
"ROI Staus",
str(text) + "\n \n" + "....Clipping Completed....",
)
else:
pass
except:
pass
self.All_names = [str(l) + "_clip" for l in layer_name]
return
def select_folder(self):
"""
This function return the project folder directory, in which the json and python script will be saved.
Here, the user will be ask to search their data directory and select its folder.
"""
self.folder_name = self.sender().objectName()
foldername = QFileDialog.getExistingDirectory(
self.FolderSearch_Button,
"Select folder ",
"",
)
self.SearchFolder.setText(foldername)
activate_config_file(self)
return
def activate_layers(self, label):
"""
This function is used to load the data from your local PC. It is called in create_<your layer name here>_idname function
Once the layer qpushbutton is released, the user is asked to search the data anywhere on their directory.
"""
label = label
#
try:
shape_file_list = []
for shape_file in QFileDialog.getOpenFileNames(
self,
"Filtered file",
"",
"Filtered files (*.shp *.SHP *.tif *.TIF *.gpkg)",
):
shape_file_list.append(shape_file)
# try:
list_of_files = shape_file_list[0]
self.path_file = list_of_files[0]
self.colNames = shape_file_loader(list_of_files)
except:
buttonReply = QMessageBox.question(
self,
"Layer status",
str("No Layer selected? \n\n" + "Load now"),
QMessageBox.Yes | QMessageBox.No,
)
if buttonReply == QMessageBox.Yes:
shape_file_list = []
for shape_file in QFileDialog.getOpenFileNames(
self,
"Filtered file",
"",
"Filtered files (*.shp *.SHP *.tif *.TIF *.gpkg)",
):
shape_file_list.append(shape_file)
list_of_files = shape_file_list[0]
while not list_of_files:
buttonReply = QMessageBox.question(
self,
"Layer status",
str("No Layer selected? \n\n" + "Load now"),
QMessageBox.Yes,
)
if buttonReply == QMessageBox.Yes:
shape_file_list = []
for shape_file in QFileDialog.getOpenFileNames(
self,
"Filtered file",
"",
"Filtered files (*.shp *.SHP *.tif *.TIF *.gpkg)",
):
shape_file_list.append(shape_file)
list_of_files = shape_file_list[0]
if len(list_of_files) == 1:
break
self.path_file = list_of_files[0]
self.colNames = shape_file_loader(list_of_files)
else:
reset = QMessageBox.question(
self, "App resetting", str("Reset now "), QMessageBox.Yes
)
if reset == QMessageBox.Yes:
self.reset_flag = self.sender().objectName()
self.colNames = []
self.path_file = ""
reset_after_run(self)
return (
self.colNames,
self.path_file if buttonReply == QMessageBox.Yes else self.close(),
)
return self.colNames, self.path_file
def create_geology_idname(self):
"""
Once Geology pushbutton is released, the function will return:
# Geology IDs which are filled in combobox associated to the layer in Qt framework.
# Then saved in the back end and added to the final data list.
"""
hide_all_combo_list(self, 1)
clear_partially_combo_list(self, 10, 1)
if (
self.Structure_checkBox.checkState() == 2
or self.Fault_checkBox.checkState() == 2
):
self.my_combo_list = combo_list(self)
for i in range(10):
self.my_combo_list[i].setVisible(True)
self.PlaceHolderQlineEdit.hide()
p, self.GeolPath = self.activate_layers(self.sender().text())
if self.GeolButton.objectName() == "GeolButton":
self.GeolPath = self.GeolPath
geol_comboHeader = [
"Formation*",
"Group",
"Supergroup",
"Description",
"Fm code",
"Rocktype 1",
"Rocktype 2",
"Polygon ID",
"Min Age",
"Max Age",
]
label_mover(self, geol_comboHeader)
self.colNames = xlayer_reader(self)
self.combo_column_appender(self.colNames, self.GeolButton.objectName())
self.geol_col_dict = {"geology column": self.colNames}
# print(f" The geology full data column: {self.geol_col_dict}")
qline_and_label_mover(
340, 200, 340, 220, " Sill Text:", self.Sill_Label, self.Sill_LineEditor
)
qline_and_label_mover(
340,
280,
340,
300,
" Intrusion Text:",
self.Intrusion_Label,
self.Intrusion_LineEditor,
)
qlineeditor_default_string(self, "sill", "intrusive")
self.params_function_activator(True)
self.geolcheck = self.Geology_checkBox.checkState()
qpush_desactivator(self, self.sender_name)
reset_qgis_cbox(self, 2)
self.dtm_push_activator()
return
def create_fault_idname(self):
"""
Once Fault qpushbutton is released, the function will return:
# Fault IDs which are filled in combobox associated to the layer in Qt framework.
# For the combobox id=4 (Dip Direction type) only ['num','alpha'] available.
# Then saved in the back end and added to the final data list.
"""
clear_partially_combo_list(self, 10, 1)
p, self.FaultPath = self.activate_layers(self.sender().text())
if self.FaultButton.objectName() == "FaultButton":
self.FaultPath = self.FaultPath
fault_comboHeader = [
"Default Dip",
"Dip Direction",
"Feature",
"Dip Direction type",
"Fdipest",
"Point ID",
"Dip Dir Convention",
]
self.colNames = xlayer_reader(self)
label_mover(self, fault_comboHeader)
self.combo_column_appender(self.colNames, self.FaultButton.objectName())
DipDirectiontype_colNames = ["num", "alpha"]
self.cmbDescriptionLayerIDName.clear()
self.cmbDescriptionLayerIDName.addItems(DipDirectiontype_colNames)
DipDirectionConv_colNames = ["Dip Direction", "Strike"]
self.cmbRocktype2LayerIDName.clear()
self.cmbRocktype2LayerIDName.addItems(DipDirectionConv_colNames)
self.fault_col_dict = {"fault column": self.colNames}
qline_and_label_mover(
340, 125, 340, 145, " Fault Text:", self.Sill_Label, self.Sill_LineEditor
)
qline_and_label_mover(
340,
185,
340,
205,
" fdipest Text:",
self.Intrusion_Label,
self.Intrusion_LineEditor,
)
qlineeditor_default_string(self, "Fault", "shallow,steep,vertical")
clear_partially_combo_list(self, 7, 1)
clear_partially_combo_list(self, 7, 0)
self.params_function_activator(True)
self.faultcheck = self.Fault_checkBox.checkState()
qpush_desactivator(self, self.sender_name)
reset_qgis_cbox(self, 2)
self.dtm_push_activator()
return
def create_struct_idname(self):
"""
Once Structure qpushbutton is released, the function will return:
# Structure IDs which are filled in combobox associated to the layer in Qt framework.
# For the combobox 4=Dip Direction convention* only ['Strike','Dip Direction'] available.
# Then saved in the back end and added to the final data list.
"""
clear_partially_combo_list(self, 10, 1)
p, self.StructPath = self.activate_layers(self.sender().text())
if self.StructButton.objectName() == "StructButton":
self.StructPath = self.StructPath
struct_comboHeader = [
"Dip*",
"Dip Direction*",
"Feature*",
"Dip Dir Convention*",
"Overturned Field",
"Point ID",
]
self.colNames = xlayer_reader(self)
label_mover(self, struct_comboHeader)
self.combo_column_appender(self.colNames, self.StructButton.objectName())
DipDirectionConv_colNames = ["Dip Direction", "Strike"]
self.cmbDescriptionLayerIDName.clear()
self.cmbDescriptionLayerIDName.addItems(DipDirectionConv_colNames)
self.struc_col_dict = {"structure column": self.colNames}
qline_and_label_mover(
340, 125, 340, 145, " Bedding Text:", self.Sill_Label, self.Sill_LineEditor
)
qline_and_label_mover(
340,
185,
340,
205,
" Overturned Text:",
self.Intrusion_Label,
self.Intrusion_LineEditor,
)
qlineeditor_default_string(self, "Bed", "overturned")
clear_partially_combo_list(self, 6, 1)
clear_partially_combo_list(self, 6, 0)
self.params_function_activator(True)
self.structcheck = self.Structure_checkBox.checkState()
qpush_desactivator(self, self.sender_name)
reset_qgis_cbox(self, 2)
self.dtm_push_activator()
return
def data_updater(self):
"""
This function update the output of the resulting data processing from combobox and qlineeditor as well as all parameters
"""
try:
if (
self.sender().objectName() == "FaultButton"
and self.sender_name == "GeolButton"
or self.sender().objectName() == "StructButton"
and self.sender_name == "GeolButton"
or self.sender().objectName() == "DTMButton"
and self.sender_name == "GeolButton"
):