📄 flow_parallel.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Module Library: //
// ta_hydrology //
// //
//-------------------------------------------------------//
// //
// Flow_Parallel.cpp //
// //
// Copyright (C) 2003 by //
// Olaf Conrad //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. SAGA 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; version 2 of the License. //
// //
// SAGA 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 the Free Software Foundation, Inc., //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
// USA. //
// //
//-------------------------------------------------------//
// //
// e-mail: oconrad@saga-gis.org //
// //
// contact: Olaf Conrad //
// Institute of Geography //
// University of Goettingen //
// Goldschmidtstr. 5 //
// 37077 Goettingen //
// Germany //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#include "Flow_Parallel.h"
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CFlow_Parallel::CFlow_Parallel(void)
{
Set_Name(_TL("Parallel Processing"));
Set_Author(_TL("Copyrights (c) 2001 by Olaf Conrad"));
Set_Description (_TW(
"Parallel processing of cells for calculation of flow accumulation and related parameters. "
"This set of algorithms processes a DEM downwards from the highest to the lowest cell.\n\n"
"References:\n\n"
"Deterministic 8\n"
"- O'Callaghan, J.F. / Mark, D.M. (1984):\n"
" 'The extraction of drainage networks from digital elevation data',\n"
" Computer Vision, Graphics and Image Processing, 28:323-344\n\n"
"Rho 8:\n"
"- Fairfield, J. / Leymarie, P. (1991):\n"
" 'Drainage networks from grid digital elevation models',\n"
" Water Resources Research, 27:709-717\n\n"
"Braunschweiger Reliefmodell:\n"
"- Bauer, J. / Rohdenburg, H. / Bork, H.-R. (1985):\n"
" 'Ein Digitales Reliefmodell als Vorraussetzung fuer ein deterministisches Modell der Wasser- und Stoff-Fluesse',\n"
" Landschaftsgenese und Landschaftsoekologie, H.10, Parameteraufbereitung fuer deterministische Gebiets-Wassermodelle,\n"
" Grundlagenarbeiten zu Analyse von Agrar-Oekosystemen, (Eds.: Bork, H.-R. / Rohdenburg, H.), p.1-15\n\n"
"Deterministic Infinity:\n"
"- Tarboton, D.G. (1997):\n"
" 'A new method for the determination of flow directions and upslope areas in grid digital elevation models',\n"
" Water Ressources Research, Vol.33, No.2, p.309-319\n\n"
"Multiple Flow Direction:\n"
"- Freeman, G.T. (1991):\n"
" 'Calculating catchment area with divergent flow based on a regular grid',\n"
" Computers and Geosciences, 17:413-22\n\n"
"- Quinn, P.F. / Beven, K.J. / Chevallier, P. / Planchon, O. (1991):\n"
" 'The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models',\n"
" Hydrological Processes, 5:59-79\n\n")
);
//-----------------------------------------------------
// Output...
Parameters.Add_Grid(
NULL , "CASPECT" , _TL("Catchment Aspect"),
_TL(""),
PARAMETER_OUTPUT_OPTIONAL
);
Parameters.Add_Grid(
NULL , "FLWPATH" , _TL("Flow Path Length"),
_TL(""),
PARAMETER_OUTPUT_OPTIONAL
);
//-----------------------------------------------------
// Method...
Parameters.Add_Choice(
NULL , "Method" , _TL("Method"),
_TL(""),
CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
_TL("Deterministic 8"),
_TL("Rho 8"),
_TL("Braunschweiger Reliefmodell"),
_TL("Deterministic Infinity"),
_TL("Multiple Flow Direction")
), 4
);
//-----------------------------------------------------
// Options...
Parameters.Add_Value(
NULL , "DOLINEAR" , _TL("Linear Flow"),
_TL("Use D8 if catchment area becomes higher than specified threshold."),
PARAMETER_TYPE_Bool
);
Parameters.Add_Value(
NULL , "LINEARTHRS" , _TL("Linear Flow Threshold"),
_TL("Use D8 if catchment area becomes higher than specified threshold (Cells)."),
PARAMETER_TYPE_Double , 500
);
Parameters.Add_Value(
NULL , "CONVERGENCE" , _TL("Convergence"),
_TL("Convergence factor for Multiple Flow Direction Algorithm (Freeman 1991)"),
PARAMETER_TYPE_Double , 1.1, 0.0, true
);
}
//---------------------------------------------------------
CFlow_Parallel::~CFlow_Parallel(void)
{}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CFlow_Parallel::On_Initialize(void)
{
pCatch_Aspect = Parameters("CASPECT")->asGrid();
pFlowPath = Parameters("FLWPATH")->asGrid();
TH_LinearFlow = Parameters("DOLINEAR")->asBool() && pDTM
? Parameters("LINEARTHRS")->asDouble() // (pDTM->Get_NX() * pDTM->Get_NY())
: -1.0;
MFD_Converge = Parameters("CONVERGENCE")->asDouble();
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CFlow_Parallel::Calculate(void)
{
int x, y;
for(y=0; y<Get_NY() && Set_Progress(y); y+=Step)
{
for(x=0; x<Get_NX(); x+=Step)
{
Init_Cell(x, y);
}
}
Set_Flow();
}
//---------------------------------------------------------
void CFlow_Parallel::Calculate(int x, int y)
{
Init_Cell(x, y);
Set_Flow();
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CFlow_Parallel::Set_Flow(void)
{
int Method, x, y;
long n;
//-----------------------------------------------------
Method = Parameters("Method")->asInt();
if( Method == 2 )
{
BRM_Init();
}
//-----------------------------------------------------
for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
{
pDTM->Get_Sorted(n,x,y);
//if( !(n%(4*Get_NX())) )DataObject_Update(pFlow);
if( TH_LinearFlow > 0.0 && pCatch->asDouble(x, y) >= TH_LinearFlow )
{
Set_D8(x, y);
}
else
{
switch( Method )
{
case 0:
Set_D8(x, y);
break;
case 1:
Set_Rho8(x, y);
break;
case 3:
Set_DInf(x, y);
break;
case 4:
Set_MFD(x, y);
break;
case 2:
Set_BRM(x, y);
break;
}
}
}
//-----------------------------------------------------
if( pRoute )
{
for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
{
pDTM->Get_Sorted(n, x, y, false);
Check_Route(x, y);
}
}
}
//---------------------------------------------------------
void CFlow_Parallel::Check_Route(int x, int y)
{
bool bSink;
int i, ix, iy;
double z;
if( pRoute->asChar(x, y) > 0 )
{
z = pDTM->asDouble(x, y);
for(i=0, bSink=true; i<8 && bSink; i++)
{
ix = Get_xTo(i, x);
iy = Get_yTo(i, y);
if( !is_InGrid(ix, iy) || z > pDTM->asDouble(ix, iy) )
{
bSink = false;
}
}
//-------------------------------------------------
if( bSink )
{
i = pRoute->asChar(x, y);
ix = Get_xTo(i, ix);
iy = Get_yTo(i, iy);
//---------------------------------------------
while( is_InGrid(ix, iy) )
{
Add_Portion(x, y, ix, iy);
i = pRoute->asChar(ix, iy);
if( i > 0 )
{
ix = Get_xTo(i, ix);
iy = Get_yTo(i, iy);
}
else
{
i = pDTM->Get_Gradient_NeighborDir(ix, iy);
if( i >= 0 )
{
ix = Get_xTo(i, ix);
iy = Get_yTo(i, iy);
}
else
{
ix = -1;
}
}
}
}
}
}
///////////////////////////////////////////////////////////
// //
// Deterministic 8 //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CFlow_Parallel::Set_D8( int x, int y )
{
int Direction;
Direction = pDTM->Get_Gradient_NeighborDir(x, y);
if( Direction >= 0 )
{
Add_Fraction(x, y, Direction);
}
}
///////////////////////////////////////////////////////////
// //
// Rho 8 //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CFlow_Parallel::Set_Rho8( int x, int y )
{
int i, ix, iy, iMax;
double z, d, dMax;
z = pDTM->asDouble(x, y);
iMax = -1;
for(i=0; i<8; i++)
{
ix = Get_xTo(i, x);
iy = Get_yTo(i, y);
if( !pDTM->is_InGrid(ix, iy) )
{
return;
}
else
{
d = z - pDTM->asDouble(ix, iy);
if( i % 2 == 1 )
{
d /= 1.0 + rand() / (double)RAND_MAX;
}
if( iMax < 0 || (iMax >= 0 && d > dMax) )
{
iMax = i;
dMax = d;
}
}
}
if( iMax >= 0 )
{
Add_Fraction(x, y, iMax);
}
}
/*void CFlow_Parallel::Set_Rho8( int x, int y )
{
int Direction, ix, iy;
double Slope, Aspect;
Get_Gradient(x, y, Slope, Aspect);
if( Aspect >= 0 )
{
Direction = (int)(Aspect / M_PI_045);
if( fmod(Aspect, M_PI_045) / M_PI_045 > rand() / (double)RAND_MAX )
{
Direction++;
}
Direction %= 8;
ix = Get_xTo(Direction, x);
iy = Get_yTo(Direction, y);
if( is_InGrid(ix, iy) && pDTM->asDouble(ix, iy) >= pDTM->asDouble(x, y) )
{
Direction = Get_Direction_Lowest(pDTM, x, y);
}
Add_Fraction(x, y, Direction);
}
}/**/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -