//--------------------------------------------------------- bool CShape_Index::Get_Diameters_Feret(CSG_Shape_Polygon *pPolygon, int Field, double dAngle) { CSG_Simple_Statistics F; double maxDir, maxF90, minDir, minF90; TSG_Point C = pPolygon->Get_Centroid(); // not really necessary for(double Direction=0.0; Direction<M_PI_090; Direction+=dAngle) { double sin_a = sin(Direction); double cos_a = cos(Direction); CSG_Simple_Statistics sx, sy; for(int iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++) { TSG_Point P = pPolygon->Get_Point(iPoint, iPart); P.x -= C.x; P.y -= C.y; // not really necessary sx += P.x * cos_a - P.y * sin_a; sy += P.x * sin_a + P.y * cos_a; } } #define CHECK_DIR(s, s90, d) { if( !F.Get_Count() ) { minDir = maxDir = d; minF90 = maxF90 = s90.Get_Range(); }\ else if( F.Get_Minimum() > s.Get_Range() ) { minDir = d; minF90 = s90.Get_Range(); }\ else if( F.Get_Maximum() < s.Get_Range() ) { maxDir = d; maxF90 = s90.Get_Range(); } F += s.Get_Range(); } CHECK_DIR(sx, sy, Direction + M_PI_090); CHECK_DIR(sy, sx, Direction ); } pPolygon->Set_Value(Field + 0, F.Get_Maximum()); pPolygon->Set_Value(Field + 1, maxDir * M_RAD_TO_DEG); pPolygon->Set_Value(Field + 2, F.Get_Minimum()); pPolygon->Set_Value(Field + 3, minDir * M_RAD_TO_DEG); pPolygon->Set_Value(Field + 4, F.Get_Mean()); pPolygon->Set_Value(Field + 5, maxF90); pPolygon->Set_Value(Field + 6, minF90); pPolygon->Set_Value(Field + 7, pow(3 * F.Get_Minimum() * F.Get_Maximum(), 1. / 3.)); 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 CGPS_Track_Aggregation::Set_Statistic(CSG_Table_Record *pAggregate, CSG_Simple_Statistics &Statistic, CSG_Simple_Statistics &Time, int nDropped, bool bVerbose) { if( pAggregate ) { pAggregate ->Set_Value(AGG_PARM , Statistic.Get_Mean()); pAggregate ->Set_Value(AGG_TIME , Time .Get_Mean()); if( bVerbose ) { pAggregate ->Set_Value(AGG_MIN , Statistic.Get_Minimum()); pAggregate ->Set_Value(AGG_MAX , Statistic.Get_Maximum()); pAggregate ->Set_Value(AGG_RANGE , Statistic.Get_Range ()); pAggregate ->Set_Value(AGG_STDDEV , Statistic.Get_StdDev ()); pAggregate ->Set_Value(AGG_COUNT , Statistic.Get_Count ()); pAggregate ->Set_Value(AGG_DTIME , Time .Get_Range ()); pAggregate ->Set_Value(AGG_DROPPED, nDropped); } return( true ); } 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 ); }