Exemplo n.º 1
0
//---------------------------------------------------------
bool CD8_Flow_Analysis::On_Execute(void)
{
	CSG_Grid	Dir, Order, Basins;

	m_pDEM		= Parameters("DEM")			->asGrid();

	m_pDir		= Parameters("DIRECTION")	->asGrid();		if( !m_pDir    ) { m_pDir    = &Dir   ; Dir   .Create(*Get_System(), SG_DATATYPE_Char ); Dir   .Set_Name(_TL("Flow Direction" )); }
	m_pOrder	= Parameters("ORDER")		->asGrid();		if( !m_pOrder  ) { m_pOrder  = &Order ; Order .Create(*Get_System(), SG_DATATYPE_Short); Order .Set_Name(_TL("Strahler Order" )); }
	m_pBasins	= Parameters("BASIN")		->asGrid();		if( !m_pBasins ) { m_pBasins = &Basins; Basins.Create(*Get_System(), SG_DATATYPE_Short); Basins.Set_Name(_TL("Drainage Basins")); }

	m_Threshold	= Parameters("THRESHOLD")	->asInt();

	//-----------------------------------------------------
	Get_Direction();

	Get_Order();

	Get_Nodes();

	Get_Basins();

	Get_Segments();

	//-----------------------------------------------------
	m_pOrder->Add(1 - m_Threshold);

	m_Nodes.Destroy();

	return( true );
}
Exemplo n.º 2
0
//---------------------------------------------------------
bool CWatershed_Segmentation::On_Execute(void)
{
    //-----------------------------------------------------
    m_pGrid		= Parameters("GRID")		->asGrid();
    m_pSeeds	= Parameters("SEEDS")		->asShapes();
    m_pSegments	= Parameters("SEGMENTS")	->asGrid();
    m_bDown		= Parameters("DOWN")		->asInt() == 1;

    //-----------------------------------------------------
    m_pSeeds->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), m_pGrid->Get_Name(), _TL("Seeds")));

    m_pSeeds->Add_Field(SG_T("XCELL")	, SG_DATATYPE_Int);		// SEED_X
    m_pSeeds->Add_Field(SG_T("YCELL")	, SG_DATATYPE_Int);		// SEED_Y
    m_pSeeds->Add_Field(SG_T("VALUE")	, SG_DATATYPE_Double);	// SEED_Z
    m_pSeeds->Add_Field(SG_T("ID")		, SG_DATATYPE_Int);		// SEED_ID
    m_pSeeds->Add_Field(SG_T("ID_JOIN")	, SG_DATATYPE_Int);		// SEED_JOIN

    //-----------------------------------------------------
    m_pSegments->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pGrid->Get_Name(), _TL("Segments")));
    m_pSegments->Set_NoData_Value(-999999.0);

    m_Dir.Create(*Get_System(), SG_DATATYPE_Char);

    //-----------------------------------------------------
    if( !Get_Seeds() )
    {
        Message_Add(_TL("no seed points identified"));

        return( false );
    }

    //-----------------------------------------------------
    Get_Segments();

    //-----------------------------------------------------
    if( Parameters("OUTPUT")->asInt() == 0 )
    {
        for(int y=0; y<Get_NY() && Set_Progress(y); y++)
        {
            for(int x=0; x<Get_NX(); x++)
            {
                int	ID	= m_pSegments->asInt(x, y);

                if( ID >= 0 )
                {
                    m_pSegments->Set_Value(x, y, m_pSeeds->Get_Shape(ID)->asDouble(SEED_Z));
                }
            }
        }
    }

    //-----------------------------------------------------
    if( Parameters("BBORDERS")->asBool() )
    {
        Get_Borders();
    }

    //-----------------------------------------------------
    m_Dir.Destroy();

    return( true );
}