//--------------------------------------------------------- double CSG_Variogram::Get_Lag_Distance(CSG_Shapes *pPoints, int Method, int nSkip) { if( Method == 0 ) { CSG_PRQuadTree QT(pPoints, 0); CSG_Simple_Statistics s; double x, y, z; if( nSkip < 1 ) { nSkip = 1; } for(int iPoint=0; iPoint<pPoints->Get_Count() && ::SG_UI_Process_Set_Progress(iPoint, pPoints->Get_Count()); iPoint+=nSkip) { TSG_Point p = pPoints->Get_Shape(iPoint)->Get_Point(0); if( QT.Select_Nearest_Points(p.x, p.y, 2) && QT.Get_Selected_Point(1, x, y, z) && (x != p.x || y != p.y) ) { s.Add_Value(SG_Get_Distance(x, y, p.x, p.y)); } } if( s.Get_Count() > 0 && s.Get_Mean() > 0.0 ) { return( s.Get_Mean() ); } } return( 0.25 * sqrt((pPoints->Get_Extent().Get_XRange() * pPoints->Get_Extent().Get_YRange()) / pPoints->Get_Count()) ); }
//--------------------------------------------------------- bool CInterpolation_AngularDistance::Get_Value(double x, double y, double &z) { int i, j, n; if( (n = m_Search.Set_Location(x, y)) <= 0 ) { return( false ); } //----------------------------------------------------- CSG_Vector X(n), Y(n), D(n), W(n), Z(n); for(i=0; i<n; i++) { m_Search.Get_Point(i, X[i], Y[i], Z[i]); D[i] = SG_Get_Distance(x, y, X[i], Y[i]); W[i] = m_Weighting.Get_Weight(D[i]); if( D[i] <= 0.0 ) { z = Z[i]; return( true ); } } //----------------------------------------------------- CSG_Simple_Statistics s; for(i=0; i<n; i++) { double w = 0.0, t = 0.0; for(j=0; j<n; j++) { if( j != i ) { t += W[j] * (1.0 - ((x - X[i]) * (x - X[j]) + (y - Y[i]) * (y - Y[j])) / (D[i] * D[j])); w += W[j]; } } s.Add_Value(Z[i], W[i] * (1.0 + t / w)); } //----------------------------------------------------- z = s.Get_Mean(); return( true ); }
//--------------------------------------------------------- bool CGSGrid_Residuals::Get_Statistics(int x, int y, bool bCenter) { if( m_pGrid->is_InGrid(x, y) ) { int i, ix, iy, nLower; double z, iz, id, iw; CSG_Simple_Statistics Statistics; for(i=0, nLower=0, z=m_pGrid->asDouble(x, y); i<m_Cells.Get_Count(); i++) { if( m_Cells.Get_Values(i, ix = x, iy = y, id, iw, true) && (bCenter || id > 0.0) && m_pGrid->is_InGrid(ix, iy) ) { Statistics.Add_Value(iz = m_pGrid->asDouble(ix, iy), iw); if( z > iz ) { nLower++; } } } //------------------------------------------------- if( Statistics.Get_Weights() > 0.0 ) { m_pMean ->Set_Value(x, y, Statistics.Get_Mean()); m_pDiff ->Set_Value(x, y, z - Statistics.Get_Mean()); m_pStdDev ->Set_Value(x, y, Statistics.Get_StdDev()); m_pRange ->Set_Value(x, y, Statistics.Get_Range()); m_pMin ->Set_Value(x, y, Statistics.Get_Minimum()); m_pMax ->Set_Value(x, y, Statistics.Get_Maximum()); m_pDevMean ->Set_Value(x, y, Statistics.Get_StdDev() > 0.0 ? ((z - Statistics.Get_Mean()) / Statistics.Get_StdDev()) : 0.0); m_pPercent ->Set_Value(x, y, 100.0 * nLower / (double)Statistics.Get_Count()); return( true ); } } //----------------------------------------------------- m_pMean ->Set_NoData(x, y); m_pDiff ->Set_NoData(x, y); m_pStdDev ->Set_NoData(x, y); m_pRange ->Set_NoData(x, y); m_pMin ->Set_NoData(x, y); m_pMax ->Set_NoData(x, y); m_pDevMean ->Set_NoData(x, y); m_pPercent ->Set_NoData(x, y); return( false ); }
//--------------------------------------------------------- bool CGSPoints_Distances::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pPoints = Parameters("POINTS") ->asShapes(); CSG_Table *pTable = Parameters("TABLE") ->asTable(); //----------------------------------------------------- CSG_PRQuadTree QT(pPoints, 0); CSG_Simple_Statistics s; double x, y, z; for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++) { TSG_Point p = pPoints->Get_Shape(iPoint)->Get_Point(0); if( QT.Select_Nearest_Points(p.x, p.y, 2) && QT.Get_Selected_Point(1, x, y, z) && (x != p.x || y != p.y) ) { s.Add_Value(SG_Get_Distance(x, y, p.x, p.y)); } } //----------------------------------------------------- if( s.Get_Count() > 0 ) { CSG_Table_Record *pRecord; pTable->Destroy(); pTable->Set_Name(CSG_String::Format(SG_T("%s [%s]"), _TL("Minimum Distance Analysis"), pPoints->Get_Name())); pTable->Add_Field(SG_T("NAME") , SG_DATATYPE_String); pTable->Add_Field(SG_T("VALUE") , SG_DATATYPE_Double); SET_VALUE(_TL("Mean Average") , s.Get_Mean()); SET_VALUE(_TL("Minimum") , s.Get_Minimum()); SET_VALUE(_TL("Maximum") , s.Get_Maximum()); SET_VALUE(_TL("Standard Deviation") , s.Get_StdDev()); SET_VALUE(_TL("Duplicates") , pPoints->Get_Count() - s.Get_Count()); DataObject_Update(pTable, SG_UI_DATAOBJECT_SHOW); return( true ); } Message_Dlg(_TL("not enough observations")); return( false ); }
//--------------------------------------------------------- bool CMultiBand_Variation::Get_Variation(int x, int y) { if( !m_Mask.is_NoData(x, y) ) { int iBand, iCell, ix, iy; double iDistance, iWeight, Weights, Distance; CSG_Vector Centroid(m_pBands->Get_Count()); //------------------------------------------------- for(iCell=0, Weights=0.0; iCell<m_Cells.Get_Count(); iCell++) { if( m_Cells.Get_Values(iCell, ix = x, iy = y, iDistance, iWeight, true) && m_Mask.is_InGrid(ix, iy) ) { for(iBand=0; iBand<m_pBands->Get_Count(); iBand++) { Centroid[iBand] += iWeight * m_pBands->asGrid(iBand)->asDouble(ix, iy); } Weights += iWeight; } } //------------------------------------------------- if( Weights > 0.0 ) { CSG_Simple_Statistics s; Centroid *= 1.0 / Weights; for(iCell=0; iCell<m_Cells.Get_Count(); iCell++) { if( m_Cells.Get_Values(iCell, ix = x, iy = y, iDistance, iWeight, true) && m_Mask.is_InGrid(ix, iy) ) { for(iBand=0, Distance=0.0; iBand<m_pBands->Get_Count(); iBand++) { Distance += SG_Get_Square(Centroid[iBand] - m_pBands->asGrid(iBand)->asDouble(ix, iy)); } s.Add_Value(sqrt(Distance), iWeight); if( ix == x && iy == y ) { if( m_pDiff ) m_pDiff->Set_Value(x, y, sqrt(Distance)); } } } if( m_pMean ) m_pMean ->Set_Value(x, y, s.Get_Mean()); if( m_pStdDev ) m_pStdDev->Set_Value(x, y, s.Get_StdDev()); return( true ); } } //----------------------------------------------------- if( m_pMean ) m_pMean ->Set_NoData(x, y); if( m_pStdDev ) m_pStdDev ->Set_NoData(x, y); if( m_pDiff ) m_pDiff ->Set_NoData(x, y); return( false ); }
//--------------------------------------------------------- bool CGSGrid_Statistics::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); if( pGrids->Get_Count() <= 1 ) { Error_Set(_TL("no grids in selection")); return( false ); } //----------------------------------------------------- CSG_Grid *pMean = Parameters("MEAN" )->asGrid(); CSG_Grid *pMin = Parameters("MIN" )->asGrid(); CSG_Grid *pMax = Parameters("MAX" )->asGrid(); CSG_Grid *pRange = Parameters("RANGE" )->asGrid(); CSG_Grid *pSum = Parameters("SUM" )->asGrid(); CSG_Grid *pVar = Parameters("VAR" )->asGrid(); CSG_Grid *pStdDev = Parameters("STDDEV" )->asGrid(); CSG_Grid *pStdDevLo = Parameters("STDDEVLO")->asGrid(); CSG_Grid *pStdDevHi = Parameters("STDDEVHI")->asGrid(); CSG_Grid *pPercentile = Parameters("PCTL" )->asGrid(); if( !pMean && !pMin && !pMax && !pRange && !pSum && !pVar && !pStdDev && !pStdDevLo && !pStdDevHi && !pPercentile ) { Error_Set(_TL("no parameter output specified")); return( false ); } double dRank = Parameters("PCTL_VAL")->asDouble() / 100.0; //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { CSG_Table Values; CSG_Simple_Statistics s; for(int i=0; i<pGrids->Get_Count(); i++) { if( !pGrids->asGrid(i)->is_NoData(x, y) ) { double z = pGrids->asGrid(i)->asDouble(x, y); s.Add_Value(z); if( pPercentile ) { if( Values.Get_Field_Count() == 0 ) { Values.Add_Field("Z", SG_DATATYPE_Double); } Values.Add_Record()->Set_Value(0, z); } } } //----------------------------------------- if( s.Get_Count() <= 0 ) { if( pMean ) pMean ->Set_NoData(x, y); if( pMin ) pMin ->Set_NoData(x, y); if( pMax ) pMax ->Set_NoData(x, y); if( pRange ) pRange ->Set_NoData(x, y); if( pSum ) pSum ->Set_NoData(x, y); if( pVar ) pVar ->Set_NoData(x, y); if( pStdDev ) pStdDev ->Set_NoData(x, y); if( pStdDevLo ) pStdDevLo ->Set_NoData(x, y); if( pStdDevHi ) pStdDevHi ->Set_NoData(x, y); if( pPercentile ) pPercentile ->Set_NoData(x, y); } else { if( pMean ) pMean ->Set_Value(x, y, s.Get_Mean()); if( pMin ) pMin ->Set_Value(x, y, s.Get_Minimum()); if( pMax ) pMax ->Set_Value(x, y, s.Get_Maximum()); if( pRange ) pRange ->Set_Value(x, y, s.Get_Range()); if( pSum ) pSum ->Set_Value(x, y, s.Get_Sum()); if( pVar ) pVar ->Set_Value(x, y, s.Get_Variance()); if( pStdDev ) pStdDev ->Set_Value(x, y, s.Get_StdDev()); if( pStdDevLo ) pStdDevLo ->Set_Value(x, y, s.Get_Mean() - s.Get_StdDev()); if( pStdDevHi ) pStdDevHi ->Set_Value(x, y, s.Get_Mean() + s.Get_StdDev()); if( pPercentile ) { Values.Set_Index(0, TABLE_INDEX_Ascending); pPercentile->Set_Value(x, y, Values.Get_Record_byIndex((int)(dRank * s.Get_Count()))->asDouble(0)); } } } } //----------------------------------------------------- return( true ); }