-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqProf_QWidget.py
4279 lines (3165 loc) · 163 KB
/
qProf_QWidget.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
import unicodedata
from qgis.core import *
from .gsf.geometry import *
from .gsf.array_utils import *
from .gsf.sorting import *
from .gis_utils.features import *
from .gis_utils.intersections import *
from .gis_utils.profile import *
from .gis_utils.qgs_tools import *
from .gis_utils.statistics import *
from .gis_utils.errors import *
from .qt_utils.filesystem import *
from .qt_utils.tools import *
from .string_utils.utils_string import *
from .config.settings import *
from .config.output import *
from .qProf_plotting import *
from .qProf_export import *
class qprof_QWidget(QWidget):
colors = ['orange', 'green', 'red', 'grey', 'brown', 'yellow', 'magenta', 'black', 'blue', 'white', 'cyan',
'chartreuse']
map_digitations = 0
def __init__(self, plugin_name, canvas):
super(qprof_QWidget, self).__init__()
self.plugin_name = plugin_name
self.canvas = canvas
self.current_directory = os.path.dirname(__file__)
self.settings = QSettings("alberese", self.plugin_name)
self.settings_gpxdir_key = "gpx/last_used_dir"
self.choose_message = "choose"
self.demline_source = "demline"
self.gpxfile_source = "gpxfile"
self.digitized_profile_line2dt = None
self.polygon_classification_colors = None
self.input_geoprofiles = GeoProfilesSet() # main instance for the geoprofiles
self.profile_windows = [] # used to maintain alive the plots, i.e. to avoid the C++ objects being destroyed
self.plane_attitudes_colors = []
self.setup_gui()
def init_topo_labels(self):
"""
Initialize topographic label and order parameters.
:return:
"""
self.profiles_labels = None
self.profiles_order = None
def setup_gui(self):
self.dialog_layout = QVBoxLayout()
self.main_widget = QTabWidget()
self.main_widget.addTab(self.setup_topoprofile_tab(), "Topography")
self.main_widget.addTab(self.setup_geology_section_tab(), "Geology")
self.main_widget.addTab(self.setup_export_section_tab(), "Export")
self.main_widget.addTab(self.setup_about_tab(), "Help")
self.prj_input_line_comboBox.currentIndexChanged.connect(self.update_linepoly_layers_boxes)
self.inters_input_line_comboBox.currentIndexChanged.connect(self.update_linepoly_layers_boxes)
self.inters_input_polygon_comboBox.currentIndexChanged.connect(self.update_linepoly_layers_boxes)
self.struct_line_refresh_lyr_combobox()
self.struct_polygon_refresh_lyr_combobox()
QgsProject.instance().layerWasAdded.connect(self.struct_point_refresh_lyr_combobox)
QgsProject.instance().layerWasAdded.connect(self.struct_line_refresh_lyr_combobox)
QgsProject.instance().layerWasAdded.connect(self.struct_polygon_refresh_lyr_combobox)
QgsProject.instance().layerRemoved.connect(self.struct_point_refresh_lyr_combobox)
QgsProject.instance().layerRemoved.connect(self.struct_line_refresh_lyr_combobox)
QgsProject.instance().layerRemoved.connect(self.struct_polygon_refresh_lyr_combobox)
self.dialog_layout.addWidget(self.main_widget)
self.setLayout(self.dialog_layout)
self.adjustSize()
self.setWindowTitle(self.plugin_name)
def setup_topoprofile_tab(self):
def create_topo_profiles():
def stop_rubberband():
try:
self.canvas_end_profile_line()
except:
pass
try:
self.clear_rubberband()
except:
pass
selected_dems = None
selected_dem_parameters = None
sample_distance = None
source_profile_lines = None
if self.qrbtDEMDataType.isChecked():
topo_source_type = self.demline_source
elif self.qrbtGPXDataType.isChecked():
topo_source_type = self.gpxfile_source
else:
warn(self,
self.plugin_name,
"Debug: source data type undefined")
return
self.input_geoprofiles = GeoProfilesSet() # reset any previous created profiles
if topo_source_type == self.demline_source:
try:
selected_dems = self.selected_dems
selected_dem_parameters = self.selected_dem_parameters
except Exception as e:
warn(self,
self.plugin_name,
f"Input DEMs definition not correct: {e}")
return
try:
sample_distance = float(self.qledProfileDensifyDistance.text())
assert sample_distance > 0.0
except Exception as e:
warn(self,
self.plugin_name,
"Sample distance value not correct: {}".format(e))
return
if self.qcbxDigitizeLineSource.isChecked():
if self.digitized_profile_line2dt is None or \
self.digitized_profile_line2dt.num_pts < 2:
warn(self,
self.plugin_name,
"No digitized line available")
return
else:
source_profile_lines = [self.digitized_profile_line2dt]
else:
stop_rubberband()
try:
source_profile_lines = self.profiles_lines
except:
warn(self,
self.plugin_name,
"DEM-line profile source not correctly created [1]")
return
if source_profile_lines is None:
warn(self,
self.plugin_name,
"DEM-line profile source not correctly created [2]")
return
elif topo_source_type == self.gpxfile_source:
stop_rubberband()
try:
source_gpx_path = str(self.qlneInputGPXFile.text())
if source_gpx_path == '':
warn(self,
self.plugin_name,
"Source GPX file is not set")
return
except Exception as e:
warn(self,
self.plugin_name,
"Source GPX file not correctly set: {}".format(e))
return
else:
warn(self,
self.plugin_name,
"Debug: uncorrect type source for topo sources def")
return
# calculates profiles
invert_profile = self.qcbxInvertProfile.isChecked()
if topo_source_type == self.demline_source: # sources are DEM(s) and line
# check total number of points in line(s) to create
estimated_total_num_pts = 0
for profile_line in source_profile_lines:
profile_length = profile_line.length_2d
profile_num_pts = profile_length / sample_distance
estimated_total_num_pts += profile_num_pts
estimated_total_num_pts = int(ceil(estimated_total_num_pts))
if estimated_total_num_pts > pt_num_threshold:
warn(
parent=self,
header=self.plugin_name,
msg="There are {} estimated points (limit is {}) in profile(s) to create.".format(estimated_total_num_pts, pt_num_threshold) +
"\nPlease increase sample distance value"
)
return
for profile_line in source_profile_lines:
try:
topo_profiles = topoprofiles_from_dems(
self.canvas,
profile_line,
sample_distance,
selected_dems,
selected_dem_parameters,
invert_profile
)
except Exception as e:
warn(self,
self.plugin_name,
"Error with data source read: {}".format(e))
return
if topo_profiles is None:
warn(self,
self.plugin_name,
"Debug: profile not created")
return
geoprofile = GeoProfile()
geoprofile.source_data_type = topo_source_type
geoprofile.original_line = profile_line
geoprofile.sample_distance = sample_distance
geoprofile.set_topo_profiles(topo_profiles)
self.input_geoprofiles.append(geoprofile)
elif topo_source_type == self.gpxfile_source: # source is GPX file
try:
topo_profiles = topoprofiles_from_gpxfile(source_gpx_path,
invert_profile,
self.gpxfile_source)
except Exception as e:
warn(self,
self.plugin_name,
"Error with profile calculation from GPX file: {}".format(e))
return
if topo_profiles is None:
warn(self,
self.plugin_name,
"Debug: profile not created")
return
geoprofile = GeoProfile()
geoprofile.source_data_type = topo_source_type
geoprofile.original_line = source_profile_lines
geoprofile.sample_distance = sample_distance
geoprofile.set_topo_profiles(topo_profiles)
self.input_geoprofiles.append(geoprofile)
else: # source error
error(self,
self.plugin_name,
"Debug: profile calculation not defined")
return
info(self,
self.plugin_name,
"Data profile read")
def define_source_DEMs():
def get_dem_resolution_in_prj_crs(dem, dem_params, on_the_fly_projection, prj_crs):
def distance_projected_pts(x, y, delta_x, delta_y, src_crs, dest_crs):
qgspt_start_src_crs = qgs_pt(x, y)
qgspt_end_src_crs = qgs_pt(x + delta_x, y + delta_y)
qgspt_start_dest_crs = project_qgs_point(qgspt_start_src_crs, src_crs, dest_crs)
qgspt_end_dest_crs = project_qgs_point(qgspt_end_src_crs, src_crs, dest_crs)
pt2_start_dest_crs = Point(qgspt_start_dest_crs.x(), qgspt_start_dest_crs.y())
pt2d_end_dest_crs = Point(qgspt_end_dest_crs.x(), qgspt_end_dest_crs.y())
return pt2_start_dest_crs.dist_2d(pt2d_end_dest_crs)
cellsizeEW, cellsizeNS = dem_params.cellsizeEW, dem_params.cellsizeNS
xMin, yMin = dem_params.xMin, dem_params.yMin
if on_the_fly_projection and dem.crs() != prj_crs:
cellsizeEW_prj_crs = distance_projected_pts(xMin, yMin, cellsizeEW, 0, dem.crs(), prj_crs)
cellsizeNS_prj_crs = distance_projected_pts(xMin, yMin, 0, cellsizeNS, dem.crs(), prj_crs)
else:
cellsizeEW_prj_crs = cellsizeEW
cellsizeNS_prj_crs = cellsizeNS
return 0.5 * (cellsizeEW_prj_crs + cellsizeNS_prj_crs)
def get_dem_parameters(dem):
return QGisRasterParameters(*raster_qgis_params(dem))
def get_selected_dems_params(dialog):
selected_dems = []
for dem_qgis_ndx in range(dialog.listDEMs_treeWidget.topLevelItemCount()):
curr_DEM_item = dialog.listDEMs_treeWidget.topLevelItem(dem_qgis_ndx)
if curr_DEM_item.checkState(0) == 2:
selected_dems.append(dialog.singleband_raster_layers_in_project[dem_qgis_ndx])
return selected_dems
self.selected_dems = None
self.selected_dem_parameters = []
current_raster_layers = loaded_monoband_raster_layers()
if len(current_raster_layers) == 0:
warn(self,
self.plugin_name,
"No loaded DEM")
return
dialog = SourceDEMsDialog(self.plugin_name, current_raster_layers)
if dialog.exec_():
selected_dems = get_selected_dems_params(dialog)
else:
warn(self,
self.plugin_name,
"No chosen DEM")
return
if len(selected_dems) == 0:
warn(self,
self.plugin_name,
"No selected DEM")
return
else:
self.selected_dems = selected_dems
# get geodata
self.selected_dem_parameters = [get_dem_parameters(dem) for dem in selected_dems]
# get DEMs resolutions in project CRS and choose the min value
dem_resolutions_prj_crs_list = []
for dem, dem_params in zip(self.selected_dems, self.selected_dem_parameters):
dem_resolutions_prj_crs_list.append(
get_dem_resolution_in_prj_crs(dem, dem_params, self.on_the_fly_projection, self.project_crs))
max_dem_resolution = max(dem_resolutions_prj_crs_list)
if max_dem_resolution > 1:
max_dem_proposed_resolution = round(max_dem_resolution)
else:
max_dem_proposed_resolution = max_dem_resolution
self.qledProfileDensifyDistance.setText(str(max_dem_proposed_resolution))
def save_rubberband():
def output_profile_line(output_format, output_filepath, pts2dt, proj_sr):
points = [[n, pt2dt.x, pt2dt.y] for n, pt2dt in enumerate(pts2dt)]
if output_format == "csv":
success, msg = write_generic_csv(output_filepath,
['id', 'x', 'y'],
points)
if not success:
warn(self,
self.plugin_name,
msg)
elif output_format == "shapefile - line":
success, msg = write_rubberband_profile_lnshp(
output_filepath,
['id'],
points,
proj_sr)
if not success:
warn(self,
self.plugin_name,
msg)
else:
error(self,
self.plugin_name,
"Debug: error in export format")
return
if success:
info(self,
self.plugin_name,
"Line saved")
def get_format_type():
if dialog.outtype_shapefile_line_QRadioButton.isChecked():
return "shapefile - line"
elif dialog.outtype_csv_QRadioButton.isChecked():
return "csv"
else:
return ""
if self.digitized_profile_line2dt is None:
warn(self,
self.plugin_name,
"No available line to save [1]")
return
elif self.digitized_profile_line2dt.num_pts < 2:
warn(self,
self.plugin_name,
"No available line to save [2]")
return
dialog = LineDataExportDialog(self.plugin_name)
if dialog.exec_():
output_format = get_format_type()
if output_format == "":
warn(self,
self.plugin_name,
"Error in output format")
return
output_filepath = dialog.outpath_QLineEdit.text()
if len(output_filepath) == 0:
warn(self,
self.plugin_name,
"Error in output path")
return
add_to_project = dialog.load_output_checkBox.isChecked()
else:
warn(self,
self.plugin_name,
"No export defined")
return
# get project CRS information
project_crs_osr = get_prjcrs_as_proj4str(self.canvas)
output_profile_line(
output_format,
output_filepath,
self.digitized_profile_line2dt.pts,
project_crs_osr)
# add theme to QGis project
if output_format == "shapefile - line" and add_to_project:
try:
digitized_line_layer = QgsVectorLayer(output_filepath,
QFileInfo(output_filepath).baseName(),
"ogr")
QgsProject.instance().addMapLayer(digitized_line_layer)
except:
QMessageBox.critical(self, "Result", "Unable to load layer in project")
return
def calculate_profile_statistics():
if not self.check_pre_statistics():
return
for ndx in range(self.input_geoprofiles.geoprofiles_num):
self.input_geoprofiles.geoprofile(ndx).topo_profiles.statistics_elev = [get_statistics(p) for p in self.input_geoprofiles.geoprofile(ndx).topo_profiles.profile_zs]
self.input_geoprofiles.geoprofile(ndx).topo_profiles.statistics_dirslopes = [get_statistics(p) for p in self.input_geoprofiles.geoprofile(ndx).topo_profiles.profile_dirslopes]
self.input_geoprofiles.geoprofile(ndx).topo_profiles.statistics_slopes = [get_statistics(p) for p in np.absolute(self.input_geoprofiles.geoprofile(ndx).topo_profiles.profile_dirslopes)]
self.input_geoprofiles.geoprofile(ndx).topo_profiles.profile_length = self.input_geoprofiles.geoprofile(ndx).topo_profiles.profile_s[-1] - self.input_geoprofiles.geoprofile(ndx).topo_profiles.profile_s[0]
statistics_elev = self.input_geoprofiles.geoprofile(ndx).topo_profiles.statistics_elev
self.input_geoprofiles.geoprofile(ndx).topo_profiles.natural_elev_range = (
np.nanmin(np.array([ds_stats["min"] for ds_stats in statistics_elev])),
np.nanmax(np.array([ds_stats["max"] for ds_stats in statistics_elev])))
self.input_geoprofiles.geoprofile(ndx).topo_profiles.statistics_calculated = True
dialog = StatisticsDialog(
self.plugin_name,
self.input_geoprofiles
)
dialog.exec_()
def load_line_layer():
def create_line_in_project_crs(profile_processed_line, line_layer_crs, on_the_fly_projection,
project_crs):
if not on_the_fly_projection:
return profile_processed_line
else:
return profile_processed_line.crs_project(line_layer_crs, project_crs)
def try_get_line_traces(
line_shape,
label_field_ndx: Optional[numbers.Integral],
order_field_ndx: Optional[numbers.Integral]
):
try:
profile_orig_lines, label_values, order_values = line_geoms_with_infos(line_shape, label_field_ndx, order_field_ndx)
except VectorInputException as error_msg:
return False, error_msg
return True, (profile_orig_lines, label_values, order_values)
def line_layer_params(dialog):
line_layer = dialog.line_shape
multiple_profiles = dialog.qrbtLineIsMultiProfile.isChecked()
label_field_ndx = dialog.Trace2D_label_field_comboBox.currentIndex()
order_field_ndx = dialog.Trace2D_order_field_comboBox.currentIndex()
return line_layer, multiple_profiles, label_field_ndx, order_field_ndx
self.init_topo_labels()
current_line_layers = loaded_line_layers()
if len(current_line_layers) == 0:
warn(self,
self.plugin_name,
"No available line layers")
return
dialog = SourceLineLayerDialog(self.plugin_name,
current_line_layers)
if dialog.exec_():
line_layer, multiple_profiles, label_field_ndx, order_field_ndx = line_layer_params(dialog)
else:
warn(self,
self.plugin_name,
"No defined line source")
return
line_label_fld_ndx = int(label_field_ndx) - 1 if label_field_ndx else None
line_order_fld_ndx = int(order_field_ndx) - 1 if order_field_ndx else None
areLinesToReorder = False if line_order_fld_ndx is None else True
# get profile path from input line layer
success, result = try_get_line_traces(line_layer, line_label_fld_ndx, line_order_fld_ndx)
if not success:
raise VectorIOException(result)
profile_orig_lines, label_values, order_values = result
processed_lines = []
if multiple_profiles:
if areLinesToReorder:
sorted_profiles = sort_by_external_key(
profile_orig_lines,
order_values
)
sorted_labels = list(sort_by_external_key(
label_values,
order_values
))
sorted_orders = sorted(order_values)
else:
sorted_profiles = profile_orig_lines
sorted_labels = label_values
sorted_orders = order_values
for orig_line in sorted_profiles:
processed_lines.append(merge_line(orig_line))
else:
sorted_labels = label_values
sorted_orders = order_values
processed_lines.append(merge_lines(profile_orig_lines, order_values))
# process input line layer
projected_lines = []
for processed_line in processed_lines:
projected_lines.append(
create_line_in_project_crs(
processed_line,
line_layer.crs(),
self.on_the_fly_projection,
self.project_crs
)
)
self.profiles_lines = [line.remove_coincident_points() for line in projected_lines]
self.profiles_labels = sorted_labels
self.profiles_order = sorted_orders
def load_point_list():
def get_point_list(dialog):
raw_point_string = dialog.point_list_qtextedit.toPlainText()
raw_point_list = raw_point_string.split("\n")
raw_point_list = [clean_string(str(unicode_txt)) for unicode_txt in raw_point_list]
data_list = [rp for rp in raw_point_list if rp != ""]
point_list = [to_float(xy_pair.split(",")) for xy_pair in data_list]
line2d = xytuple_list_to_Line(point_list)
return line2d
self.init_topo_labels()
dialog = LoadPointListDialog(self.plugin_name)
if dialog.exec_():
line2d = get_point_list(dialog)
else:
warn(self,
self.plugin_name,
"No defined line source")
return
try:
npts = line2d.num_pts
if npts < 2:
warn(self,
self.plugin_name,
"Defined line source with less than two points")
return
except:
warn(self,
self.plugin_name,
"No defined line source")
return
self.profiles_lines = [line2d]
def digitize_line():
def connect_digitize_maptool():
self.digitize_maptool.moved.connect(self.canvas_refresh_profile_line)
self.digitize_maptool.leftClicked.connect(self.profile_add_point)
self.digitize_maptool.rightClicked.connect(self.canvas_end_profile_line)
self.init_topo_labels()
qprof_QWidget.map_digitations += 1
self.clear_rubberband()
self.profile_canvas_points = []
if qprof_QWidget.map_digitations == 1:
info(self,
self.plugin_name,
"Now you can digitize a line on the map.\nLeft click: add point\nRight click: end adding point")
self.previous_maptool = self.canvas.mapTool() # Save the standard map tool for restoring it at the end
self.digitize_maptool = MapDigitizeTool(self.canvas) # mouse listener
self.canvas.setMapTool(self.digitize_maptool)
connect_digitize_maptool()
self.rubberband = QgsRubberBand(self.canvas)
self.rubberband.setWidth(2)
self.rubberband.setColor(QColor(Qt.red))
def select_input_gpx_file():
gpx_last_used_dir = self.settings.value(self.settings_gpxdir_key,
"")
file_name, __ = QFileDialog.getOpenFileName(self,
self.tr("Open GPX file"),
gpx_last_used_dir,
"GPX (*.gpx *.GPX)")
if not file_name:
return
else:
update_directory_key(self.settings,
self.settings_gpxdir_key,
file_name)
self.qlneInputGPXFile.setText(file_name)
def plot_topo_profiles():
def get_profile_plot_params(dialog):
profile_params = {}
# get profile plot parameters
try:
profile_params['plot_min_elevation_user'] = float(dialog.qledtPlotMinValue.text())
except:
profile_params['plot_min_elevation_user'] = None
try:
profile_params['plot_max_elevation_user'] = float(dialog.qledtPlotMaxValue.text())
except:
profile_params['plot_max_elevation_user'] = None
profile_params['set_vertical_exaggeration'] = dialog.qcbxSetVerticalExaggeration.isChecked()
try:
profile_params['vertical_exaggeration'] = float(dialog.qledtDemExagerationRatio.text())
assert profile_params['vertical_exaggeration'] > 0
except:
profile_params['vertical_exaggeration'] = 1
profile_params['filled_height'] = dialog.qcbxPlotFilledHeight.isChecked()
profile_params['filled_slope'] = dialog.qcbxPlotFilledSlope.isChecked()
profile_params['plot_height_choice'] = dialog.qcbxPlotProfileHeight.isChecked()
profile_params['plot_slope_choice'] = dialog.qcbxPlotProfileSlope.isChecked()
profile_params['plot_slope_absolute'] = dialog.qrbtPlotAbsoluteSlope.isChecked()
profile_params['plot_slope_directional'] = dialog.qrbtPlotDirectionalSlope.isChecked()
profile_params['invert_xaxis'] = dialog.qcbxInvertXAxisProfile.isChecked()
surface_names = self.input_geoprofiles.geoprofile(0).topo_profiles.surface_names
if hasattr(dialog, 'visible_elevation_layers') and dialog.visible_elevation_layers is not None:
profile_params['visible_elev_lyrs'] = dialog.visible_elevation_layers
else:
profile_params['visible_elev_lyrs'] = surface_names
if hasattr(dialog, 'elevation_layer_colors') and dialog.elevation_layer_colors is not None:
profile_params['elev_lyr_colors'] = dialog.elevation_layer_colors
else:
profile_params['elev_lyr_colors'] = [QColor('red')] * len(surface_names)
return profile_params
if not self.check_pre_profile():
return
natural_elev_min_set = []
natural_elev_max_set = []
profile_length_set = []
for geoprofile in self.input_geoprofiles.geoprofiles:
natural_elev_min, natural_elev_max = geoprofile.topo_profiles.natural_elev_range
natural_elev_min_set.append(natural_elev_min)
natural_elev_max_set.append(natural_elev_max)
profile_length_set.append(geoprofile.topo_profiles.profile_length)
surface_names = geoprofile.topo_profiles.surface_names
if self.input_geoprofiles.plot_params is None:
surface_colors = None
else:
surface_colors = self.input_geoprofiles.plot_params.get('elev_lyr_colors')
dialog = PlotTopoProfileDialog(self.plugin_name,
profile_length_set,
natural_elev_min_set,
natural_elev_max_set,
surface_names,
surface_colors)
if dialog.exec_():
self.input_geoprofiles.plot_params = get_profile_plot_params(dialog)
else:
return
self.input_geoprofiles.profiles_created = True
# plot profiles
plot_addit_params = dict()
plot_addit_params["add_trendplunge_label"] = self.plot_prj_add_trendplunge_label.isChecked()
plot_addit_params["add_ptid_label"] = self.plot_prj_add_pt_id_label.isChecked()
plot_addit_params["polygon_class_colors"] = self.polygon_classification_colors
plot_addit_params["plane_attitudes_colors"] = self.plane_attitudes_colors
profile_window = plot_geoprofiles(self.input_geoprofiles,
plot_addit_params)
self.profile_windows.append(profile_window)
qwdgTopoProfile = QWidget()
qlytTopoProfile = QVBoxLayout()
## Input data
qgbxTopoSources = QGroupBox(qwdgTopoProfile)
qgbxTopoSources.setTitle("Topographic profile sources")
qlyTopoSources = QVBoxLayout()
####
qtbxDataInput = QToolBox()
self.on_the_fly_projection, self.project_crs = get_on_the_fly_projection(self.canvas)
qwdgDEMInput = QWidget()
qlytDEMInput = QVBoxLayout()
## input DEM section
inputDEM_QGroupBox = QGroupBox()
inputDEM_QGroupBox.setTitle("Input DEMs")
inputDEM_Layout = QVBoxLayout()
self.DefineSourceDEMs_pushbutton = QPushButton(self.tr("Define source DEMs"))
self.DefineSourceDEMs_pushbutton.clicked.connect(define_source_DEMs)
inputDEM_Layout.addWidget(self.DefineSourceDEMs_pushbutton)
inputDEM_QGroupBox.setLayout(inputDEM_Layout)
qlytDEMInput.addWidget(inputDEM_QGroupBox)
## input Line layer section
qgbxInputLine = QGroupBox()
qgbxInputLine.setTitle("Input line")
qlytInputLine = QGridLayout()
self.qcbxDigitizeLineSource = QRadioButton(self.tr("Digitized line"))
self.qcbxDigitizeLineSource.setChecked(True)
qlytInputLine.addWidget(self.qcbxDigitizeLineSource, 0, 0, 1, 1)
#
self.qpbtDigitizeLine = QPushButton(self.tr("Digitize line"))
self.qpbtDigitizeLine.clicked.connect(digitize_line)
self.qpbtDigitizeLine.setToolTip("Digitize a line on the map.\n"
"Left click: add point\n"
"Right click: end adding point\n"
"From: Define topographic sources (below)\n"
"you can use also an existing line\n"
"or a point list")
qlytInputLine.addWidget(self.qpbtDigitizeLine, 0, 1, 1, 1)
self.qpbtClearLine = QPushButton(self.tr("Clear"))
self.qpbtClearLine.clicked.connect(self.clear_rubberband)
qlytInputLine.addWidget(self.qpbtClearLine, 0, 2, 1, 1)
self.qpbtClearLine = QPushButton(self.tr("Save"))
self.qpbtClearLine.clicked.connect(save_rubberband)
qlytInputLine.addWidget(self.qpbtClearLine, 0, 3, 1, 1)
#
self.qrbtLoadLineLayer = QRadioButton(self.tr("Line layer"))
qlytInputLine.addWidget(self.qrbtLoadLineLayer, 1, 0, 1, 1)
self.qpbtDefineLineLayer = QPushButton(self.tr("Choose layer"))
self.qpbtDefineLineLayer.clicked.connect(load_line_layer)
qlytInputLine.addWidget(self.qpbtDefineLineLayer, 1, 1, 1, 3)
self.qrbtPointListforLine = QRadioButton(self.tr("Point list"))
qlytInputLine.addWidget(self.qrbtPointListforLine, 2, 0, 1, 1)
self.qpbtDefinePointList = QPushButton(self.tr("Create list"))
self.qpbtDefinePointList.clicked.connect(load_point_list)
qlytInputLine.addWidget(self.qpbtDefinePointList, 2, 1, 1, 3)
# trace sampling spat_distance
qlytInputLine.addWidget(QLabel(self.tr("line densify distance")), 3, 0, 1, 1)
self.qledProfileDensifyDistance = QLineEdit()
qlytInputLine.addWidget(self.qledProfileDensifyDistance, 3, 1, 1, 3)
qgbxInputLine.setLayout(qlytInputLine)
qlytDEMInput.addWidget(qgbxInputLine)
qwdgDEMInput.setLayout(qlytDEMInput)
qtbxDataInput.addItem(qwdgDEMInput, "DEM input")
#
qwdgGPXInput = QWidget()
qlytGPXInput = QGridLayout()
qlytGPXInput.addWidget(QLabel(self.tr("Choose input file:")), 0, 0, 1, 1)
self.qlneInputGPXFile = QLineEdit()
self.qlneInputGPXFile.setPlaceholderText("my_track.gpx")
qlytGPXInput.addWidget(self.qlneInputGPXFile, 0, 1, 1, 1)
self.qphbInputGPXFile = QPushButton("...")
self.qphbInputGPXFile.clicked.connect(select_input_gpx_file)
qlytGPXInput.addWidget(self.qphbInputGPXFile, 0, 2, 1, 1)
qwdgGPXInput.setLayout(qlytGPXInput)
qtbxDataInput.addItem(qwdgGPXInput, "GPX input")
#
qlyTopoSources.addWidget(qtbxDataInput)
#
qwgtDoTopoDataRead = QWidget()
qlytDoTopoDataRead = QGridLayout()
self.qrbtDEMDataType = QRadioButton("DEM input")
self.qrbtDEMDataType.setChecked(True)
qlytDoTopoDataRead.addWidget(self.qrbtDEMDataType, 0, 0, 1, 1)
self.qrbtGPXDataType = QRadioButton("GPX input")
qlytDoTopoDataRead.addWidget(self.qrbtGPXDataType, 0, 1, 1, 1)
self.qcbxInvertProfile = QCheckBox("Invert orientation")
qlytDoTopoDataRead.addWidget(self.qcbxInvertProfile, 0, 2, 1, 1)
self.qpbtReadData = QPushButton("Read source data")
self.qpbtReadData.clicked.connect(create_topo_profiles)
qlytDoTopoDataRead.addWidget(self.qpbtReadData, 1, 0, 1, 3)
qwgtDoTopoDataRead.setLayout(qlytDoTopoDataRead)
##
qlyTopoSources.addWidget(qwgtDoTopoDataRead)
qgbxTopoSources.setLayout(qlyTopoSources)
qlytTopoProfile.addWidget(qgbxTopoSources)
## Profile statistics
qgbxProfStats = QGroupBox(qwdgTopoProfile)
qgbxProfStats.setTitle("Profile statistics")
qlytProfStats = QGridLayout()
self.qpbtProfileStats = QPushButton(self.tr("Calculate profile statistics"))
self.qpbtProfileStats.clicked.connect(calculate_profile_statistics)
qlytProfStats.addWidget(self.qpbtProfileStats, 0, 0, 1, 3)
qgbxProfStats.setLayout(qlytProfStats)
qlytTopoProfile.addWidget(qgbxProfStats)
## Create profile section
qgbxPlotProfile = QGroupBox(qwdgTopoProfile)
qgbxPlotProfile.setTitle('Profile plot')
qlytPlotProfile = QGridLayout()
self.qpbtPlotProfileCreate = QPushButton(self.tr("Create topographic profile"))
self.qpbtPlotProfileCreate.clicked.connect(plot_topo_profiles)
qlytPlotProfile.addWidget(self.qpbtPlotProfileCreate, 0, 0, 1, 4)
qgbxPlotProfile.setLayout(qlytPlotProfile)
qlytTopoProfile.addWidget(qgbxPlotProfile)
###################
qwdgTopoProfile.setLayout(qlytTopoProfile)
return qwdgTopoProfile
def setup_geology_section_tab(self):
section_geology_QWidget = QWidget()
section_geology_layout = QVBoxLayout()
geology_toolbox = QToolBox()
### Point project toolbox
xs_point_proj_QWidget = QWidget()
qlytXsPointProj = QVBoxLayout()
## input section
qgbxXsInputPointProj = QGroupBox(xs_point_proj_QWidget)
qgbxXsInputPointProj.setTitle('Input')
qlytXsInputPointProj = QGridLayout()
# input point geological layer