//--------------------------------------------------------- void CD8_Flow_Analysis::Get_Direction(void) { Process_Set_Text(_TL("Flow Direction")); m_pDir->Set_NoData_Value(-1); CSG_Grid *pCon = Parameters("CONNECTION") ->asGrid(); if( pCon ) { pCon->Assign(0.0); } for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0, i, ix, iy; x<Get_NX(); x++) { if( (i = m_pDEM->Get_Gradient_NeighborDir(x, y)) >= 0 && m_pDEM->is_InGrid(ix = Get_xTo(i, x), iy = Get_yTo(i, y)) ) { m_pDir->Set_Value(x, y, i); if( pCon ) { pCon->Add_Value(ix, iy, 1); } } else { m_pDir->Set_NoData(x, y); } } } }
//--------------------------------------------------------- bool CGridding_Spline_MBA::BA_Get_Phi(CSG_Grid &Phi) { int iPoint, _x, _y, ix, iy; double x, y, z, dx, dy, wxy, wy, SW2, W[4][4]; CSG_Grid Delta; //----------------------------------------------------- Phi .Assign(0.0); Delta .Create(Phi.Get_System()); //----------------------------------------------------- for(iPoint=0; iPoint<m_Points.Get_Count() && Set_Progress(iPoint, m_Points.Get_Count()); iPoint++) { x = (m_Points[iPoint].x - Phi.Get_XMin()) / Phi.Get_Cellsize(); y = (m_Points[iPoint].y - Phi.Get_YMin()) / Phi.Get_Cellsize(); z = m_Points[iPoint].z; if( (_x = (int)x) >= 0 && _x < Phi.Get_NX() - 3 && (_y = (int)y) >= 0 && _y < Phi.Get_NY() - 3 ) { dx = x - _x; dy = y - _y; for(iy=0, SW2=0.0; iy<4; iy++) // compute W[k,l] and Sum[a=0-3, b=0-3](W²[a,b]) { wy = BA_Get_B(iy, dy); for(ix=0; ix<4; ix++) { wxy = W[iy][ix] = wy * BA_Get_B(ix, dx); SW2 += wxy*wxy; } } for(iy=0; iy<4; iy++) { for(ix=0; ix<4; ix++) { wxy = W[iy][ix]; Delta.Add_Value(_x + ix, _y + iy, wxy*wxy * ((wxy * z) / SW2)); // Numerator Phi .Add_Value(_x + ix, _y + iy, wxy*wxy); // Denominator } } } } //----------------------------------------------------- for(iy=0; iy<Phi.Get_NY(); iy++) { for(ix=0; ix<Phi.Get_NX(); ix++) { if( (z = Phi.asDouble(ix, iy)) != 0.0 ) { Phi.Set_Value(ix, iy, Delta.asDouble(ix, iy) / z); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CKriging_Regression::On_Execute(void) { //----------------------------------------------------- CSG_Shapes Points(SHAPE_TYPE_Point); CSG_Grid *pPrediction = Parameters("PREDICTION")->asGrid(); CSG_Grid *pRegression = Parameters("REGRESSION")->asGrid(); CSG_Grid *pResiduals = Parameters("RESIDUALS" )->asGrid(); CSG_Grid *pVariance = Parameters("VARIANCE" )->asGrid(); //----------------------------------------------------- if( !pResiduals ) { pResiduals = pPrediction; } //----------------------------------------------------- SG_RUN_MODULE_ExitOnError("statistics_regression", 1, // Multiple Regression Analysis (Points and Predictor Grids) SG_MODULE_PARAMETER_SET("PREDICTORS", Parameters("PREDICTORS")) && SG_MODULE_PARAMETER_SET("POINTS" , Parameters("POINTS" )) && SG_MODULE_PARAMETER_SET("ATTRIBUTE" , Parameters("FIELD" )) && SG_MODULE_PARAMETER_SET("INFO_COEFF", Parameters("INFO_COEFF")) && SG_MODULE_PARAMETER_SET("INFO_MODEL", Parameters("INFO_MODEL")) && SG_MODULE_PARAMETER_SET("INFO_STEPS", Parameters("INFO_STEPS")) && SG_MODULE_PARAMETER_SET("RESAMPLING", Parameters("RESAMPLING")) && SG_MODULE_PARAMETER_SET("COORD_X" , Parameters("COORD_X" )) && SG_MODULE_PARAMETER_SET("COORD_Y" , Parameters("COORD_Y" )) && SG_MODULE_PARAMETER_SET("INTERCEPT" , Parameters("INTERCEPT" )) && SG_MODULE_PARAMETER_SET("METHOD" , Parameters("METHOD" )) && SG_MODULE_PARAMETER_SET("P_VALUE" , Parameters("P_VALUE" )) && SG_MODULE_PARAMETER_SET("REGRESSION", pRegression) && SG_MODULE_PARAMETER_SET("RESIDUALS" , &Points ) ); //----------------------------------------------------- Process_Set_Text(m_OK.Get_Name()); m_OK.Set_Manager(NULL); if( !m_OK.Set_Parameter("POINTS" , &Points) || !m_OK.Set_Parameter("FIELD" , 2) // residual || !m_OK.Set_Parameter("LOG" , Parameters("LOG" )) || !m_OK.Set_Parameter("BLOCK" , Parameters("BLOCK" )) || !m_OK.Set_Parameter("DBLOCK" , Parameters("DBLOCK" )) || !m_OK.Set_Parameter("SEARCH_RANGE" , Parameters("SEARCH_RANGE" )) || !m_OK.Set_Parameter("SEARCH_RADIUS" , Parameters("SEARCH_RADIUS" )) || !m_OK.Set_Parameter("SEARCH_POINTS_ALL", Parameters("SEARCH_POINTS_ALL")) || !m_OK.Set_Parameter("SEARCH_POINTS_MIN", Parameters("SEARCH_POINTS_MIN")) || !m_OK.Set_Parameter("SEARCH_POINTS_MAX", Parameters("SEARCH_POINTS_MAX")) || !m_OK.Set_Parameter("SEARCH_DIRECTION" , Parameters("SEARCH_DIRECTION" )) || !m_OK.Set_Parameter("TARGET_DEFINITION", 1) // grid or grid system || !m_OK.Set_Parameter("PREDICTION" , pResiduals) || !m_OK.Set_Parameter("VARIANCE" , pVariance ) || (!SG_UI_Get_Window_Main() && ( // saga_cmd !m_OK.Set_Parameter("VAR_MAXDIST" , Parameters("VAR_MAXDIST" )) || !m_OK.Set_Parameter("VAR_NCLASSES" , Parameters("VAR_NCLASSES" )) || !m_OK.Set_Parameter("VAR_NSKIP" , Parameters("VAR_NSKIP" )) || !m_OK.Set_Parameter("VAR_MODEL" , Parameters("VAR_MODEL" )))) ) { Error_Set(CSG_String::Format(SG_T("%s [%s].[%s]"), _TL("could not initialize tool"), SG_T("statistics_regression"), m_OK.Get_Name().c_str())); return( false ); } if( !m_OK.Execute() ) { Error_Set(CSG_String::Format(SG_T("%s [%s].[%s]"), _TL("could not execute tool"), SG_T("statistics_regression"), m_OK.Get_Name().c_str()));\ return( false ); } //----------------------------------------------------- #pragma omp parallel for for(int y=0; y<Get_NY(); y++) { for(int x=0; x<Get_NX(); x++) { if( pRegression->is_NoData(x, y) || pResiduals->is_NoData(x, y) ) { pPrediction->Set_NoData(x, y); } else { pPrediction->Add_Value(x, y, pRegression->asDouble(x, y) + pResiduals->asDouble(x, y)); } } } //----------------------------------------------------- pRegression->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Regression"))); pPrediction->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Prediction"))); if( Parameters("RESIDUALS")->asGrid() ) { pResiduals->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Residuals"))); } if( pVariance ) { pVariance ->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Quality"))); } //----------------------------------------------------- return( true ); }