-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLSDIndexChannel.hpp
More file actions
289 lines (251 loc) · 10.4 KB
/
Copy pathLSDIndexChannel.hpp
File metadata and controls
289 lines (251 loc) · 10.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
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// LSDIndexChannel
// Land Surface Dynamics IndexChannel
//
// An object within the University
// of Edinburgh Land Surface Dynamics group topographic toolbox
// for retaining information of channels
//
// Data is mostly pointers to indeces withing the LSDFlowInfo object
// For data about the actuall channel details such as elevation,
// drainage area, etc. once needs to use the derivative class
// LSDChannel
//
// 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
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/** @file LSDIndexChannel.hpp
@author Simon M. Mudd, University of Edinburgh
@author David Milodowski, University of Edinburgh
@author Martin D. Hurst, British Geological Survey
@author Stuart W. D. Grieve, University of Edinburgh
@author Fiona Clubb, University of Edinburgh
@version Version 0.0.1
@brief This object contains the node indices as well as the
row and col indices for individual channel segments.
@details These indices could be arranged arbitrailiy according to channel
junctions or simply nodes downstream of a given node and upstream
of another arbitrary node EndNode.
@date 30/08/2012
*/
#include <vector>
#include "TNT/tnt.h"
#include "LSDFlowInfo.hpp"
using namespace std;
using namespace TNT;
#ifndef LSDIndexChannel_H
#define LSDIndexChannel_H
///@brief This object contains the node indexes as well as the
///row and col indices for individual channel segments.
class LSDIndexChannel
{
public:
/// @brief The create function. This is default and throws an error.
LSDIndexChannel() { create(); }
/// @brief Create LSDIndexChannel object between a start and end node.
/// @param StartNode Integer starting node.
/// @param EndNode Integer ending node.
/// @param FlowInfo LSDFlowInfo object.
LSDIndexChannel(int StartNode, int EndNode, LSDFlowInfo& FlowInfo)
{ create(StartNode, EndNode, FlowInfo); }
/// @brief Create LSDIndexChannel object between starting junction and node and ending junction and node.
/// @param StartJunction Integer starting junction.
/// @param StartNode Integer starting node.
/// @param EndJunction Integer ending junction.
/// @param EndNode Integer ending node.
/// @param FlowInfo LSDFlowInfo object.
LSDIndexChannel(int StartJunction, int StartNode,
int EndJunction, int EndNode, LSDFlowInfo& FlowInfo)
{ create(StartJunction,StartNode,EndJunction,EndNode, FlowInfo); }
LSDIndexChannel(vector<float>& X_coords, vector<float>& Y_coords, LSDFlowInfo& FlowInfo, float threshold_area, float threshold_distance)
{ create(X_coords, Y_coords, FlowInfo, threshold_area, threshold_distance); }
// get functions
/// @return Starting junction ID.
int get_StartJunction() const { return StartJunction; }
/// @return Ending junciton ID.
int get_EndJunction() const { return EndJunction; }
/// @return Starting node ID.
int get_StartNode() const { return StartNode; }
/// @return Ending Node ID.
int get_EndNode() const { return EndNode; }
/// @return Number of rows as an integer.
int get_NRows() const { return NRows; }
/// @return Number of columns as an integer.
int get_NCols() const { return NCols; }
/// @return Minimum X coordinate as an integer.
float get_XMinimum() const { return XMinimum; }
/// @return Minimum Y coordinate as an integer.
float get_YMinimum() const { return YMinimum; }
/// @return Data resolution as an integer.
float get_DataResolution() const { return DataResolution; }
/// @return No Data Value as an integer.
int get_NoDataValue() const { return NoDataValue; }
/// @return Georeferencing information
map<string,string> get_GeoReferencingStrings() const { return GeoReferencingStrings; }
/// @return Get vector of row indexes.
vector<int> get_RowSequence() const { return RowSequence; }
/// @return Get vector of column indexes.
vector<int> get_ColSequence() const { return ColSequence; }
/// @return Get vector of node indexes.
vector<int> get_NodeSequence() const { return NodeSequence; }
/// @return This tells how many nodes are in the channel.
int get_n_nodes_in_channel() const {return int(NodeSequence.size()); }
/// @brief gets the row and column of the end node
/// @param FlowInfo the LSDFlowInfo object
/// @param row the row that will be replaced
/// @param col the col that will be replaced with the correct value
/// @author SMM
/// @date 06/05/2015
void get_row_column_of_end_node(LSDFlowInfo& FlowInfo, int& row, int& col);
/// @brief This gets the node index at a given node in the index channel.
/// @param n_node index of target node.
/// @return Node index.
/// @author SMM
/// @date 01/01/12
int get_node_in_channel(int n_node);
/// @brief This removes the final node in a channel
/// @details Used when channel ends in a receiver junction but user wants penultamite node
/// @author SMM
/// @date 05/11/2013
void truncate_final_node();
/// @brief Get the number of contributing pixels at a given node in the channel.
/// @param n_node index of target node.
/// @param FlowInfo LSDFlowInfo object.
/// @return Contributing pixels.
/// @author SMM
/// @date 01/01/12
int get_contributing_pixels_at_node(int n_node, LSDFlowInfo& FlowInfo);
/// @brief This gets the node, row, and column index.
/// @param n_node index of target node.
/// @param node Blank variable for output node.
/// @param row Blank variable for output row index.
/// @param col Blank variable for output column index.
/// @return Node, row, and column index.
/// @author SMM
/// @date 01/01/12
void get_node_row_col_in_channel(int n_node, int& node, int& row, int& col);
/// @brief This gets the contriubting pixels at the outlet of the channel.
/// @param FlowInfo LSDFlowInfo object.
/// @return Contriubting pixels at the outlet of the channel.
/// @author SMM
/// @date 01/01/12
int get_contributing_pixels_at_outlet(LSDFlowInfo& FlowInfo)
{ return FlowInfo.retrieve_contributing_pixels_of_node(EndNode); }
/// @brief Gets the pixels at the penultimate node.
///
/// @details Useful when calculating area of basins where the tributary junction is at the EndNode.
/// @param FlowInfo LSDFlowInfo object.
/// @return Pixels at the penultimate node.
/// @author SMM
/// @date 01/01/12
int get_contributing_pixels_at_penultimate_node(LSDFlowInfo& FlowInfo);
/// @return This prints the channel to an LSDIndexRaster in order to see where the channel is.
/// @author SMM
/// @date 01/01/12
LSDIndexRaster print_index_channel_to_index_raster();
/// @brief This function appends a channel onto an existing LSDIndexRaster
/// @author SMM
/// @date 26/09/2013
void append_index_channel_to_index_raster(LSDIndexRaster& old_raster);
/// @brief Function to get vectors with the X and Y coordinates of nodes in the channel
/// @param X_coordinates vector to write X_coords
/// @param Y_coordinates vector to write Y_coords
/// @author FJC
/// @date 17/02/17
void get_coordinates_of_channel_nodes(vector<double>& X_coordinates, vector<double>& Y_coordinates, LSDFlowInfo& FlowInfo);
/// @brief Function to get vectors with the X and Y coordinates of nodes in the channel
/// @param X_coordinates vector to write X_coords
/// @param Y_coordinates vector to write Y_coords
/// @author FJC
/// @date 17/02/17
void get_coordinates_of_channel_nodes(vector<float>& X_coordinates, vector<float>& Y_coordinates);
/// @brief Function to get write index channel to csv
/// @param path the path name
/// @param filename prefix for the csv file
/// @author FJC
/// @date 17/02/17
void write_channel_to_csv(string path, string filename);
/// @brief Function to get write index channel to csv
/// @detail Similar to above but mimics code in other objects to ensure you get the same channels
/// @param path the path name
/// @param filename prefix for the csv file
/// @param FlowInfo
/// @param FlowDistance
/// @author SMM
/// @date 20/03/18
void write_channel_to_csv(string path, string filename, LSDFlowInfo& FlowInfo, LSDRaster& FlowDistance, LSDRaster& Elevation);
protected:
///Number of rows.
int NRows;
///Number of columns.
int NCols;
///Minimum X coordinate.
float XMinimum;
///Minimum Y coordinate.
float YMinimum;
///Data resolution.
float DataResolution;
///No data value.
int NoDataValue;
///A map of strings for holding georeferencing information
map<string,string> GeoReferencingStrings;
/// The starting junction (numbered within LSDJunctionNetwork object).
int StartJunction;
/// The node index of the starting Junction (numbered in the FlowInfo object).
int StartNode;
/// The ending junction (numbered within LSDJunctionNetwork object).
int EndJunction;
/// The node index of the ending Junction (numbered in the FlowInfo object).
int EndNode;
///Vector of row indices.
vector<int> RowSequence;
///Vector of column indices.
vector<int> ColSequence;
///Vector of node indices.
vector<int> NodeSequence;
private:
void create();
void create(int StartNode, int EndNode, LSDFlowInfo& FlowInfo);
void create(int StartJunction, int StartNode,
int EndJunction, int EndNode, LSDFlowInfo& FlowInfo);
void create(vector<float>& X_coords, vector<float>& Y_coords, LSDFlowInfo& FlowInfo, float threshold_area, float threshold_distance);
};
#endif