//--------------------------------------------------------- bool CGrid_Volume::On_Execute(void) { int x, y, Method; double Level, Volume, z; CSG_Grid *pGrid; CSG_String s; //----------------------------------------------------- pGrid = Parameters("GRID") ->asGrid(); Level = Parameters("LEVEL") ->asDouble(); Method = Parameters("METHOD") ->asInt(); //----------------------------------------------------- for(y=0, Volume=0.0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { if( !pGrid->is_NoData(x, y) ) { z = pGrid->asDouble(x, y) - Level; switch( Method ) { case 0: // Count Only Above Base Level if( z > 0.0 ) { Volume += z; } break; case 1: // Count Only Below Base Level if( z < 0.0 ) { Volume -= z; } break; case 2: // Subtract Volumes Below Base Level Volume += z; break; case 3: // Add Volumes Below Base Level Volume += fabs(z); break; } } } } //----------------------------------------------------- Volume *= pGrid->Get_Cellarea(); s.Printf(_TL("Volume: %f"), Volume); Message_Add(s); Message_Dlg(s, _TL("Grid Volume")); //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- int CTable_Trend_Base::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter) { if( pParameter->Cmp_Identifier("FORMULAS") ) { CSG_String Formula; switch( pParameter->asInt() ) { default: Formula = "a + b * x" ; break; case 1: Formula = "a + b * x + c * x^2" ; break; case 2: Formula = "a + b * x + c * x^2 + d * x^3"; break; case 3: Formula = "a + b * ln(x)" ; break; case 4: Formula = "a + b * x^c" ; break; case 5: Formula = "a + b / x" ; break; case 6: Formula = "a + b * (1 - exp(-x / c))" ; break; case 7: Formula = "a + b * (1 - exp(-(x / c)^2))"; break; } pParameters->Set_Parameter("FORMULA", Formula); } if( pParameter->Cmp_Identifier("FORMULA") ) { if( !m_Trend.Set_Formula(pParameter->asString()) ) { Message_Dlg(m_Trend.Get_Error(), _TL("Error in Formula")); return( false ); } } return( true ); }
//--------------------------------------------------------- int CTable_Trend_Base::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter) { if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("FORMULAS")) ) { const SG_Char *Formula; switch( pParameter->asInt() ) { default: return( false ); case 0: Formula = SG_T("a + b * x"); break; case 1: Formula = SG_T("a + b * x + c * x^2"); break; case 2: Formula = SG_T("a + b * x + c * x^2 + d * x^3"); break; case 3: Formula = SG_T("a + b * ln(x)"); break; case 4: Formula = SG_T("a + b * x^c"); break; case 5: Formula = SG_T("a + b / x"); break; case 6: Formula = SG_T("a + b * (1 - exp(-x / c))"); break; case 7: Formula = SG_T("a + b * (1 - exp(-(x / c)^2))"); break; } pParameters->Get_Parameter("FORMULA")->Set_Value(Formula); } if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("FORMULA")) ) { if( !m_Trend.Set_Formula(pParameter->asString()) ) { Message_Dlg(m_Trend.Get_Error(), _TL("Error in Formula")); return( false ); } } return( true ); }
//--------------------------------------------------------- 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 ); }
int CFit::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter) { if (!SG_STR_CMP(pParameter->Get_Identifier(), SG_T("FORMEL")) ) { CSG_String Msg; Formel.Set_Formula(pParameters->Get_Parameter("FORMEL")->asString()); if( Formel.Get_Error(Msg) ) { Error_Set (Msg); Message_Dlg(Msg); return( -1 ); } } return( 0 ); }
//--------------------------------------------------------- bool CSADO_SolarRadiation::On_Execute(void) { //----------------------------------------------------- m_pDEM = Parameters("GRD_DEM") ->asGrid(); m_pVP = Parameters("GRD_VAPOUR") ->asGrid(); m_pSumDirect = Parameters("GRD_DIRECT") ->asGrid(); m_bUpdateDirect = Parameters("UPD_DIRECT") ->asBool() && m_pSumDirect; m_pSumDiffus = Parameters("GRD_DIFFUS") ->asGrid(); m_bUpdateDiffus = Parameters("UPD_DIFFUS") ->asBool() && m_pSumDiffus; m_pSumTotal = Parameters("GRD_TOTAL") ->asGrid(); m_bUpdateTotal = Parameters("UPD_TOTAL") ->asBool() && m_pSumTotal; m_Solar_Const = Parameters("SOLARCONST") ->asDouble(); m_Atmosphere = Parameters("ATMOSPHERE") ->asDouble(); m_VP = Parameters("VAPOUR") ->asDouble(); m_bHorizon = Parameters("BHORIZON") ->asBool(); m_Latitude = Parameters("LATITUDE") ->asDouble() * M_DEG_TO_RAD; m_bBending = Parameters("BENDING") ->asBool(); m_Hour = Parameters("MOMENT") ->asDouble(); m_dHour = Parameters("DHOUR") ->asDouble(); m_dDays = Parameters("DDAYS") ->asInt(); m_Day_A = Parameters("DAY_A") ->asInt(); m_Day_B = Parameters("DAY_B") ->asInt(); switch( Parameters("PERIOD")->asInt() ) { case 0: // moment m_bMoment = true; m_bUpdateDirect = m_bUpdateDiffus = m_bUpdateTotal = false; break; case 1: // day m_bMoment = false; m_Day_B = m_Day_A; m_Hour = 0.0; break; case 2: // range of days m_bMoment = false; m_Hour = 0.0; break; case 3: // same moment for a range of days m_bMoment = false; m_dHour = 24.0; break; } //----------------------------------------------------- if( !m_pSumDirect && !m_pSumDiffus && !m_pSumTotal ) { Message_Dlg(_TL("No output grid has been choosen."), Get_Name()); } else if( m_pSumDirect == m_pDEM || m_pSumDiffus == m_pDEM || m_pSumTotal == m_pDEM ) { Message_Dlg(_TL("Output must not overwrite elevation grid."), Get_Name()); } else { return( Get_Insolation() ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool Cdodproperror::On_Execute(void) { if (!GetParameterValues()) { return false; } CSG_String TempDirPath = Parameters("TEMP_DIR")->asFilePath()->asString(); LogOutput = SG_File_Make_Path(TempDirPath, CSG_String("out"), CSG_String("txt")); LogError = SG_File_Make_Path(TempDirPath, CSG_String("error"), CSG_String("txt"));; NewDEM_InputPath = SG_File_Make_Path(TempDirPath, CSG_String("newdem"), CSG_String("tif")); OldDEM_InputPath = SG_File_Make_Path(TempDirPath, CSG_String("olddem"), CSG_String("tif")); PropError_InputPath = SG_File_Make_Path(TempDirPath, CSG_String("properror"), CSG_String("tif")); RawDoD_OutputPath = SG_File_Make_Path(TempDirPath, CSG_String("rawdodoutput"), CSG_String("tif")); ThresholdedDoD_OutputPath = SG_File_Make_Path(TempDirPath, CSG_String("threshdodoutput"), CSG_String("tif")); // convert grids to tiffs for command input CSG_Grid* InputGrids [3] = {NewDEM, OldDEM, PropError}; CSG_Strings InputGridPaths = CSG_Strings(); InputGridPaths.Add(NewDEM_InputPath); InputGridPaths.Add(OldDEM_InputPath); InputGridPaths.Add(PropError_InputPath); if (!SaveGridsAsTIFF(InputGrids, InputGridPaths)) { return false; } CSG_Strings OutputGridPaths = CSG_Strings(); OutputGridPaths.Add(RawDoD_OutputPath); OutputGridPaths.Add(ThresholdedDoD_OutputPath); CSG_Strings OutputGridNames = CSG_Strings(); OutputGridNames.Add("Raw DoD"); OutputGridNames.Add("Thresholded DoD"); // delete old output files (GCD throws an error if a file already exists) if (!DeleteFiles(OutputGridPaths)) { return false; } CSG_String CMD = CSG_String::Format(SG_T("\"\"%s\" %s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" >\"%s\" 2>\"%s\"\""), GCD.c_str(), GCD_CMD.c_str(), NewDEM_InputPath.c_str(), OldDEM_InputPath.c_str(), PropError_InputPath.c_str(), RawDoD_OutputPath.c_str(), ThresholdedDoD_OutputPath.c_str(), LogOutput.c_str(), LogError.c_str()); Message_Add(CSG_String("Executing: ") + CMD); if (system(CMD.b_str()) != 0) { Message_Dlg(CSG_String::Format(SG_T("Error while executing %s, see Execution Log for details"), GCD_CMD.c_str())); DisplayLogs(); return false; } CSG_Grid* OutputGrids [3] = {RawDoD, ThresholdedDoD}; if (!LoadTIFFsAsGrids(OutputGridPaths, OutputGrids, OutputGridNames)) { return false; } Parameters("RAW_DOD")->Set_Value(RawDoD); Parameters("THRESHOLDED_DOD")->Set_Value(ThresholdedDoD); ApplyColors(NewDEM, RawDoD); ApplyColors(NewDEM, ThresholdedDoD); DisplayFile(LogOutput); return true; }
//--------------------------------------------------------- bool CGCS_Grid_Longitude_Range::On_Execute(void) { CSG_Parameter_Grid_List *pInput = Parameters("INPUT" )->asGridList(); CSG_Parameter_Grid_List *pOutput = Parameters("OUTPUT")->asGridList(); if( pInput->Get_Count() <= 0 ) { Message_Dlg(_TL("nothing to do: no data in selection")); return( false ); } pOutput->Del_Items(); //----------------------------------------------------- int xZero; CSG_Grid_System Target; //----------------------------------------------------- if( Parameters("DIRECTION")->asInt() == 0 ) // 0 - 360 >> -180 - 180 { if( Get_XMax() <= 180.0 ) { Message_Add(_TL("Nothing to do. Raster is already within target range.")); return( true ); } else if( Get_XMin() >= 180.0 ) { xZero = 0; Target.Assign(Get_Cellsize(), Get_XMin() - 360.0, Get_YMin(), Get_NX(), Get_NY()); } else if( Get_XMax() - 360.0 < Get_XMin() - Get_Cellsize() ) { Error_Set(_TL("Nothing to do be done. Raster splitting is not supported.")); return( false ); } else { xZero = (int)(0.5 + 180.0 / Get_Cellsize()); Target.Assign(Get_Cellsize(), Get_XMin() - 180.0, Get_YMin(), Get_NX(), Get_NY()); } } //----------------------------------------------------- else // -180 - 180 >> 0 - 360 { if( Get_XMin() >= 0.0 ) { Message_Add(_TL("Nothing to do. Raster is already within target range.")); return( true ); } else if( Get_XMax() <= 0.0 ) { xZero = 0; Target.Assign(Get_Cellsize(), Get_XMin() + 360.0, Get_YMin(), Get_NX(), Get_NY()); } else if( Get_XMin() + 360.0 > Get_XMax() + Get_Cellsize() ) { Error_Set(_TL("Nothing to do be done. Raster splitting is not supported.")); return( false ); } else { xZero = (int)(0.5 + 180.0 / Get_Cellsize()); Target.Assign(Get_Cellsize(), Get_XMin() - 180.0, Get_YMin(), Get_NX(), Get_NY()); } } //----------------------------------------------------- for(int i=0; i<pInput->Get_Count() && Process_Get_Okay(); i++) { CSG_Grid *pIn = pInput->asGrid(i); CSG_Grid *pOut = SG_Create_Grid(Target, pIn->Get_Type()); pOut->Set_Name(pIn->Get_Name()); pOut->Set_NoData_Value_Range(pIn->Get_NoData_Value(), pIn->Get_NoData_hiValue()); pOut->Set_ZFactor(pIn->Get_ZFactor()); pOutput->Add_Item(pOut); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0, xx=xZero; x<Get_NX(); x++, xx++) { if( xx >= Get_NX() ) { xx = 0; } pOut->Set_Value(xx, y, pIn->asDouble(x, y)); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CExercise_01::On_Execute(void) { int x, y, Method; double Factor, Value_Input, Value_Output; CSG_Grid *pInput, *pOutput; //----------------------------------------------------- // Get parameter settings... pInput = Parameters("INPUT" )->asGrid(); pOutput = Parameters("OUTPUT")->asGrid(); Factor = Parameters("FACTOR")->asDouble(); Method = Parameters("METHOD")->asInt(); //----------------------------------------------------- // Check for valid parameter settings... if( Method == 3 && Factor == 0.0 ) { Message_Add(_TL("Division by zero is not allowed !!!")); Message_Dlg(_TL("Division by zero is not allowed !!!")); return( false ); // prevent a division by zero!!! } //----------------------------------------------------- // Execute calculation... for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Value_Input = pInput->asDouble(x, y); switch( Method ) { case 0: // Addition... Value_Output = Value_Input + Factor; break; case 1: // Subtraction... Value_Output = Value_Input - Factor; break; case 2: // Multiplication... Value_Output = Value_Input * Factor; break; case 3: // Division... Value_Output = Value_Input / Factor; break; } pOutput->Set_Value(x, y, Value_Output); } } //----------------------------------------------------- // Return 'true' if everything went okay... return( true ); }
bool CMine_Sweeper::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode) { int ok = true; int time; int redraw = false; int xpos; int ypos; if( !Get_Grid_Pos(xpos, ypos) ) return( false ); xpos/=SPRITE_SIZE; ypos/=SPRITE_SIZE; ypos=Mine_NY-1-ypos; switch( Mode ) { default: return( false ); case MODULE_INTERACTIVE_LDOWN: if(First_Click) { ResetBoard(xpos, ypos); First_Click=false; } ok = Play(xpos, ypos, false); redraw = true; break; case MODULE_INTERACTIVE_RDOWN: Mark(xpos, ypos); redraw = true; break; } if (redraw) { if(ok) { Show_GameBoard(false); time= Time->Time(); Message_Add(CSG_String::Format(SG_T(":-) Time:%ds Mines:%d\n"),time,N_Mines-MarkedMines)); if (OpenFields == Mine_NX*Mine_NY-N_Mines ) { Message_Add(CSG_String::Format(_TL(":-) :-) you are a winner :-) :-) Time:%ds\n"),time)); Message_Dlg(CSG_String::Format(_TL(":-) :-) you are a winner :-) :-) Time:%ds\n"),time)); Show_GameBoard(true); First_Click=true; } } else { Show_GameBoard(true); Message_Dlg(CSG_String::Format(_TL(":-( :-( you are a loser :-( :-("))); Message_Add(CSG_String::Format(_TL(":-( :-( you are a loser :-( :-("))); First_Click=true; } } return true; }