📄 channelnetwork.cpp
字号:
{
iMin = i;
break;
}
else
{
dz = (z - pDTM->asDouble(ix,iy)) / Get_Length(i);
if( iMin <= 0 || dzMin < dz )
{
iMin = i;
dzMin = dz;
}
}
}
pChannels->Set_Value(x,y, iMin );
}
//---------------------------------------------------------
void CChannelNetwork::Set_Route_Weighted(int x, int y, CSG_Grid *pWeight, double Weight_Threshold)
{
bool bMin;
int i, ix, iy, iMin;
double z, dz, dzMin, w, wMin;
z = pDTM->asDouble(x,y);
iMin = 0;
for(i=1; i<=8; i++)
{
ix = Get_xTo(i,x);
iy = Get_yTo(i,y);
if( !pDTM->is_InGrid(ix, iy) )
{
iMin = i;
break;
}
else
{
dz = (z - pDTM->asDouble(ix,iy)) / Get_Length(i);
if( dz > 0 )
{
bMin = false;
w = pWeight->asDouble(ix,iy);
if( iMin <= 0 )
{
bMin = true;
}
else if( Weight_Threshold > 0 )
{
if( w > Weight_Threshold && wMin > Weight_Threshold )
{
if( dzMin < dz )
{
bMin = true;
}
}
else if( wMin < w )
{
bMin = true;
}
}
else if( wMin < w )
{
bMin = true;
}
if( bMin )
{
iMin = i;
wMin = w;
dzMin = dz;
}
}
}
}
pChannels->Set_Value(x,y, iMin );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CChannelNetwork::Set_Channel_Route(int x, int y)
{
const int BUFFER_GROWSIZE = 256;
int xStart, yStart, i, ix, iy, goDir, m, n, nDiv;
double z, dz, dzMin, Length;
//-----------------------------------------------------
if( pStart->asChar(x,y) && !pChannelRoute->asChar(x,y) )
{
Lock_Create();
n = 0;
nDiv = 0;
Length = 0;
xStart = x;
yStart = y;
do
{
//---------------------------------------------
// 1. Divergence ?!...
if( pConvergence )
{
if( pConvergence->asDouble(x,y) > -1.0 )
{
nDiv++;
}
else
{
nDiv = 0;
}
}
if( pConvergence && nDiv > maxDivCells )
{
goDir = -1;
}
else
{
//-----------------------------------------
// 2. Is there any channel around ?!...
goDir = 0;
z = pDTM->asDouble(x,y);
for(i=1; i<=8; i++)
{
ix = Get_xTo(i,x);
iy = Get_yTo(i,y);
if( pDTM->is_InGrid(ix,iy) && !is_Locked(ix,iy) && pChannelRoute->asChar(ix,iy) )
{
dz = (z - pDTM->asDouble(ix,iy)) / Get_Length(i);
if( goDir <= 0 || dzMin < dz )
{
goDir = i;
dzMin = dz;
}
}
}
if( goDir <= 0 ) // ...if not then go as usual...
{
goDir = pChannels->asInt(x,y);
}
//-----------------------------------------
// 3. Go to Drainage Direction !...
if( goDir > 0 )
{
Lock_Set(x,y);
x = Get_xTo(goDir,x);
y = Get_yTo(goDir,y);
Length += Get_UnitLength(goDir);
if( n >= Direction_Buffer )
{
Direction_Buffer += BUFFER_GROWSIZE;
Direction = (int *)SG_Realloc(Direction, Direction_Buffer * sizeof(int));
}
Direction[n++] = goDir;
}
}
}
while( goDir > 0 && pDTM->is_InGrid(x,y) && !is_Locked(x,y) && !pChannelRoute->asChar(x,y) );
//-------------------------------------------------
if( Length >= minLength )
{
x = xStart;
y = yStart;
if( goDir < 0 )
{
n -= nDiv;
}
for(m=0; m<n; m++)
{
goDir = Direction[m];
pChannelRoute->Set_Value(x,y,goDir);
for(i=0; i<8; i++) // Don't start new channels beside existing ones...
{
ix = Get_xTo(i,x);
iy = Get_yTo(i,y);
if( pDTM->is_InGrid(ix,iy) )
{
pStart->Set_Value(ix,iy,0);
}
}
x = Get_xTo(goDir,x);
y = Get_yTo(goDir,y);
}
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CChannelNetwork::Set_Channel_Order(int x, int y)
{
int i, ix, iy, j, n;
//-----------------------------------------------------
if( pChannelRoute->asChar(x,y) > 0 )
{
for(i=n=0, j=4; i<8; i++, j=(j+1)%8)
{
ix = Get_xTo(i,x);
iy = Get_yTo(i,y);
if( pDTM->is_InGrid(ix,iy) && pChannelRoute->asChar(ix,iy) && j == pChannelRoute->asChar(ix,iy) % 8 )
{
n++;
}
}
//-----------------------------------------------------
if( n == 0 )
{
Lock_Create();
do
{
Lock_Set(x,y);
pChannels->Add_Value(x,y, 1 );
i = pChannelRoute->asChar(x,y);
if( i > 0 )
{
x = Get_xTo(i,x);
y = Get_yTo(i,y);
}
}
while( pDTM->is_InGrid(x,y) && i > 0 && !is_Locked(x,y) );
}
}
}
//---------------------------------------------------------
void CChannelNetwork::Set_Channel_Mouth(int x, int y)
{
int Order, goDir, ix, iy;
Order = pChannels->asInt(x,y);
if( Order > 0 )
{
goDir = pChannelRoute->asChar(x,y);
if( goDir > 0 )
{
ix = Get_xTo(goDir,x);
iy = Get_yTo(goDir,y);
if( !pDTM->is_InGrid(ix,iy) || (pChannels->asInt(ix,iy) > 0 && Order != pChannels->asInt(ix,iy)) )
{
pChannels->Set_Value(x,y, -1 );
}
}
else
{
pChannels->Set_Value(x,y, -1 );
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CChannelNetwork::Set_Vector(int x, int y, int ID)
{
bool bContinue;
int i, ix, iy, j, Order;
double xMin, yMin, Length;
CSG_Shape *pShape;
//-----------------------------------------------------
if( (Order = pChannels->asInt(x,y)) > 0 )
{
bContinue = true;
for(i=0, j=4; i<8 && bContinue; i++, j=(j+1)%8)
{
ix = Get_xTo(i,x);
iy = Get_yTo(i,y);
if( pDTM->is_InGrid(ix,iy)
&& pChannels->asInt(ix,iy) == Order
&& pChannelRoute->asChar(ix,iy) && j == pChannelRoute->asChar(ix,iy) % 8 )
{
bContinue = false;
}
}
//-------------------------------------------------
if( bContinue ) // Startpunkt gefunden...
{
xMin = pDTM->Get_XMin(),
yMin = pDTM->Get_YMin();
ID = 1;
pShape = pShapes->Add_Shape();
do
{
bContinue = false;
Length = 0;
Lock_Set(x,y);
pShape->Add_Point(xMin + x * Get_Cellsize(), yMin + y * Get_Cellsize());
i = pChannelRoute->asChar(x,y);
if( i > 0 )
{
ix = Get_xTo(i,x);
iy = Get_yTo(i,y);
Length += Get_Length(i);
if( pDTM->is_InGrid(ix,iy) )
{
if( !is_Locked(ix,iy)
&& ( pChannels->asInt(ix,iy) == Order
|| pChannels->asInt(ix,iy) < 0) )
{
x = ix;
y = iy;
bContinue = true;
}
else
{
pShape->Add_Point(xMin + ix * Get_Cellsize(), yMin + iy * Get_Cellsize());
}
}
}
}
while( bContinue );
pShape->Get_Record()->Set_Value(0, ID );
pShape->Get_Record()->Set_Value(1, Order );
pShape->Get_Record()->Set_Value(2, Length );
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -