//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 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 CWindeffect_Correction::Get_Data(int x, int y, CSG_Matrix &Data, CSG_Simple_Statistics &statsObserved) { for(int i=0; i<m_Kernel.Get_Count(); i++) { int ix = m_Kernel.Get_X(i, x); int iy = m_Kernel.Get_Y(i, y); if( m_pBoundary->is_InGrid(ix, iy) && m_pWind->is_InGrid(ix, iy) && m_pObserved->is_InGrid(ix, iy) ) { CSG_Vector d(2); d[BND] = m_pBoundary->asDouble(ix, iy); d[WND] = m_pWind ->asDouble(ix, iy); Data.Add_Row(d); statsObserved += m_pObserved->asDouble(ix, iy); } } return( statsObserved.Get_Count() >= 5 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CGrid_Values_AddTo_Shapes::On_Execute(void) { CSG_Parameter_Grid_List *pGrids; CSG_Shapes *pShapes; //----------------------------------------------------- pShapes = Parameters("RESULT")->asShapes(); pGrids = Parameters("GRIDS" )->asGridList(); //----------------------------------------------------- if( pGrids->Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- if( pShapes == NULL ) { pShapes = Parameters("SHAPES")->asShapes(); } else if( pShapes != Parameters("SHAPES")->asShapes() ) { pShapes->Create(*Parameters("SHAPES")->asShapes()); } //----------------------------------------------------- switch( Parameters("RESAMPLING")->asInt() ) { default: m_Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: m_Resampling = GRID_RESAMPLING_Bilinear; break; case 2: m_Resampling = GRID_RESAMPLING_BicubicSpline; break; case 3: m_Resampling = GRID_RESAMPLING_BSpline; break; } //----------------------------------------------------- for(int iGrid=0; iGrid<pGrids->Get_Count(); iGrid++) { CSG_Grid *pGrid = pGrids->asGrid(iGrid); int Field = pShapes->Get_Field_Count(); pShapes->Add_Field(pGrid->Get_Name(), SG_DATATYPE_Double); for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Simple_Statistics Statistics; CSG_Shape *pShape = pShapes->Get_Shape(iShape); if( pShape->Get_Extent().Intersects(pGrid->Get_Extent()) ) { switch( pShapes->Get_Type() ) { case SHAPE_TYPE_Point: default: case SHAPE_TYPE_Points: Get_Data_Point (Statistics, pShape, pGrid); break; case SHAPE_TYPE_Line: Get_Data_Line (Statistics, pShape, pGrid); break; case SHAPE_TYPE_Polygon: Get_Data_Polygon(Statistics, pShape, pGrid); break; } } if( Statistics.Get_Count() > 0 ) { pShape->Set_Value(Field, Statistics.Get_Mean()); } else { pShape->Set_NoData(Field); } } } //----------------------------------------------------- if( pShapes == Parameters("SHAPES")->asShapes() ) { DataObject_Update(pShapes); } return( true ); }