示例#1
0
//---------------------------------------------------------
void CFlow_RecursiveUp::Get_Flow(int x, int y)
{
	int		i, ix, iy, j;

	double	jFlow;

	if( !is_Locked(x,y) )
	{
		Lock_Set(x,y);

		Init_Cell(x,y);

		for(i=0, j=4; i<8; i++, j=(j+1)%8)
		{
			ix	= Get_xTo(i,x);
			iy	= Get_yTo(i,y);

			if( is_InGrid(ix,iy) )
			{
				jFlow	= Flow[iy][ix][j];

				if( jFlow > 0 )
				{
					Get_Flow(ix,iy);

					Add_Fraction(ix,iy,j,jFlow);
				}
			}
		}
	}
}
示例#2
0
//---------------------------------------------------------
bool CFlow_RecursiveUp::Calculate(int x, int y)
{
	On_Create();

	Get_Flow(x,y);

	On_Destroy();

	return( true );
}
示例#3
0
//---------------------------------------------------------
bool CErosion_LS_Fields::On_Execute(void)
{
	//-----------------------------------------------------
	m_Method		= Parameters("METHOD"        )->asInt();
	m_Method_Slope	= Parameters("METHOD_SLOPE"  )->asInt();
	m_Method_Area	= Parameters("METHOD_AREA"   )->asInt();

	m_bStopAtEdge	= Parameters("STOP_AT_EDGE"  )->asBool();

	m_Erosivity		= Parameters("EROSIVITY"     )->asDouble();
	m_Stability		= Parameters("STABILITY"     )->asInt();

	m_pDEM			= Parameters("DEM"           )->asGrid();
	m_pUp_Area		= Parameters("UPSLOPE_AREA"  )->asGrid();
	m_pUp_Length	= Parameters("UPSLOPE_LENGTH")->asGrid();
	m_pUp_Slope		= Parameters("UPSLOPE_SLOPE" )->asGrid();
	m_pLS			= Parameters("LS_FACTOR"     )->asGrid();

	DataObject_Set_Colors(m_pUp_Area  , 11, SG_COLORS_WHITE_BLUE    , false);
	DataObject_Set_Colors(m_pUp_Length, 11, SG_COLORS_YELLOW_RED    , false);
	DataObject_Set_Colors(m_pUp_Slope , 11, SG_COLORS_YELLOW_RED    , false);
	DataObject_Set_Colors(m_pLS       , 11, SG_COLORS_RED_GREY_GREEN, true );

	if( m_pUp_Area   == NULL )	m_pUp_Area   = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float);
	if( m_pUp_Length == NULL )	m_pUp_Length = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float);
	if( m_pUp_Slope  == NULL )	m_pUp_Slope  = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float);

	//-----------------------------------------------------
	bool	bResult	= Set_Fields() && Get_Flow() && Get_LS();

	if( bResult )
	{
		Get_Statistics();

		Get_Balance();
	}

	//-----------------------------------------------------
	if( m_pUp_Area   && Parameters("UPSLOPE_AREA"  )->asGrid() == NULL ) delete(m_pUp_Area  );
	if( m_pUp_Length && Parameters("UPSLOPE_LENGTH")->asGrid() == NULL ) delete(m_pUp_Length);
	if( m_pUp_Slope  && Parameters("UPSLOPE_SLOPE" )->asGrid() == NULL ) delete(m_pUp_Slope );

	m_Fields.Destroy();

	return( bResult );
}
示例#4
0
//---------------------------------------------------------
bool CFlow_RecursiveUp::Calculate(void)
{
	CSG_Grid	*pTargets	= Parameters("TARGETS")->asGrid();

	On_Create();

	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			if( !pTargets || !pTargets->is_NoData(x, y) )
			{
				Get_Flow(x, y);
			}
		}
	}

	On_Destroy();

	return( true );
}
示例#5
0
//---------------------------------------------------------
bool CErosion_LS_Fields::Get_Flow(void)
{
	//-----------------------------------------------------
	if( !m_pDEM->Set_Index() )	// create index ...
	{
		return( false );
	}

	Process_Set_Text(_TL("Flow Accumulation"));

	m_pUp_Area  ->Assign(0.0);
	m_pUp_Length->Assign(0.0);
	m_pUp_Slope ->Assign(0.0);

	for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
	{
		int		x, y;
		double	dzSum, dz[8], Slope, Aspect;

		if( m_pDEM->Get_Sorted(n, x, y) && !m_Fields.is_NoData(x, y) && m_pDEM->Get_Gradient(x, y, Slope, Aspect) )
		{
			double	Up_Area		= m_pUp_Area  ->asDouble(x, y) + Get_Cellarea();
			double	Up_Length	= m_pUp_Length->asDouble(x, y) + log(Up_Area);
			double	Up_Slope	= m_pUp_Slope ->asDouble(x, y) + log(Up_Area) * Slope;

			//---------------------------------------------
			if( (dzSum = Get_Flow(x, y, dz)) > 0.0 )
			{
				for(int i=0; i<8; i++)
				{
					if( dz[i] > 0.0 )
					{
						int	ix	= Get_xTo(i, x);
						int	iy	= Get_yTo(i, y);

						m_pUp_Area  ->Add_Value(ix, iy, Up_Area   * dz[i] / dzSum);
						m_pUp_Length->Add_Value(ix, iy, Up_Length * dz[i] / dzSum);
						m_pUp_Slope ->Add_Value(ix, iy, Up_Slope  * dz[i] / dzSum);
					}
				}
			}

			//---------------------------------------------
			switch( m_Method_Area )
			{
			case 0:	// specific catchment area (contour length simply as cell size)
				m_pUp_Area->Set_Value(x, y, Up_Area / (Get_Cellsize()));
				break;

			case 1:	// specific catchment area (contour length dependent on aspect)
				m_pUp_Area->Set_Value(x, y,	Up_Area / (Get_Cellsize() * (fabs(sin(Aspect)) + fabs(cos(Aspect)))));
				break;

			case 2:	// catchment length (square root of catchment area)
				m_pUp_Area->Set_Value(x, y, sqrt(Up_Area));
				break;

			case 3:	// effective flow length
				m_pUp_Area->Set_Value(x, y, Up_Length);
				break;

			case 4:	// total catchment area
				m_pUp_Area->Set_Value(x, y, Up_Area);
				break;
			}

			m_pUp_Length->Set_Value(x, y, Up_Length);
			m_pUp_Slope ->Set_Value(x, y, Up_Slope / (Up_Length > M_ALMOST_ZERO ? Up_Length : M_ALMOST_ZERO));
		}
	}

	//-----------------------------------------------------
	return( true );
}