1 
2 ///////////////////////////////////////////////////////////
3 //                                                       //
4 //                         SAGA                          //
5 //                                                       //
6 //      System for Automated Geoscientific Analyses      //
7 //                                                       //
8 //                     Tool Library                      //
9 //                       RivFlow                         //
10 //                                                       //
11 //-------------------------------------------------------//
12 //                                                       //
13 //                    RivGridPrep.cpp                    //
14 //                                                       //
15 //                 Copyright (C) 2014 by                 //
16 //                   Christian Alwardt                   //
17 //                                                       //
18 //-------------------------------------------------------//
19 //                                                       //
20 // This file is part of 'SAGA - System for Automated     //
21 // Geoscientific Analyses'. SAGA is free software; you   //
22 // can redistribute it and/or modify it under the terms  //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the     //
25 // License, or (at your option) any later version.       //
26 //                                                       //
27 // SAGA is distributed in the hope that it will be       //
28 // useful, but WITHOUT ANY WARRANTY; without even the    //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A  //
30 // PARTICULAR PURPOSE. See the GNU General Public        //
31 // License for more details.                             //
32 //                                                       //
33 // You should have received a copy of the GNU General    //
34 // Public License along with this program; if not,       //
35 // write to the Free Software Foundation, Inc.,          //
36 // 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
37 // USA.                                                  //
38 //                                                       //
39 //-------------------------------------------------------//
40 //                                                       //
41 //    e-mail:     alwardt@ifsh.de                        //
42 //                                                       //
43 //    contact:    Christian Alwardt                      //
44 //                Institute for Peace Research           //
45 //                and Security Policy (IFSH)             //
46 //                University of Hamburg                  //
47 //                Germany                                //
48 //                                                       //
49 ///////////////////////////////////////////////////////////
50 
51 
52 ///////////////////////////////////////////////////////////
53 //														 //
54 //		RivTool 0.1										 //
55 //														 //
56 ///////////////////////////////////////////////////////////
57 
58 
59 #include "RivGridPrep.h"
60 
61 
62 //---------------------------------------------------------
63 //#########################################################
64 
CRivGridPrep(void)65 CRivGridPrep::CRivGridPrep(void)
66 {
67 	//-----------------------------------------------------
68 	// Modul information
69 
70 	Set_Name		("RiverGridGeneration");
71 	Set_Author		("Christian Alwardt");
72 	Set_Description	("Generation of RiverCourse-GridCells");
73 
74 	//-----------------------------------------------------
75 	// Define your parameters list...
76 
77 	Parameters.Add_Grid(
78 		NULL, "INPUT"	, "Gel�ndemodell (DTM)",
79 		"Digitales Gel�ndemodell des Flusseinzugsgebietes",
80 		PARAMETER_INPUT
81 	);
82 
83 	Parameters.Add_Grid(
84 		NULL, "OUTPUT"	, "HG Raster",
85 		"Schrittweise Ausgabe der gew�nschten Abflusspfade des Hauprgerinnerasters",
86 		PARAMETER_OUTPUT
87 	); // Flussgrids [!=0] , keine Flussgrid [0]
88 
89 
90 	Parameters.Add_Value(
91 		NULL, "SX"	, "Abflusspfad-Quelle, x-Wert",
92 		"X-Wert der Quellen-Rasterzelle",
93 		PARAMETER_TYPE_Int, 0, 0, true
94 	);
95 
96 	Parameters.Add_Value(
97 		NULL, "SY"	, "Abflusspfad-Quelle, y-Wert",
98 		"Y-Wert der Quellen-Rastertzelle",
99 		PARAMETER_TYPE_Int, 0, 0, true
100 	);
101 
102 	Parameters.Add_Value(
103 		NULL, "MX"	, "Abflusspfad-M�ndung, x-Wert",
104 		"X-Wert des M�ndungs-Rasterzelle",
105 		PARAMETER_TYPE_Int, 0, 0, true
106 	);
107 
108 	Parameters.Add_Value(
109 		NULL, "MY"	, "Abflusspfad-M�ndung, y-Wert",
110 		"Y-Wert des M�ndungsRasterzelle",
111 		PARAMETER_TYPE_Int, 0, 0, true
112 	);
113 
114 	Parameters.Add_Value(
115 		NULL, "Owrite", "Overwrite RiverGridCells",
116 		"Bereits existierende RiverGridCells werden �berschrieben (Wenn nicht gesetzt: Abflusspfadende, wenn eine existierende RiverGridCell erreicht wird -> zB bei Fluss mit zwei Quellen sinnvoll).",
117 		PARAMETER_TYPE_Bool, false
118 	);
119 }
120 
121 
122 ///////////////////////////////////////////////////////////
123 //														 //
124 //	Hauptfunktion										 //
125 //														 //
126 ///////////////////////////////////////////////////////////
127 
128 
On_Execute(void)129 bool CRivGridPrep::On_Execute(void)
130 {
131 	//-----------------------------------------------------
132 	// Get the parameter settings...
133 
134 	m_pDTM = Parameters("INPUT")->asGrid();
135 	m_pRivGridCells = Parameters("OUTPUT")->asGrid();
136 	m_pSX = Parameters("SX")->asInt();
137 	m_pSY = Parameters("SY")->asInt();
138 	m_pMX = Parameters("MX")->asInt();
139 	m_pMY = Parameters("MY")->asInt();
140 
141 	//-----------------------------------------------------
142 	// Do something...
143 
144 
145 	if(!Set_RivGridCells(m_pSX, m_pSY, m_pMX, m_pMY))
146 		Message_Dlg("Achtung, Fehler beim Erzeugen des Flussgrids");
147 
148 	//-----------------------------------------------------
149 	// Return 'true' if everything is okay...
150 
151 	return( true );
152 }
153 
154 
155 
156 //#########################################################
157 //---------------------------------------------------------
158 //#########################################################
159 ///////////////////////////////////////////////////////////
160 //														 //
161 //	Funktionen											 //
162 //														 //
163 ///////////////////////////////////////////////////////////
164 
165 
166 //######################################################
167 //
Set_RivGridCells(int sx,int sy,int mx,int my)168 bool CRivGridPrep::Set_RivGridCells(int sx, int sy, int mx, int my )
169 {
170 	//Identifizierung der Flussgrids und setzen des Flusskilometerwertes - immer von Gitterboxmittelpunkt zu Mittelpunkt
171 
172 
173 //	if( Parameters("Owrite")->asBool() )
174 //		m_pRivGrids->Assign(0.0);
175 
176 	int x = sx;
177 	int y = sy;
178 	int i = -1;
179 	double dist = m_pDTM->Get_Cellsize() / 2;	// Wert Flusskilomter der ersten Flussgitterboxmitte
180 	m_pRivGridCells->Set_Value(x, y, dist); // setzen der Kilometer bis zur Mitte der ersten Flussgitterbox
181 
182 	while( !m_pDTM->is_NoData(x,y))
183 	{
184 		i = m_pDTM->Get_Gradient_NeighborDir(x, y);
185 
186 		if(i >= 0)
187 		{
188 			dist = dist + Get_Length(i);				//bisheriger FlusskilometerWert + Weg zur n�chsten Gitterboxmitte (abh�ngig ob Wasser diagonal oder rechtwinklig in n�chste Gitterbox flie�t) am Ende der Gridbox wird in FlussGitterbox geschrieben (!=0)
189 
190 			x = Get_xTo(i, x);
191 			y = Get_yTo(i, y);
192 
193 			if(!Parameters("Owrite")->asBool() && m_pRivGridCells->asDouble(x,y) != 0) //falls "�berschreiben" nicht gesetzt, bricht Funktion ab sobald ein Grid != 0 erreicht wird.
194 				return(true);
195 
196 			if(x == mx && y == my)
197 			{
198 				m_pRivGridCells->Set_Value(x, y, dist); // setzen der Kilometer bis zur Mitte der letzten Flussgitterbox
199 
200 				DataObject_Update(m_pRivGridCells);
201 				return (true);
202 			}
203 			else
204 				m_pRivGridCells->Set_Value(x, y, dist);	//FlusskilometerWert der n�chsten Gridbox(mitte) wird in n�chste FlussGitterbox i (ix,iy) geschrieben (!=0)
205 
206 			DataObject_Update(m_pRivGridCells);
207 
208 
209 		}
210 		else
211 			return(false);
212 	}
213 
214 	return (false);
215 }
216 ///////////////////////////////////////////////////////////
217 //														 //
218 //														 //
219 //														 //
220 ///////////////////////////////////////////////////////////
221 
222 //---------------------------------------------------------
223