//--------------------------------------------------------- bool CTopographic_Correction::On_Execute(void) { //----------------------------------------------------- if( !Get_Illumination() ) { m_Slope .Destroy(); m_Illumination .Destroy(); return( false ); } if( !Get_Model() ) { m_Slope .Destroy(); m_Illumination .Destroy(); return( false ); } //----------------------------------------------------- Process_Set_Text(_TL("Topographic Correction")); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( m_pOriginal->is_NoData(x, y) ) { m_pCorrected->Set_NoData(x, y); } else { m_pCorrected->Set_Value(x, y, Get_Correction( m_Slope .asDouble(x, y), m_Illumination.asDouble(x, y), m_pOriginal ->asDouble(x, y) )); } } } //----------------------------------------------------- m_Slope .Destroy(); m_Illumination .Destroy(); return( true ); }
//--------------------------------------------------------- bool CGWR_Grid_Downscaling::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pPredictors = Parameters("PREDICTORS")->asGridList(); if( (m_nPredictors = pPredictors->Get_Count()) <= 0 ) { return( false ); } m_pDependent = Parameters("DEPENDENT")->asGrid(); if( !m_pDependent->Get_Extent().Intersects(Get_System()->Get_Extent()) ) { return( false ); } //----------------------------------------------------- int i; Process_Set_Text(_TL("upscaling of predictors")); m_pPredictors = (CSG_Grid **)SG_Calloc(m_nPredictors , sizeof(CSG_Grid *)); m_pModel = (CSG_Grid **)SG_Calloc(m_nPredictors + 1, sizeof(CSG_Grid *)); for(i=0; i<m_nPredictors; i++) { m_pPredictors[i] = SG_Create_Grid(m_pDependent->Get_System()); m_pPredictors[i] ->Assign(pPredictors->asGrid(i), GRID_INTERPOLATION_NearestNeighbour); // GRID_INTERPOLATION_Mean_Cells m_pModel [i] = SG_Create_Grid(m_pDependent->Get_System()); m_pModel [i] ->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPredictors->asGrid(i)->Get_Name(), _TL("Factor"))); } m_pModel[m_nPredictors] = SG_Create_Grid(m_pDependent->Get_System()); m_pModel[m_nPredictors] ->Set_Name(_TL("Intercept")); //----------------------------------------------------- Process_Set_Text(_TL("model creation")); bool bResult = Get_Model(); //----------------------------------------------------- for(i=0; i<m_nPredictors; i++) { delete(m_pPredictors[i]); m_pPredictors[i] = pPredictors->asGrid(i); } //----------------------------------------------------- if( bResult ) { Process_Set_Text(_TL("downscaling")); bResult = Set_Model(); } //----------------------------------------------------- if( Parameters("MODEL_OUT")->asBool() ) { CSG_Parameter_Grid_List *pModel = Parameters("MODEL")->asGridList(); pModel->Del_Items(); pModel->Add_Item(m_pModel[m_nPredictors]); for(i=0; i<m_nPredictors; i++) { pModel->Add_Item(m_pModel[i]); } } else { for(i=0; i<=m_nPredictors; i++) { delete(m_pModel[i]); } } SG_FREE_SAFE(m_pModel); SG_FREE_SAFE(m_pPredictors); return( bResult ); }
//--------------------------------------------------------- bool CGW_Multi_Regression_Grid::On_Execute(void) { int i; //----------------------------------------------------- CSG_Parameter_Grid_List *pPredictors = Parameters("PREDICTORS")->asGridList(); if( !Initialize(Parameters("POINTS")->asShapes(), Parameters("DEPENDENT")->asInt(), pPredictors) ) { Finalize(); return( false ); } //----------------------------------------------------- CSG_Grid Quality; m_dimModel = *Get_System(); if( Parameters("RESOLUTION")->asInt() == 1 && Parameters("RESOLUTION_VAL")->asDouble() > Get_Cellsize() ) { CSG_Rect r(Get_System()->Get_Extent()); r.Inflate(0.5 * Parameters("RESOLUTION_VAL")->asDouble(), false); m_dimModel.Assign(Parameters("RESOLUTION_VAL")->asDouble(), r); Quality.Create(m_dimModel); m_pQuality = &Quality; } else { m_pQuality = Parameters("QUALITY")->asGrid(); } //----------------------------------------------------- Process_Set_Text(_TL("upsetting model domain")); m_pPredictors = (CSG_Grid **)SG_Calloc(m_nPredictors , sizeof(CSG_Grid *)); m_pModel = (CSG_Grid **)SG_Calloc(m_nPredictors + 1, sizeof(CSG_Grid *)); for(i=0; i<m_nPredictors; i++) { if( m_dimModel.Get_Cellsize() > Get_Cellsize() ) // scaling { m_pPredictors[i] = SG_Create_Grid(m_dimModel); m_pPredictors[i] ->Assign(pPredictors->asGrid(i), GRID_INTERPOLATION_NearestNeighbour); // GRID_INTERPOLATION_Mean_Cells } else { m_pPredictors[i] = pPredictors->asGrid(i); } m_pModel [i] = SG_Create_Grid(m_dimModel); m_pModel [i] ->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPredictors->asGrid(i)->Get_Name(), _TL("Factor"))); } m_pModel[m_nPredictors] = SG_Create_Grid(m_dimModel); m_pModel[m_nPredictors] ->Set_Name(_TL("Intercept")); //----------------------------------------------------- Process_Set_Text(_TL("model creation")); bool bResult = Get_Model(); //----------------------------------------------------- if( m_dimModel.Get_Cellsize() > Get_Cellsize() ) // scaling { for(i=0; i<m_nPredictors; i++) { delete(m_pPredictors[i]); m_pPredictors[i] = pPredictors->asGrid(i); } } //----------------------------------------------------- if( bResult ) { Process_Set_Text(_TL("model application")); bResult = Set_Model(); } //----------------------------------------------------- if( Parameters("MODEL_OUT")->asBool() ) { CSG_Parameter_Grid_List *pModel = Parameters("MODEL")->asGridList(); pModel->Del_Items(); pModel->Add_Item(m_pModel[m_nPredictors]); for(i=0; i<m_nPredictors; i++) { pModel->Add_Item(m_pModel[i]); } } else { for(i=0; i<=m_nPredictors; i++) { delete(m_pModel[i]); } } SG_FREE_SAFE(m_pModel); SG_FREE_SAFE(m_pPredictors); Finalize(); return( bResult ); }
//--------------------------------------------------------- bool CGW_Regression::On_Execute(void) { //----------------------------------------------------- m_pPoints = Parameters("POINTS" )->asShapes(); m_iDependent = Parameters("DEPENDENT")->asInt (); m_iPredictor = Parameters("PREDICTOR")->asInt (); m_Weighting.Set_Parameters(&Parameters); //----------------------------------------------------- if( !m_Search.Initialize(m_pPoints, -1) ) { return( false ); } //----------------------------------------------------- m_pQuality = m_Grid_Target.Get_Grid("QUALITY" ); m_pSlope = m_Grid_Target.Get_Grid("SLOPE" ); m_pIntercept = m_Grid_Target.Get_Grid("INTERCEPT"); if( !m_pIntercept || !m_pSlope || !m_pQuality ) { m_Search.Finalize(); return( false ); } m_pIntercept->Set_Name(CSG_String::Format(SG_T("%s (%s)"), Parameters("DEPENDENT")->asString(), _TL("GWR Intercept"))); m_pSlope ->Set_Name(CSG_String::Format(SG_T("%s (%s)"), Parameters("DEPENDENT")->asString(), _TL("GWR Slope"))); m_pQuality ->Set_Name(CSG_String::Format(SG_T("%s (%s)"), Parameters("DEPENDENT")->asString(), _TL("GWR Quality"))); //----------------------------------------------------- for(int y=0; y<m_pIntercept->Get_NY() && Set_Progress(y, m_pIntercept->Get_NY()); y++) { for(int x=0; x<m_pIntercept->Get_NX(); x++) { CSG_Regression_Weighted Model; if( Get_Model(x, y, Model) ) { m_pIntercept->Set_Value(x, y, Model[0]); m_pSlope ->Set_Value(x, y, Model[1]); m_pQuality ->Set_Value(x, y, Model.Get_R2()); } else { m_pIntercept->Set_NoData(x, y); m_pSlope ->Set_NoData(x, y); m_pQuality ->Set_NoData(x, y); } } } //----------------------------------------------------- m_Search.Finalize(); DataObject_Update(m_pIntercept); DataObject_Update(m_pSlope); DataObject_Update(m_pQuality); return( true ); }