コード例 #1
0
ファイル: Flow_AreaUpslope.cpp プロジェクト: am2222/SAGA-GIS
//---------------------------------------------------------
void CFlow_AreaUpslope::Set_Value(int x, int y)
{
	int		i;

	if( m_pRoute && (i = m_pRoute->asChar(x, y)) >= 0 )
	{
		int		ix, iy;
		double	Flow;

		ix	= m_pDTM->Get_System().Get_xTo(i, x);
		iy	= m_pDTM->Get_System().Get_yTo(i, y);

		if( m_pDTM->is_InGrid(ix, iy, true) && (Flow = m_pFlow->asDouble(ix, iy)) > 0.0 )
		{
			m_pFlow->Set_Value(x, y, Flow);
		}
	}
	else if( !m_pDTM->is_NoData(x, y) )
	{
		switch( m_Method )
		{
		case 0:	Set_D8		(x, y);	break;
		case 1:	Set_DInf	(x, y);	break;
		case 2:	Set_MFD		(x, y);	break;
		}
	}
}
コード例 #2
0
ファイル: CellBalance.cpp プロジェクト: am2222/SAGA-GIS
//---------------------------------------------------------
bool CCellBalance::On_Execute(void)
{
	int		x, y, Method;
	double	Weight;
	CSG_Grid	*pWeights;

	m_pDEM		= Parameters("DEM")		->asGrid(); 
	pWeights	= Parameters("WEIGHTS")	->asGrid(); 
	m_pBalance	= Parameters("BALANCE")	->asGrid();
	Weight		= Parameters("WEIGHT")	->asDouble();
	Method		= Parameters("METHOD")	->asInt();

	m_pBalance->Assign(0.0);

	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( m_pDEM->is_NoData(x, y) )
			{
				m_pBalance->Set_NoData	(x, y);
			}
			else
			{
				if( pWeights )
				{
					Weight	= pWeights->is_NoData(x, y) ? 0.0 : pWeights->asDouble(x, y);
				}

				m_pBalance->Add_Value	(x, y, -Weight);

				switch( Method )
				{
				case 0:	Set_D8	(x, y, Weight);	break;
				case 1:	Set_MFD	(x, y, Weight);	break;
				}
			}
        }
    }

	return( true );
}
コード例 #3
0
//---------------------------------------------------------
void CFlow_RecursiveUp::On_Create(void)
{
	int		x, y, Method;

	double	*p;

	//-----------------------------------------------------
	On_Destroy();

	Flow	= (double ***)SG_Malloc(    Get_NY    () * sizeof(double **));
	p		= (double   *)SG_Malloc(8 * Get_NCells() * sizeof(double   ));

	for(y=0; y<Get_NY(); y++)
	{
		Flow[y]	= (double **)SG_Malloc( Get_NX    () * sizeof(double  *));

		for(x=0; x<Get_NX(); x++, p+=8)
		{
			Flow[y][x]	= p;
		}
	}

	//-----------------------------------------------------
	Lock_Create();

	Method	= Parameters("Method")->asInt();

	memset(Flow[0][0], 0, 8 * Get_NCells() * sizeof(double) );

	for(y=0; y<Get_NY(); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( pRoute && pRoute->asChar(x,y) > 0 )
			{
				Flow[y][x][pRoute->asChar(x,y) % 8]	= 1.0;
			}
			else
			{
				switch( Method )
				{
					case 0:
						Set_D8(x,y);
						break;

					case 1:
						Set_Rho8(x,y);
						break;

					case 2:
						Set_DInf(x,y);
						break;

					case 3:
						Set_MFD(x,y);
						break;
				}
			}
		}
	}
}
コード例 #4
0
//---------------------------------------------------------
bool CChannelNetwork_Distance::On_Execute(void)
{
	//-----------------------------------------------------
	m_pDEM		= Parameters("ELEVATION")->asGrid();
	m_pChannels	= Parameters("CHANNELS" )->asGrid();
	m_pRoute	= Parameters("ROUTE"    )->asGrid();

	m_pDistance	= Parameters("DISTANCE" )->asGrid();
	m_pDistVert	= Parameters("DISTVERT" )->asGrid();
	m_pDistHorz	= Parameters("DISTHORZ" )->asGrid();

	m_pTime		= Parameters("TIME"     )->asGrid();
	m_pSDR		= Parameters("SDR"      )->asGrid();

	m_Flow_B	= Parameters("FLOW_B"   )->asDouble();
	m_Flow_K	= Parameters("FLOW_K"   )->asDouble();
	m_Flow_R	= Parameters("FLOW_R"   )->asDouble();
	m_pFlow_K	= Parameters("FLOW_K"   )->asGrid();
	m_pFlow_R	= Parameters("FLOW_R"   )->asGrid();

	m_pFields	= Parameters("FIELDS"   )->asGrid();
	m_pPasses	= Parameters("PASSES"   )->asGrid();

	//-----------------------------------------------------
	m_pDistance->Assign_NoData();
	m_pDistVert->Assign_NoData();
	m_pDistHorz->Assign_NoData();

	if( m_pTime )
	{
		m_pTime->Assign_NoData();
		m_pTime->Set_Unit("hours");
	}

	if( m_pSDR  )
	{
		m_pSDR ->Assign_NoData();
	}

	if( m_pFields && m_pPasses )
	{
		m_pPasses->Set_NoData_Value(-1.0);
		m_pPasses->Assign_NoData();
	}

	if( !m_pDEM->Set_Index() )
	{
		Error_Set(_TL("index creation failed"));

		return( false );
	}

	//-----------------------------------------------------
	int  Method		= Parameters("METHOD")->asInt();
	bool bBoundary	= Parameters("BOUNDARY")->asBool();

	for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
	{
		int		x, y;

		if( m_pDEM->Get_Sorted(n, x, y, false) )	// ascending, only valid dem cells
		{
			if( is_Channel(x, y, bBoundary) )
			{
				m_pDistance->Set_Value(x, y, 0.0);
				m_pDistVert->Set_Value(x, y, 0.0);
				m_pDistHorz->Set_Value(x, y, 0.0);

				if( m_pTime   ) m_pTime  ->Set_Value(x, y, 0.0);
				if( m_pFields ) m_pPasses->Set_Value(x, y, 0.0);
			}
			else // if( m_pDEM->is_InGrid(x, y) )
			{
				switch( Method )
				{
				default: Set_D8 (x, y); break;
				case  1: Set_MFD(x, y); break;
				}

				if( m_pSDR && !m_pTime->is_NoData(x, y) )
				{
					m_pSDR->Set_Value(x, y, exp(-m_Flow_B * m_pTime->asDouble(x, y)));
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #5
0
//---------------------------------------------------------
bool CFlow_Parallel::Set_Flow(void)
{
	//-----------------------------------------------------
	if( !m_pDTM->Set_Index() )
	{
		return( false );
	}

	//-----------------------------------------------------
	int Method	= Parameters("METHOD")->asInt();

	if( Method == 2 )
	{
		BRM_Init();
	}

	//-----------------------------------------------------
	double	dLinear	= Parameters("LINEAR_DO")->asBool() ? Parameters("LINEAR_MIN")->asDouble() : -1.0;

	CSG_Grid	*pLinear_Val	= Parameters("LINEAR_VAL")->asGrid();
	CSG_Grid	*pLinear_Dir	= Parameters("LINEAR_DIR")->asGrid();

	//-----------------------------------------------------
	bool	bNoNegatives	= m_pWeights ? Parameters("NO_NEGATIVES")->asBool() : false;

	CSG_Grid	*pLoss	= Parameters("WEIGHT_LOSS")->asGrid();

	if( bNoNegatives && pLoss )
	{
		pLoss->Assign_NoData();
	}

	//-----------------------------------------------------
	for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
	{
		int		x, y;

		if( m_pDTM->Get_Sorted(n, x, y) )
		{
			if( bNoNegatives && m_pFlow->asDouble(x, y) < 0.0 )
			{
				if( pLoss )
				{
					pLoss->Set_Value(x, y, fabs(m_pFlow->asDouble(x, y)));
				}

				m_pFlow->Set_Value(x, y, 0.0);
			}

			if( pLinear_Dir && !pLinear_Dir->is_NoData(x, y) )
			{
				Set_D8(x, y, pLinear_Dir->asInt(x, y));
			}
			else if( dLinear > 0.0 && dLinear <= (pLinear_Val && !pLinear_Val->is_NoData(x, y) ? pLinear_Val->asDouble(x, y) : m_pFlow->asDouble(x, y)) )
			{
				Set_D8(x, y, pLinear_Dir && !pLinear_Dir->is_NoData(x, y) ? pLinear_Dir->asInt(x, y) : -1);
			}
			else switch( Method )
			{
			case 0:	Set_D8    (x, y);	break;
			case 1:	Set_Rho8  (x, y);	break;
			case 2:	Set_BRM   (x, y);	break;
			case 3:	Set_DInf  (x, y);	break;
			case 4:	Set_MFD   (x, y);	break;
			case 5:	Set_MDInf (x, y);	break;
			case 6:	Set_MMDGFD(x, y);	break;
			}
		}
	}

	//-----------------------------------------------------
	if( m_pRoute )
	{
		for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
		{
			int		x, y;

			if( m_pDTM->Get_Sorted(n, x, y, false) )
			{
				Check_Route(x, y);
			}
		}
	}

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