//--------------------------------------------------------- bool CGW_Multi_Regression_Grid::Set_Model(void) { CSG_Grid *pRegression = Parameters("REGRESSION")->asGrid(); CSG_Grid *pQuality = Parameters("QUALITY" )->asGrid(); pRegression->Set_Name(CSG_String::Format(SG_T("%s [%s]" ), m_Points.Get_Name(), _TL("GWR"))); pQuality ->Set_Name(CSG_String::Format(SG_T("%s [%s, %s]"), m_Points.Get_Name(), _TL("GWR"), _TL("Quality"))); if( m_pQuality == Parameters("QUALITY")->asGrid() ) { pQuality = NULL; } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { double p_y = Get_YMin() + y * Get_Cellsize(); #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double Value, p_x = Get_XMin() + x * Get_Cellsize(); if( Set_Model(p_x, p_y, Value) ) { GRID_SET_VALUE(pRegression, x, y, Value); GRID_SET_VALUE(pQuality , x, y, m_pQuality->Get_Value(p_x, p_y)); } else { GRID_SET_NODATA(pRegression, x, y); GRID_SET_NODATA(pQuality , x, y); } } } //----------------------------------------------------- Set_Residuals(); return( true ); }
//--------------------------------------------------------- bool CPoint_Zonal_Multi_Grid_Regression::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pPoints = Parameters("POINTS" )->asShapes(); CSG_Shapes *pZones = Parameters("ZONES" )->asShapes(); CSG_Grid *pRegression = Parameters("REGRESSION")->asGrid (); pRegression->Assign_NoData(); CSG_Grid Regression(*Get_System(), SG_DATATYPE_Float); SG_UI_Progress_Lock(true); // suppress dialogs from popping up for(int i=0; i<pZones->Get_Count() && Process_Get_Okay(); i++) { CSG_Shape_Polygon *pZone = (CSG_Shape_Polygon *)pZones->Get_Shape(i); //------------------------------------------------- // select all points located in current zone polygon bool bResult; CSG_Shapes Zone(SHAPE_TYPE_Polygon); Zone.Add_Shape(pZone); SG_RUN_TOOL(bResult, "shapes_tools", 5, // select points by location SG_TOOL_PARAMETER_SET("LOCATIONS", &Zone) && SG_TOOL_PARAMETER_SET("SHAPES" , pPoints) ); if( !bResult ) { SG_UI_Process_Set_Okay(); // don't stop overall work flow, if tool execution failed for current zone } else if( pPoints->Get_Selection_Count() > 0 ) { //--------------------------------------------- // copy selected points to a new (temporary) points layer CSG_Shapes Selection; SG_RUN_TOOL(bResult, "shapes_tools", 6, // copy selected points to a new layer SG_TOOL_PARAMETER_SET("INPUT" , pPoints) && SG_TOOL_PARAMETER_SET("OUTPUT", &Selection) ); pPoints->asShapes()->Select(); // unselect everything from original points layer //--------------------------------------------- // perform the regression analysis, regression grid for zone is temporary SG_RUN_TOOL(bResult, "statistics_regression", 1, // multiple linear regression for points and predictor grids SG_TOOL_PARAMETER_SET("PREDICTORS", Parameters("PREDICTORS")) && SG_TOOL_PARAMETER_SET("REGRESSION", &Regression ) && SG_TOOL_PARAMETER_SET("POINTS" , &Selection ) && SG_TOOL_PARAMETER_SET("ATTRIBUTE" , Parameters("ATTRIBUTE" )) && SG_TOOL_PARAMETER_SET("RESAMPLING", Parameters("RESAMPLING")) && SG_TOOL_PARAMETER_SET("COORD_X" , Parameters("COORD_X" )) && SG_TOOL_PARAMETER_SET("COORD_Y" , Parameters("COORD_Y" )) && SG_TOOL_PARAMETER_SET("INTERCEPT" , Parameters("INTERCEPT" )) && SG_TOOL_PARAMETER_SET("METHOD" , Parameters("METHOD" )) && SG_TOOL_PARAMETER_SET("P_VALUE" , Parameters("P_VALUE" )) ); //--------------------------------------------- // use zone polygon as mask for copying zonal regression result to final regression grid if( !bResult ) { SG_UI_Process_Set_Okay(); // don't stop overall work flow, if tool execution failed for current zone } else { #pragma omp parallel for // speed up using multiple processors for(int y=0; y<Get_NY(); y++) { for(int x=0; x<Get_NX(); x++) { if( !Regression.is_NoData(x, y) && pZone->Contains(Get_System()->Get_Grid_to_World(x, y)) ) { pRegression->Set_Value(x, y, Regression.asDouble(x, y)); } } } } } } //----------------------------------------------------- SG_UI_Progress_Lock(false); //----------------------------------------------------- Set_Residuals(pPoints, pRegression); //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGW_Regression_Grid::On_Execute(void) { //----------------------------------------------------- m_pPredictor = Parameters("PREDICTOR" )->asGrid (); m_pRegression = Parameters("REGRESSION")->asGrid (); m_pQuality = Parameters("QUALITY" )->asGrid (); m_pIntercept = Parameters("INTERCEPT" )->asGrid (); m_pSlope = Parameters("SLOPE" )->asGrid (); m_pPoints = Parameters("POINTS" )->asShapes(); m_iDependent = Parameters("DEPENDENT" )->asInt (); m_nPoints_Min = Parameters("SEARCH_POINTS_MIN")->asInt (); m_nPoints_Max = Parameters("SEARCH_POINTS_ALL")->asInt () == 0 ? Parameters("SEARCH_POINTS_MAX")->asInt () : 0; m_Radius = Parameters("SEARCH_RANGE" )->asInt () == 0 ? Parameters("SEARCH_RADIUS" )->asDouble() : 0.0; m_Direction = Parameters("SEARCH_DIRECTION" )->asInt () == 0 ? -1 : 4; m_Weighting.Set_Parameters(Parameters("WEIGHTING")->asParameters()); //----------------------------------------------------- if( (m_nPoints_Max > 0 || m_Radius > 0.0) && !m_Search.Create(m_pPoints, -1) ) { return( false ); } //----------------------------------------------------- GRID_INIT(m_pRegression, _TL("GWR Regression")); GRID_INIT(m_pQuality , _TL("GWR Quality")); GRID_INIT(m_pIntercept , _TL("GWR Intercept")); GRID_INIT(m_pSlope , _TL("GWR Slope")); //----------------------------------------------------- int nPoints_Max = m_nPoints_Max > 0 ? m_nPoints_Max : m_pPoints->Get_Count(); m_y.Create(nPoints_Max); m_z.Create(nPoints_Max); m_w.Create(nPoints_Max); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( m_pPredictor->is_NoData(x, y) || !Get_Regression(x, y) ) { GRID_SET_NODATA(m_pRegression , x, y); GRID_SET_NODATA(m_pIntercept , x, y); GRID_SET_NODATA(m_pSlope , x, y); GRID_SET_NODATA(m_pQuality , x, y); } } } //----------------------------------------------------- Set_Residuals(); m_y.Destroy(); m_z.Destroy(); m_w.Destroy(); m_Search.Destroy(); DataObject_Update(m_pIntercept); DataObject_Update(m_pSlope); DataObject_Update(m_pQuality); return( true ); }
//--------------------------------------------------------- bool CPoint_Trend_Surface::On_Execute(void) { int iAttribute; CSG_Shapes *pPoints, *pResiduals; CSG_Grid *pRegression; //----------------------------------------------------- pPoints = Parameters("POINTS") ->asShapes(); pResiduals = Parameters("RESIDUALS") ->asShapes(); iAttribute = Parameters("ATTRIBUTE") ->asInt(); switch( Parameters("POLYNOM")->asInt() ) { case 0: m_xOrder = 1; m_yOrder = 1; m_tOrder = 1; break; // simple planar surface // a + bx + cy case 1: m_xOrder = 1; m_yOrder = 1; m_tOrder = 2; break; // bi-linear saddle"), // a + bx + cy + dxy case 2: m_xOrder = 2; m_yOrder = 2; m_tOrder = 2; break; // quadratic surface"), // a + bx + cy + dxy + ex2 + fy2 case 3: m_xOrder = 3; m_yOrder = 3; m_tOrder = 3; break; // cubic surface"), // a + bx + cy + dxy + ex2 + fy2 + gx2y + hxy2 + ix3 + iy3 case 4: m_xOrder = Parameters("XORDER")->asInt(); m_yOrder = Parameters("YORDER")->asInt(); m_tOrder = Parameters("TORDER")->asInt(); break; } //----------------------------------------------------- if( !Get_Regression(pPoints, iAttribute) ) { return( false ); } Set_Message(); //----------------------------------------------------- pRegression = NULL; switch( Parameters("TARGET")->asInt() ) { case 0: // user defined... if( m_Grid_Target.Init_User(pPoints->Get_Extent()) && Dlg_Parameters("USER") ) { pRegression = m_Grid_Target.Get_User(); } break; case 1: // grid... if( Dlg_Parameters("GRID") ) { pRegression = m_Grid_Target.Get_Grid(); } break; } if( pRegression == NULL ) { return( false ); } //----------------------------------------------------- pRegression->Set_Name(CSG_String::Format(SG_T("%s [%s]"), Parameters("ATTRIBUTE")->asString(), _TL("Trend Surface"))); Set_Regression(pRegression); Set_Residuals(pPoints, iAttribute, pResiduals, pRegression); m_Coefficients.Destroy(); return( true ); }