//--------------------------------------------------------- bool CGW_Regression_Grid::Get_Regression(int x, int y) { int nPoints = Set_Variables(x, y); if( nPoints < m_nPoints_Min ) { return( false ); } //----------------------------------------------------- int i; double zMean, rss, tss; CSG_Vector b, z; CSG_Matrix Y, YtW; //----------------------------------------------------- z .Create(nPoints); Y .Create(2, nPoints); YtW.Create(nPoints, 2); for(i=0, zMean=0.0; i<nPoints; i++) { Y [i][0] = 1.0; Y [i][1] = m_y[i]; YtW[0][i] = m_w[i]; YtW[1][i] = m_w[i] * m_y[i]; zMean += (z[i] = m_z[i]); } //----------------------------------------------------- b = (YtW * Y).Get_Inverse() * (YtW * z); zMean /= nPoints; for(i=0, rss=0.0, tss=0.0; i<nPoints; i++) { rss += m_w[i] * SG_Get_Square(m_z[i] - (b[0] + b[1] * m_y[i])); tss += m_w[i] * SG_Get_Square(m_z[i] - zMean); } GRID_SET_VALUE(m_pRegression, x, y, b[0] + b[1] * m_pPredictor->asDouble(x, y)); GRID_SET_VALUE(m_pIntercept , x, y, b[0]); GRID_SET_VALUE(m_pSlope , x, y, b[1]); GRID_SET_VALUE(m_pQuality , x, y, (tss - rss) / tss); //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- 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 CParam_Scale::On_Execute(void) { //----------------------------------------------------- bool bConstrain; int Index[6]; double zScale, Tol_Slope, Tol_Curve; CSG_Matrix Normal; //----------------------------------------------------- bConstrain = Parameters("CONSTRAIN")->asBool(); zScale = Parameters("ZSCALE" )->asDouble(); if( zScale <= 0.0 ) { zScale = 1.0; } Tol_Slope = Parameters("TOL_SLOPE")->asDouble(); Tol_Curve = Parameters("TOL_CURVE")->asDouble(); m_pDEM = Parameters("DEM" )->asGrid(); //----------------------------------------------------- CSG_Grid *pFeature = Parameters("FEATURES" )->asGrid(); CSG_Grid *pElevation = Parameters("ELEVATION")->asGrid(); CSG_Grid *pSlope = Parameters("SLOPE" )->asGrid(); CSG_Grid *pAspect = Parameters("ASPECT" )->asGrid(); CSG_Grid *pProfC = Parameters("PROFC" )->asGrid(); CSG_Grid *pPlanC = Parameters("PLANC" )->asGrid(); CSG_Grid *pLongC = Parameters("LONGC" )->asGrid(); CSG_Grid *pCrosC = Parameters("CROSC" )->asGrid(); CSG_Grid *pMiniC = Parameters("MINIC" )->asGrid(); CSG_Grid *pMaxiC = Parameters("MAXIC" )->asGrid(); //----------------------------------------------------- if( !Get_Weights() ) { return( false ); } if( !Get_Normal(Normal) ) { return( false ); } // To constrain the quadtratic through the central cell, ignore the calculations involving the // coefficient f. Since these are all in the last row and column of the matrix, simply redimension. if( !SG_Matrix_LU_Decomposition(bConstrain ? 5 : 6, Index, Normal.Get_Data()) ) { return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { CSG_Vector Observed; double elevation, slope, aspect, profc, planc, longc, crosc, minic, maxic; if( Get_Observed(x, y, Observed, bConstrain) && SG_Matrix_LU_Solve(bConstrain ? 5 : 6, Index, Normal, Observed.Get_Data()) ) { Get_Parameters(zScale, Observed.Get_Data(), elevation, slope, aspect, profc, planc, longc, crosc, minic, maxic); GRID_SET_VALUE(pFeature , Get_Feature(slope, minic, maxic, crosc, Tol_Slope, Tol_Curve)); GRID_SET_VALUE(pElevation, elevation + m_pDEM->asDouble(x, y)); // Add central elevation back GRID_SET_VALUE(pSlope , slope); GRID_SET_VALUE(pAspect , aspect); GRID_SET_VALUE(pProfC , profc); GRID_SET_VALUE(pPlanC , planc); GRID_SET_VALUE(pLongC , longc); GRID_SET_VALUE(pCrosC , crosc); GRID_SET_VALUE(pMiniC , minic); GRID_SET_VALUE(pMaxiC , maxic); } else { GRID_SET_NODATA(pFeature); GRID_SET_NODATA(pElevation); GRID_SET_NODATA(pSlope); GRID_SET_NODATA(pAspect); GRID_SET_NODATA(pProfC); GRID_SET_NODATA(pPlanC); GRID_SET_NODATA(pLongC); GRID_SET_NODATA(pCrosC); GRID_SET_NODATA(pMiniC); GRID_SET_NODATA(pMaxiC); } } } //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pFeature, "LUT"); if( pLUT && pLUT->asTable() ) { pLUT->asTable()->Del_Records(); LUT_SET_CLASS(FLAT , _TL("Planar" ), SG_GET_RGB(180, 180, 180)); LUT_SET_CLASS(PIT , _TL("Pit" ), SG_GET_RGB( 0, 0, 0)); LUT_SET_CLASS(CHANNEL, _TL("Channel" ), SG_GET_RGB( 0, 0, 255)); LUT_SET_CLASS(PASS , _TL("Pass (saddle)"), SG_GET_RGB( 0, 255, 0)); LUT_SET_CLASS(RIDGE , _TL("Ridge" ), SG_GET_RGB(255, 255, 0)); LUT_SET_CLASS(PEAK , _TL("Peak" ), SG_GET_RGB(255, 0, 0)); DataObject_Set_Parameter(pFeature, pLUT); DataObject_Set_Parameter(pFeature, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } //----------------------------------------------------- DataObject_Set_Colors(pSlope , 11, SG_COLORS_YELLOW_RED); DataObject_Set_Colors(pAspect, 11, SG_COLORS_ASPECT_3); DataObject_Set_Colors(pProfC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pPlanC , 11, SG_COLORS_RED_GREY_BLUE, false); DataObject_Set_Colors(pLongC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pCrosC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pMiniC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pMaxiC , 11, SG_COLORS_RED_GREY_BLUE, true); //----------------------------------------------------- return( true ); }