-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLSDAnalysisDriver.cpp
More file actions
2287 lines (2026 loc) · 78.4 KB
/
LSDAnalysisDriver.cpp
File metadata and controls
2287 lines (2026 loc) · 78.4 KB
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
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// LSDAnalysisDriver.cpp
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// This object parses parameter files and drives analysis. Its purpose is
// to stop having to write a bunch of .cpp driver functions and instead
// be able to write a parameter files without compiling
//
// Developed by:
// Simon M. Mudd
// Martin D. Hurst
// David T. Milodowski
// Stuart W.D. Grieve
// Declan A. Valters
// Fiona Clubb
//
// Copyright (C) 2013 Simon M. Mudd 2013
//
// Developer can be contacted by simon.m.mudd _at_ ed.ac.uk
//
// Simon Mudd
// University of Edinburgh
// School of GeoSciences
// Drummond Street
// Edinburgh, EH8 9XP
// Scotland
// United Kingdom
//
// 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;
// without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the
// GNU General Public License along with this program;
// if not, write to:
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301
// USA
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <fstream>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include "LSDStatsTools.hpp"
#include "LSDRaster.hpp"
#include "LSDAnalysisDriver.hpp"
#include "LSDJunctionNetwork.hpp"
#include "LSDChannel.hpp"
using namespace std;
#ifndef LSDAnalysisDriver_CPP
#define LSDAnalysisDriver_CPP
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// The default constructor. This asks the user for a pathname and
// param filename
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDAnalysisDriver::create()
{
cout << "I need a parameter file to run. Please enter the path: " << endl;
cin >> pathname;
check_pathname_for_slash();
cout << "Now I need a parameter filename: " << endl;
cin >> param_fname;
got_flowinfo = false;
got_polyfit = false;
got_JunctionNetwork = false;
ingest_data(pathname, param_fname);
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// This constructor runs with the path and filename
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDAnalysisDriver::create(string pname, string fname)
{
pathname = pname;
check_pathname_for_slash();
param_fname = fname;
got_flowinfo = false;
got_polyfit = false;
got_JunctionNetwork = false;
ingest_data(pathname, param_fname);
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// This function gets all the data from a parameter file
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDAnalysisDriver::ingest_data(string pname, string p_fname)
{
// the full name of the file
string full_name = pname+p_fname;
ifstream infile;
infile.open(full_name.c_str());
string parameter, value, lower, lower_val;
string bc;
cout << "Parameter filename is: " << full_name << endl;
// now ingest parameters
while (infile.good())
{
parse_line(infile, parameter, value);
lower = parameter;
if (parameter == "NULL")
continue;
for (unsigned int i=0; i<parameter.length(); ++i)
{
lower[i] = tolower(parameter[i]);
}
cout << "parameter is: " << lower << " and value is: " << value << endl;
// get rid of control characters
value = RemoveControlCharactersFromEndOfString(value);
if (lower == "dem read extension")
{
dem_read_extension = value;
// get rid of any control characters from the end (if param file was made in DOS)
dem_read_extension = RemoveControlCharactersFromEndOfString(dem_read_extension);
}
else if (lower == "dem write extension")
{
dem_write_extension = value;
// get rid of any control characters from the end (if param file was made in DOS)
dem_write_extension = RemoveControlCharactersFromEndOfString(dem_write_extension);
}
else if (lower == "write path")
{
write_path = value;
// get rid of any control characters from the end (if param file was made in DOS)
write_path = RemoveControlCharactersFromEndOfString(write_path);
}
else if (lower == "write fname")
{
write_fname = value;
// get rid of any control characters from the end (if param file was made in DOS)
write_fname = RemoveControlCharactersFromEndOfString(write_fname);
//cout << "Got the write name, it is: " << write_fname << endl;
}
else if (lower == "read path")
{
read_path = value;
// get rid of any control characters from the end (if param file was made in DOS)
read_path = RemoveControlCharactersFromEndOfString(read_path);
//cout << "Got the write name, it is: " << write_fname << endl;
}
else if (lower == "read fname")
{
read_fname = value;
// get rid of any control characters from the end (if param file was made in DOS)
read_fname = RemoveControlCharactersFromEndOfString(read_fname);
//cout << "Got the read name, it is: " << read_fname << endl;
}
//=-=-=-=-=-=--=-=-=-=-
// paramters for fill
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "min_slope_for_fill")
{
float_parameters["min_slope_for_fill"] = atof(value.c_str());
}
else if (lower == "fill_method")
{
method_map["fill_method"] = value;
method_map["fill_method"] = RemoveControlCharactersFromEndOfString(method_map["fill_method"]);
}
//=-=-=-=-=-=--=-=-=-=-
// paramters for hillshade
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "hs_altitude")
{
float_parameters["hs_altitude"] = atof(value.c_str());
}
else if (lower == "hs_azimuth")
{
float_parameters["hs_azimuth"] = atof(value.c_str());
}
else if (lower == "hs_z_factor")
{
float_parameters["hs_z_factor"] = atof(value.c_str());
}
else if (lower == "hs_use_fill")
{
//cout << "Use hs bool: " << value << endl;
bool temp_bool = (value == "true") ? true : false;
//cout << "Temp bool: " << temp_bool << endl;
//bool tbool = true;
//bool fbool = false;
//cout << "True is " << tbool << " and false is: " << fbool << endl;
analyses_switches["hs_use_fill"] = temp_bool;
cout << "You have set use of the fill raster for the hillshade to "
<< analyses_switches["hs_use_fill"] << endl;
}
//=-=-=-=-=-=--=-=-=-=-
// parameters for flow info
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "boundary conditions")
{
// get the boundary value in lowercase
lower_val = value;
for (unsigned int i=0; i<value.length(); ++i)
{
lower_val[i] = tolower(value[i]);
}
vector<string> temp_bc(4);
bc = lower_val;
// now loop through collecting boundary conditions
for (int i = 0; i<4; i++)
{
string this_bc = bc.substr(i,1);
//cout << "Component " << i << " of the bc string: " << this_bc << endl;
if (this_bc.find("p") != 0 && this_bc.find("b") != 0 && this_bc.find("n") != 0)
{
cout << "boundary condition not periodic, baselevel or noflux!" << endl;
cout << "defaulting to no flux" << endl;
temp_bc[i] = "n";
}
else
{
temp_bc[i] = this_bc;
}
}
boundary_conditions = temp_bc;
}
//=-=-=-=-=-=--=-=-=-=-
// parameters for chi
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "nodeindex fname for chi map")
{
support_file_names["nodeindex_fname_for_chi_map"] = atof(value.c_str());
}
else if (lower == "a_0")
{
float_parameters["A_0"] = atof(value.c_str());
}
else if (lower == "m_over_n")
{
float_parameters["m_over_n"] = atof(value.c_str());
}
else if (lower == "threshold_area_for_chi")
{
float_parameters["threshold_area_for_chi"] = atof(value.c_str());
}
//=-=-=-=-=-=--=-=-=-=-
// parameters for polyfit
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "polyfit_window_radius")
{
float_parameters["polyfit_window_radius"] = atof(value.c_str());
cout << "Your polyfit window radius is: " << float_parameters["polyfit_window_radius"] << endl;
}
else if (lower == "slope_method")
{
method_map["slope_method"] = value;
// get rid of any control characters from the end (if param file was made in DOS)
method_map["slope_method"] = RemoveControlCharactersFromEndOfString(method_map["slope_method"]);
cout << "Your slope method is: " << method_map["slope_method"] << endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-
// parameters for drainage area extraction
//=-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "drainage_area_method")
{
method_map["drainage_area_method"] = value;
// get rid of any control characters from the end (if param file was made in DOS)
method_map["drainage_area_method"] = RemoveControlCharactersFromEndOfString(method_map["drainage_area_method"]);
}
//=-=-=-=-=-=-=-=-=-=-=-=-
// parameters for single thread channel extraction
//=-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "single_thread_channel_method")
{
method_map["single_thread_channel_method"] = value;
// get rid of any control characters from the end (if param file was made in DOS)
method_map["single_thread_channel_method"] =
RemoveControlCharactersFromEndOfString(method_map["single_thread_channel_method"]);
}
//=-=-=-=-=-=--=-=-=-=-
// parameters for area threshold channel network
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "pixel_threshold_for_channel_net")
{
float_parameters["pixel_threshold_for_channel_net"] = atof(value.c_str());
}
//=-=-=-=-=-=--=-=-=-=-
// parameters for landscape properties
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "root_cohesion")
{
float_parameters["root_cohesion"] = atof(value.c_str());
cout << "Your root_cohesion is: " << float_parameters["root_cohesion"] << endl;
}
else if (lower == "soil_density")
{
float_parameters["soil_density"] = atof(value.c_str());
cout << "Your soil_density is: " << float_parameters["soil_density"] << endl;
}
else if (lower == "hydraulic_conductivity")
{
float_parameters["hydraulic_conductivity"] = atof(value.c_str());
cout << "Your hydraulic_conductivity is: " << float_parameters["hydraulic_conductivity"] << endl;
}
else if (lower == "soil_thickness")
{
float_parameters["soil_thickness"] = atof(value.c_str());
cout << "Your soil_thickness is: " << float_parameters["soil_thickness"] << endl;
}
else if (lower == "tan_phi")
{
float_parameters["tan_phi"] = atof(value.c_str());
cout << "Your tan_phi is: " << float_parameters["tan_phi"] << endl;
}
//=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=
// parameters for nodata hole filling
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "nodata_hole_filling_window_width")
{
float_parameters["nodata_hole_filling_window_width"] = atof(value.c_str());
cout << "Your hole_filling_window is: "
<< float_parameters["nodata_hole_filling_window_width"] << " pixels" << endl;
}
//=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=
// parameters for masking
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "curvature_mask_threshold")
{
float_parameters["curvature_mask_threshold"] = atof(value.c_str());
cout << "Your curvature_mask_threshold is: "
<< float_parameters["curvature_mask_threshold"] << " 1/m" << endl;
}
else if (lower == "curvature_mask_nodataisbelowthreshold")
{
int_parameters["curvature_mask_nodataisbelowthreshold"] = atoi(value.c_str());
cout << "Your curvature_mask_nodataisbelowthreshold is: "
<< int_parameters["curvature_mask_nodataisbelowthreshold"] << "; anything other than 0 means true." << endl;
}
else if (lower == "mask_threshold")
{
float_parameters["mask_threshold"] = atof(value.c_str());
cout << "Mask_threshold is: "
<< float_parameters["mask_threshold"] << " (dimensions depend on raster)" << endl;
}
else if (lower == "mask_nodataisbelowthreshold")
{
int_parameters["mask_nodataisbelowthreshold"] = atoi(value.c_str());
cout << "Your mask_nodataisbelowthreshold is: "
<< int_parameters["mask_nodataisbelowthreshold"] << "; anything other than 0 means true." << endl;
}
//=-=-=-=-=-=--=-=-=-=-
// what to write
//-=-=-=-=-=-=-=-=-=-=-=-
else if (lower == "write fill")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_fill"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
}
else if (lower == "write trimmed and nodata filled")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_trim_ndfill"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_trimmed_hole_filled"] = temp_bool;
}
else if (lower == "write hillshade")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_hillshade"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_hillshade"] = temp_bool;
}
else if (lower == "write mask threshold")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_mask_threshold"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_mask_threshold"] = temp_bool;
}
else if (lower == "write slope")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_slope"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
raster_switches["need_slope"] = temp_bool;
}
else if (lower == "write curvature")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_curvature"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_curvature"] = temp_bool;
}
else if (lower == "write curvature mask threshold")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_curvature_mask_threshold"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_curvature"] = temp_bool;
raster_switches["need_curvature_mask_threshold"] = temp_bool;
}
else if (lower == "write planform curvature")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_planform_curvature"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_planform_curvature"] = temp_bool;
}
else if (lower == "write tangential curvature")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_tangential_curvature"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_tangential_curvature"] = temp_bool;
}
else if (lower == "write profile curvature")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_profile_curvature"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_profile_curvature"] = temp_bool;
}
else if (lower == "write aspect")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_aspect"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_aspect"] = temp_bool;
}
else if (lower == "write topographic classification")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_topographic_classification"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_topographic_classification"] = temp_bool;
}
else if (lower == "write drainage area")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_drainage_area"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
raster_switches["need_drainage_area"] = temp_bool;
}
else if (lower == "write channel net")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_channel_net"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
raster_switches["need_flowinfo"] = temp_bool;
raster_switches["need_ContributingPixels"] = temp_bool;
raster_switches["need_JunctionNetwork"] = temp_bool;
raster_switches["need_sources"] = temp_bool;
raster_switches["need_SOArray"] = temp_bool;
raster_switches["need_JunctionIndex"] = temp_bool;
}
else if (lower == "write nodeindex")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_nodeindex"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
raster_switches["need_flowinfo"] = temp_bool;
raster_switches["need_nodeindex"] = temp_bool;
}
else if (lower == "write single thread channel")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_single_thread_channel"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
raster_switches["need_flowinfo"] = temp_bool;
raster_switches["need_flow_distance"] = temp_bool;
raster_switches["need_drainage_area"] = temp_bool;
}
else if (lower == "write chi map")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_chi_map"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
raster_switches["need_flowinfo"] = temp_bool;
raster_switches["need_chi_map"] = temp_bool;
}
else if (lower == "write factor of safety at saturation")
{
bool temp_bool = (value == "true") ? true : false;
analyses_switches["write_FS_sat"] = temp_bool;
raster_switches["need_base_raster"] = temp_bool;
raster_switches["need_fill"] = temp_bool;
raster_switches["need_slope"] = temp_bool;
raster_switches["need_slope_angle"] = temp_bool;
raster_switches["need_FS_sat"] = temp_bool;
}
else
{
cout << "Line " << __LINE__ << ": No parameter '"
<< parameter << "' expected.\n\t> Check spelling." << endl;
}
//cout << "Got " << lower << " and value is: " << value << endl;
}
infile.close();
cout << "I'm checking to make sure the filenames are compatible now." << endl;
check_file_extensions_and_paths();
cout << "Ingestion of parameter file complete, and pathnames checked.\n"
<< "I am now moving on to computing the rasters. \n\n";
compute_rasters_from_raster_switches();
cout << "I've finished computing the rasters.\n"
<< "I am now moving on to writing the data. \n\n";
write_rasters_from_analysis_switches();
cout << "Well I guess I am all finished now. I sure hope you got what you wanted! Have a nice day." << endl;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// this is a wrapper function that loops through the maps of raster switches
// gets the desired rasters, and then prints where necessary
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDAnalysisDriver::compute_rasters_from_raster_switches()
{
cout << "LINE 250, computing rasters" << endl;
// read the base raster
if(raster_switches.find("need_base_raster") != raster_switches.end())
{
//cout<<"LINE 255 I am loading the base raster now"<<endl;
read_base_raster();
}
// get the fill raster
if(raster_switches.find("need_fill") != raster_switches.end())
{
//cout<<"LINE 262 I need to compute fill!!!"<<endl;
// check to see if the base raster is loaded
if(map_of_LSDRasters.find("base_raster") == map_of_LSDRasters.end())
{
//cout << "Base raster hasn't been loaded. Loading it now." << endl;
read_base_raster();
// now the base raster is in the map
fill_raster();
}
else
{
fill_raster();
}
}
// get trimmed and nodata filled raster
if(raster_switches.find("need_trimmed_hole_filled") != raster_switches.end())
{
if(map_of_LSDRasters.find("trimmed_hole_filled") == map_of_LSDRasters.end())
{
calculate_trimmed_and_nodata_filled();
}
}
// get the hillshade
if(raster_switches.find("need_hillshade") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("hillshade") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_hillshade();
}
}
// get a thresholded map
if(raster_switches.find("need_mask_threshold") != raster_switches.end())
{
// check to see if curvature maskhas already been calculated
if(map_of_LSDRasters.find("mask_threshold") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_mask_threshold();
}
}
// get the slope
if(raster_switches.find("need_slope") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("slope") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_slope();
}
}
// get the angle
if(raster_switches.find("need_slope_angle") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("slope_angle") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_slope_angle();
}
}
// get the aspect
if(raster_switches.find("need_aspect") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("aspect") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_polyfit();
}
}
// get the curvature
if(raster_switches.find("need_curvature") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("curvature") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_polyfit();
}
}
// get the curvature threshold map
if(raster_switches.find("need_curvature_mask_threshold") != raster_switches.end())
{
// check to see if curvature has already been calculated
if(map_of_LSDRasters.find("curvature") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_polyfit();
}
// check to see if curvature maskhas already been calculated
if(map_of_LSDIndexRasters.find("curvature_mask_threshold") == map_of_LSDIndexRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_curvature_mask_threshold();
}
}
// get the planform curvature
if(raster_switches.find("need_planform_curvature") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("planform_curvature") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_polyfit();
}
}
// get the profile curvature
if(raster_switches.find("need_profile_curvature") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("profile_curvature") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_polyfit();
}
}
// get the tangential curvature
if(raster_switches.find("need_tangential_curvature") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("tangential_curvature") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_polyfit();
}
}
// get the classification
if(raster_switches.find("need_polyfit_classification") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("polyfit_classification") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_polyfit();
}
}
// get the drainage area
if(raster_switches.find("need_drainage_area") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("drainage_area") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_drainage_area();
}
}
// get the angle
if(raster_switches.find("need_FS_sat") != raster_switches.end())
{
// check to see if it has already been calculated
if(map_of_LSDRasters.find("FS_sat") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_FS_sat();
}
}
// get the flow info
if(raster_switches.find("need_flowinfo") != raster_switches.end())
{
cout << "Hey buddy, I need to get the FlowInfo object" << endl;
// only calculate flow info if it has not already been calculated
if (not got_flowinfo)
{
calculate_flowinfo();
}
}
LSDJunctionNetwork JN;
// get the junction network
if(raster_switches.find("need_JunctionNetwork") != raster_switches.end())
{
cout << "Hey buddy, I need to get the JunctionNetwork object" << endl;
// only calculate flow info if it has not already been calculated
if (not got_JunctionNetwork)
{
JN = calculate_JunctionNetwork();
}
}
// get the sources
if(raster_switches.find("need_sources") != raster_switches.end())
{
// check to see if it has already been calculated
if(integer_vector_map.find("sources") ==integer_vector_map.end())
{
// it hasn't been calculated. Calculate it now.
calculate_sources();
}
}
// get the Stream order array
if(raster_switches.find("need_SOArray") != raster_switches.end())
{
//cout << "Hey buddy, I need to get the FlowInfo object" << endl;
// only calculate flow info if it has not already been calculated
if(map_of_LSDIndexRasters.find("SOArray") == map_of_LSDIndexRasters.end())
{
calculate_SOArray(JN);
}
}
// get the JunctionIndex aray
if(raster_switches.find("need_JunctionIndex") != raster_switches.end())
{
//cout << "Hey buddy, I need to get the FlowInfo object" << endl;
// only calculate flow info if it has not already been calculated
if(map_of_LSDIndexRasters.find("JunctionIndex") == map_of_LSDIndexRasters.end())
{
calculate_JunctionIndex(JN);
}
}
// get the contributing pixels
if(raster_switches.find("need_ContributingPixel") != raster_switches.end())
{
//cout << "Hey buddy, I need to get the FlowInfo object" << endl;
// only calculate flow info if it has not already been calculated
if(map_of_LSDIndexRasters.find("ContributingPixels") == map_of_LSDIndexRasters.end())
{
calculate_ContributingPixels();
}
}
// check to see if you need the nodeindex raster
if(raster_switches.find("need_nodeindex") != raster_switches.end())
{
//cout << "Hey buddy, I need to get the nodeindex object" << endl;
// check to see if it has already been calculated
if(map_of_LSDIndexRasters.find("nodeindex") == map_of_LSDIndexRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_nodeindex();
}
}
// check to see if you need the chi raster
if(raster_switches.find("need_chi_map") != raster_switches.end())
{
//cout << "Hey buddy, I sure can compute the chi map for ya. " << endl;
// check to see if it has already been calculated
if(map_of_LSDRasters.find("chi_map") == map_of_LSDRasters.end())
{
// it hasn't been calculated. Calculate it now.
calculate_chi_map();
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Reads the base raster for analysis
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDAnalysisDriver::write_rasters_from_analysis_switches()
{
if(analyses_switches.find("write_fill") != analyses_switches.end())
{
//cout << "LINE 323, so you want me to write fill? Okay." << endl;
if(map_of_LSDRasters.find("fill") == map_of_LSDRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
compute_rasters_from_raster_switches();
}
string fill_seperator = "_fill";
string fill_fname = write_path+write_fname+fill_seperator;
map_of_LSDRasters["fill"].write_raster(fill_fname,dem_write_extension);
}
// write the trimmed and no data filled
if(analyses_switches.find("write_trim_ndfill") != analyses_switches.end())
{
if(map_of_LSDRasters.find("trimmed_hole_filled") == map_of_LSDRasters.end())
{
calculate_trimmed_and_nodata_filled();
}
string ndh_fill_seperator = "_trim_ndf";
string ndh_fill_fname = write_path+write_fname+ndh_fill_seperator;
map_of_LSDRasters["trimmed_hole_filled"].write_raster(ndh_fill_fname,dem_write_extension);
}
// write the hillshade
if(analyses_switches.find("write_hillshade") != analyses_switches.end())
{
//cout << "LINE 323, so you want me to write fill? Okay." << endl;
if(map_of_LSDRasters.find("hillshade") == map_of_LSDRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
compute_rasters_from_raster_switches();
}
string r_seperator = "_hs";
string r_fname = write_path+write_fname+r_seperator;
map_of_LSDRasters["hillshade"].write_raster(r_fname,dem_write_extension);
}
// write curvature
if(analyses_switches.find("write_mask_threshold") != analyses_switches.end())
{
// check to see if the slope map exists
if(map_of_LSDIndexRasters.find("mask_threshold") == map_of_LSDIndexRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
calculate_mask_threshold();
}
string mask_seperator = "_THMASK";
string mask_fname = write_path+write_fname+mask_seperator;
map_of_LSDRasters["mask_threshold"].write_raster(mask_fname,dem_write_extension);
}
// write slope
if(analyses_switches.find("write_slope") != analyses_switches.end())
{
// check to see if the slope map exists
if(map_of_LSDRasters.find("slope") == map_of_LSDRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
calculate_slope();
}
string slope_seperator = "_slope";
string slope_fname = write_path+write_fname+slope_seperator;
map_of_LSDRasters["slope"].write_raster(slope_fname,dem_write_extension);
}
// write slope
if(analyses_switches.find("write_FS_sat") != analyses_switches.end())
{
// check to see if the slope map exists
if(map_of_LSDRasters.find("FS_sat") == map_of_LSDRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
calculate_FS_sat();
}
string slope_seperator = "_FSsat";
string slope_fname = write_path+write_fname+slope_seperator;
map_of_LSDRasters["FS_sat"].write_raster(slope_fname,dem_write_extension);
}
// write aspect
if(analyses_switches.find("write_aspect") != analyses_switches.end())
{
// check to see if the slope map exists
if(map_of_LSDRasters.find("aspect") == map_of_LSDRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
calculate_polyfit();
}
string aspect_seperator = "_aspect";
string aspect_fname = write_path+write_fname+aspect_seperator;
map_of_LSDRasters["aspect"].write_raster(aspect_fname,dem_write_extension);
}
// write curvature
if(analyses_switches.find("write_curvature") != analyses_switches.end())
{
// check to see if the slope map exists
if(map_of_LSDRasters.find("curvature") == map_of_LSDRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
calculate_polyfit();
}
string curvature_seperator = "_curvature";
string curvature_fname = write_path+write_fname+curvature_seperator;
map_of_LSDRasters["curvature"].write_raster(curvature_fname,dem_write_extension);
}
// write curvature
if(analyses_switches.find("write_curvature_mask_threshold") != analyses_switches.end())
{
// check to see if the slope map exists
if(map_of_LSDIndexRasters.find("curvature_mask_threshold") == map_of_LSDIndexRasters.end())
{
//cout << "You've not run the get raster routine. Running now. " << endl;
calculate_curvature_mask_threshold();
}
string curvature_seperator = "_curvature_mask";
string curvature_fname = write_path+write_fname+curvature_seperator;
map_of_LSDIndexRasters["curvature_mask_threshold"].write_raster(curvature_fname,dem_write_extension);
}
// write profile curvature
if(analyses_switches.find("write_profile_curvature") != analyses_switches.end())
{
// check to see if the slope map exists