//--------------------------------------------------------- bool CDVWK_SoilMoisture::On_Execute(void) { int Day, x, y, i, LandUseID; CSG_Grid *pGrid; //----------------------------------------------------- if( pClimate->Get_Record_Count() > 0 ) { pFK_mm = Parameters("STA_FC") ->asGrid(); FK_mm_Def = Parameters("STA_FC_DEF") ->asDouble(); pPWP_mm = Parameters("STA_PWP") ->asGrid(); PWP_mm_Def = Parameters("STA_PWP_DEF") ->asDouble(); pWi_mm = Parameters("DYN_W") ->asGrid(); DataObject_Set_Colors(pWi_mm, 100, SG_COLORS_YELLOW_BLUE); //------------------------------------------------- pLandUse = SG_Create_Grid(pWi_mm, pCropCoeff->Get_Record_Count() < 127 ? SG_DATATYPE_Char : SG_DATATYPE_Int); pLandUse->Assign(Parameters("LANDUSE_DEF")->asInt()); if( (pGrid = Parameters("LANDUSE")->asGrid()) != NULL ) { for(y=0; y<Get_NY(); y++) { for(x=0; x<Get_NX(); x++) { LandUseID = pGrid->asInt(x, y); for(i=0; i<pCropCoeff->Get_Record_Count(); i++) { if( LandUseID == pCropCoeff->Get_Record(i)->asInt(0) ) { pLandUse->Set_Value(x, y, i); break; } } } } } //------------------------------------------------- DataObject_Update(pWi_mm, 0, pFK_mm ? pFK_mm->Get_ZMax() : FK_mm_Def, true); for(Day=0; Day<365 && Set_Progress(Day, 365); Day++) { Step_Day(Day); DataObject_Update(pWi_mm, true); } //------------------------------------------------- delete(pLandUse); return( true ); } return( false ); }
//--------------------------------------------------------- bool CSADO_SolarRadiation::Get_Insolation(void) { //----------------------------------------------------- if( Initialise() ) { if( m_bMoment ) { Get_Insolation(m_Day_A, m_Hour); Finalise(); } //------------------------------------------------- else { for(int Day=m_Day_A; Day<=m_Day_B && Process_Get_Okay(false); Day+=m_dDays) { for(double Hour=m_Hour; Hour<24.0 && Process_Get_Okay(false); Hour+=m_dHour) { Process_Set_Text(CSG_String::Format(SG_T("%s: %d(%d-%d), %s: %f"), _TL("Day"), Day, m_Day_A, m_Day_B, _TL("Hour"), Hour)); if( m_bUpdateDirect ) m_pSumDirect->Assign(0.0); if( m_bUpdateDiffus ) m_pSumDiffus->Assign(0.0); if( m_bUpdateTotal ) m_pSumTotal ->Assign(0.0); if( Get_Insolation(Day, Hour) ) { if( m_bUpdateDirect ) { m_TmpDirect += *m_pSumDirect; DataObject_Update(m_pSumDirect); } if( m_bUpdateDiffus ) { m_TmpDiffus += *m_pSumDiffus; DataObject_Update(m_pSumDiffus); } if( m_bUpdateTotal ) { m_TmpTotal += *m_pSumTotal; DataObject_Update(m_pSumTotal); } } } } Finalise(m_dHour / (24.0 * (1 + m_Day_B - m_Day_A))); // *m_pSumDirect *= m_dHour / D->size(); } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CLife::On_Execute(void) { //----------------------------------------------------- m_pLife = m_Grid_Target.Get_Grid("LIFE", SG_DATATYPE_Byte); if( !m_pLife ) { Error_Set(_TL("could not create target grid")); return( false ); } //----------------------------------------------------- m_nColors = Parameters("FADECOLOR")->asInt(); for(int y=0; y<m_pLife->Get_NY(); y++) { for(int x=0; x<m_pLife->Get_NX(); x++) { m_pLife->Set_Value(x, y, CSG_Random::Get_Uniform(0, 100) < 50 ? 0 : m_nColors); } } //----------------------------------------------------- m_pLife->Set_Name(_TL("Conway's Game of Life")); m_pLife->Set_NoData_Value(-1); DataObject_Add (m_pLife); DataObject_Set_Colors(m_pLife, 11, SG_COLORS_WHITE_BLUE); DataObject_Update (m_pLife, 0, m_nColors, SG_UI_DATAOBJECT_SHOW); //----------------------------------------------------- int i; m_Count.Create(m_pLife->Get_System(), SG_DATATYPE_Byte); for(i=1; Process_Get_Okay(true) && Next_Cycle(i > m_nColors); i++) { Process_Set_Text(CSG_String::Format("%s: %d", _TL("Life Cycle"), i)); DataObject_Update(m_pLife, 0, m_nColors); } m_Count.Destroy(); //----------------------------------------------------- if( is_Progress() ) { Message_Add(CSG_String::Format("\n%s %d %s\n", _TL("Dead after"), i, _TL("Life Cycles")), false); } return( true ); }
//--------------------------------------------------------- bool CGrid_Profile::On_Execute(void) { m_pDEM = Parameters("DEM") ->asGrid(); m_pValues = Parameters("VALUES") ->asGridList(); m_pPoints = Parameters("POINTS") ->asShapes(); m_pLine = Parameters("LINE") ->asShapes(); m_bAdd = false; DataObject_Update(m_pDEM , SG_UI_DATAOBJECT_SHOW_NEW_MAP); DataObject_Update(m_pLine, SG_UI_DATAOBJECT_SHOW_LAST_MAP); return( true ); }
//--------------------------------------------------------- bool CKinWav_D8::Gauges_Set_Flow(double Time) { if( m_pGauges_Flow && m_pGauges_Flow->Get_Field_Count() == m_pGauges->Get_Count() + 1 ) { CSG_Table_Record *pRecord = m_pGauges_Flow->Add_Record(); pRecord->Set_Value(0, Time); for(int i=0; i<m_pGauges->Get_Count(); i++) { double Flow; if( m_pFlow->Get_Value(m_pGauges->Get_Shape(i)->Get_Point(0), Flow) ) { pRecord->Set_Value(i + 1, Flow); } } DataObject_Update(m_pGauges_Flow); return( true ); } return( false ); }
bool CIsochronesVar::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode) { int iX, iY; if( Mode != MODULE_INTERACTIVE_LDOWN || !Get_Grid_Pos(iX, iY) ) { return( false ); } m_pTime->Assign((double)0); writeTimeOut(iX, iY, iX, iY); for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ m_pTime->Set_Value(x,y,m_pTime->asDouble(x,y)/3600.); }// for }// for ZeroToNoData(); DataObject_Update(m_pTime, true); return (true); }//method
//--------------------------------------------------------- bool CGrid_Profile::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode) { switch( Mode ) { default: break; case MODULE_INTERACTIVE_LDOWN: if( !m_bAdd ) { m_bAdd = true; m_pLine->Create(SHAPE_TYPE_Line, CSG_String::Format(SG_T("Profile [%s]"), m_pDEM->Get_Name())); m_pLine->Add_Field("ID" , SG_DATATYPE_Int); m_pLine->Add_Shape()->Set_Value(0, 1); } m_pLine->Get_Shape(0)->Add_Point(Get_System()->Fit_to_Grid_System(ptWorld)); DataObject_Update(m_pLine); break; case MODULE_INTERACTIVE_RDOWN: Set_Profile(); m_bAdd = false; break; } return( true ); }
//--------------------------------------------------------- bool CSelect_Points::On_Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode) { switch( Mode ) { case TOOL_INTERACTIVE_LUP: m_pSelection->Del_Records(); if( m_bAddCenter ) { m_pSelection->Add_Shape()->Add_Point(ptWorld); } if( m_Search.Select_Nearest_Points(ptWorld.Get_X(), ptWorld.Get_Y(), m_MaxPoints, m_Radius, m_Quadrant) ) { for(int i=0; i<m_Search.Get_Selected_Count(); i++) { CSG_Shape *pPoint = m_pSelection->Add_Shape(m_pPoints->Get_Shape((int)m_Search.Get_Selected_Z(i))); pPoint->Set_Value(m_pSelection->Get_Field_Count() - 2, i + 1); pPoint->Set_Value(m_pSelection->Get_Field_Count() - 1, m_Search.Get_Selected_Distance(i)); } } DataObject_Update(m_pSelection); break; default: break; } return( true ); }
void Cdodproperror::ApplyColors(CSG_Grid* from, CSG_Grid* to) { CSG_Colors colors; DataObject_Get_Colors(from, colors); DataObject_Set_Colors(to, colors); DataObject_Update(to, false); }
//--------------------------------------------------------- void CHillslope_Evolution_FTCS::Set_Difference(void) { CSG_Grid *pDiff = Parameters("DIFF")->asGrid(); if( pDiff ) { CSG_Grid *pDEM = Parameters("DEM")->asGrid(); #pragma omp parallel for for(int i=0; i<Get_NCells(); i++) { if( pDEM->is_NoData(i) ) { pDiff->Set_NoData(i); } else { pDiff->Set_Value(i, m_pDEM->asDouble(i) - pDEM->asDouble(i)); } } if( Parameters("UPDATE")->asBool() ) { DataObject_Update(pDiff, SG_UI_DATAOBJECT_SHOW); } } }
//--------------------------------------------------------- bool CGridding_Spline_MBA::_Set_MBA_Refinement(double dCell) { bool bContinue; int nCells; CSG_Grid A, B, *Phi, *Psi, *pTmp; for(bContinue=true, Psi=&A, Phi=&B, nCells=1; bContinue; nCells*=2, dCell/=2.0) { bContinue = _Get_Phi(*Phi, dCell, nCells); if( nCells > 1 ) { _Set_MBA_Refinement(Psi, Phi); } pTmp = Phi; Phi = Psi; Psi = pTmp; if( m_bUpdate ) { BA_Set_Grid(*Psi); DataObject_Update(m_pGrid, true); } } BA_Set_Grid(*Psi); return( true ); }
//--------------------------------------------------------- void CMandelbrot::Calculate(void) { int x, y, i; double xPos, yPos, dx, dy; dx = m_Extent.Get_XRange() / (m_pGrid->Get_NX() - 1.0); dy = m_Extent.Get_YRange() / (m_pGrid->Get_NY() - 1.0); for(y=0, yPos=m_Extent.Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, yPos+=dy) { for(x=0, xPos=m_Extent.Get_XMin(); x<m_pGrid->Get_NX(); x++, xPos+=dx) { switch( m_Method ) { default: case 0: i = Get_Mandelbrot (xPos, yPos); break; case 1: i = Get_Julia (xPos, yPos); break; } if( i >= m_maxIterations ) { m_pGrid->Set_NoData(x, y); } else { m_pGrid->Set_Value(x, y, i); } } } DataObject_Update(m_pGrid, true); }
bool CSinuosity::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode){ int iX, iY; if( Mode != MODULE_INTERACTIVE_LDOWN || !Get_Grid_Pos(iX, iY) ) { return( false ); } // if( !m_pDEM->is_InGrid_byPos(ptWorld.Get_X(), ptWorld.Get_Y()) ){ // return false; // }//if // iX = (int) ((ptWorld.Get_X() - m_pDEM->Get_XMin()) / m_pDEM->Get_Cellsize()); // iY = (int) ((ptWorld.Get_Y() - m_pDEM->Get_YMin()) / m_pDEM->Get_Cellsize()); m_iX = iX; m_iY = iY; m_pSinuosity->Assign((double)0); writeDistOut(iX, iY, iX, iY); ZeroToNoData(); calculateSinuosity(); DataObject_Update(m_pSinuosity); return true; }//method
//--------------------------------------------------------- bool CMine_Sweeper::MakeBoard(int level) { int i, x, y; CSG_Colors Colors; switch( level ) { case 0: Mine_NX = 8; Mine_NY = 8; N_Mines=10; break; case 1: Mine_NX = 16; Mine_NY = 16; N_Mines=40; break; case 2: Mine_NX = 30; Mine_NY = 16; N_Mines=99; break; } pInput = SG_Create_Grid(SG_DATATYPE_Int,SPRITE_SIZE*Mine_NX, SPRITE_SIZE*Mine_NY); pInput->Set_Name(_TL("Mine Sweeper")); Parameters("GRID")->Set_Value(pInput); //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pInput, "LUT"); if( pLUT && pLUT->asTable() ) { pLUT->asTable()->Del_Records(); for(i=0; i<16; i++) { CSG_Table_Record *pRecord = pLUT->asTable()->Add_Record(); pRecord->Set_Value(0, SG_GET_RGB(mine_res_color[i*3], mine_res_color[i*3+1], mine_res_color[i*3+2])); pRecord->Set_Value(3, i); } DataObject_Set_Parameter(pInput, pLUT); DataObject_Set_Parameter(pInput, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } Colors.Set_Count(16); for ( i=0;i<16; i++) { Colors.Set_Color(i, SG_GET_RGB(mine_res_color[i*3], mine_res_color[i*3+1], mine_res_color[i*3+2])); } DataObject_Set_Colors(pInput, Colors); DataObject_Update(pInput, 0.0, 15.0, true); //----------------------------------------------------- for( y = 0; y < Mine_NY; y++) for( x = 0; x < Mine_NX; x++) { SetSprite(x,y,SPRITE_CLOSE); } pInput->Set_Value(0, 0); return true; }
//--------------------------------------------------------- bool CFilter_Rank::On_Execute(void) { int x, y; double Rank; CSG_Grid *pResult; //----------------------------------------------------- m_pInput = Parameters("INPUT" )->asGrid(); pResult = Parameters("RESULT")->asGrid(); Rank = Parameters("RANK" )->asInt() / 100.0; //----------------------------------------------------- m_Kernel.Set_Radius(Parameters("RADIUS")->asInt(), Parameters("MODE")->asInt() == 0); //----------------------------------------------------- if( !pResult || pResult == m_pInput ) { pResult = SG_Create_Grid(m_pInput); } else { pResult->Set_Name(CSG_String::Format(SG_T("%s [%s: %.1f]"), m_pInput->Get_Name(), _TL("Rank"), 100.0 * Rank)); pResult->Set_NoData_Value(m_pInput->Get_NoData_Value()); } //----------------------------------------------------- for(y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel private(x) for(x=0; x<Get_NX(); x++) { double Value; if( Get_Value(x, y, Rank, Value) ) { pResult->Set_Value(x, y, Value); } else { pResult->Set_NoData(x, y); } } } //----------------------------------------------------- if( !Parameters("RESULT")->asGrid() || Parameters("RESULT")->asGrid() == m_pInput ) { m_pInput->Assign(pResult); delete(pResult); DataObject_Update(m_pInput); } m_Kernel.Destroy(); return( true ); }
//--------------------------------------------------------- bool CGeoref_Grid_Move::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode) { if( Mode == MODULE_INTERACTIVE_LDOWN ) { m_Down = ptWorld; } else if( Mode == MODULE_INTERACTIVE_LUP ) { if( m_Down != ptWorld ) { if( m_pSource == NULL ) { m_pSource = new CSG_Grid(*m_pGrid); m_pSource ->Set_Name(m_pGrid->Get_Name()); m_Move = m_Down - ptWorld; } else { m_Move += m_Down - ptWorld; } //--------------------------------------------- int x, y, ix, iy, dx, dy; dx = (int)(0.5 + m_Move.Get_X() / m_pSource->Get_Cellsize()); dy = (int)(0.5 + m_Move.Get_Y() / m_pSource->Get_Cellsize()); for(y=0, iy=dy; y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, iy++) { if( iy >= 0 && iy < m_pSource->Get_NY() ) { for(x=0, ix=dx; x<m_pGrid->Get_NX(); x++, ix++) { if( ix >= 0 && ix < m_pSource->Get_NX() ) { m_pGrid->Set_Value(x, y, m_pSource->asDouble(ix, iy)); } else { m_pGrid->Set_NoData(x, y); } } } else { for(x=0; x<m_pGrid->Get_NX(); x++) { m_pGrid->Set_NoData(x, y); } } } DataObject_Update(m_pGrid); } } return( true ); }
//--------------------------------------------------------- bool CShapes_Cut_Interactive::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode) { switch( Mode ) { //----------------------------------------------------- case MODULE_INTERACTIVE_LDOWN: if( m_bDown == false ) { m_bDown = true; m_pDown = ptWorld; } return( true ); //----------------------------------------------------- case MODULE_INTERACTIVE_LUP: if( m_bDown == true ) { m_bDown = false; CSG_Rect r(m_pDown, ptWorld); if( Get_Extent(r) ) { if( Cut_Set_Extent(r, m_pExtent, true) ) { DataObject_Update(m_pExtent); } if( Cut_Shapes(r, m_Method, m_pShapes, m_pCut) ) { DataObject_Update(m_pCut); } else { Message_Add(_TL("No shapes in selection")); } } } return( true ); } return( true ); }
//--------------------------------------------------------- bool CGrid_Colors_Fit::On_Execute(void) { int iColor; long aC, bC; double aZ, bZ, dColor, zMin, zRange; CSG_Colors Colors_Old, Colors_New; CSG_Grid *pGrid; pGrid = Parameters("GRID")->asGrid(); Colors_New.Set_Count(Parameters("COUNT")->asInt()); switch( Parameters("SCALE")->asInt() ) { case 0: default: zMin = pGrid->Get_ZMin(); zRange = pGrid->Get_ZMax() - zMin; break; case 1: zMin = Parameters("RANGE")->asRange()->Get_LoVal(); zRange = Parameters("RANGE")->asRange()->Get_HiVal() - zMin; break; } DataObject_Get_Colors(pGrid, Colors_Old); if( Colors_Old.Get_Count() > 1 && pGrid->Get_ZRange() > 0.0 && zRange != 0.0 ) { dColor = 100.0 / Colors_Old.Get_Count(); aZ = 0.0; aC = Colors_Old.Get_Color(0); for(iColor=1; iColor<Colors_Old.Get_Count()-1; iColor++) { bZ = aZ; bC = aC; aZ = (pGrid->Get_Percentile(iColor * dColor) - zMin) / zRange; aC = Colors_Old.Get_Color(iColor); _Set_Colors(Colors_New, bZ, bC, aZ, aC); } bZ = aZ; bC = aC; aZ = 1.0; aC = Colors_Old.Get_Color(Colors_Old.Get_Count() - 1); _Set_Colors(Colors_New, bZ, bC, aZ, aC); DataObject_Set_Colors (pGrid, Colors_New); DataObject_Update (pGrid, zMin, zMin + zRange); return( true ); } return( false ); }
//--------------------------------------------------------- bool CAddCoordinates::On_Execute(void) { CSG_Shapes *pShapes = Parameters("OUTPUT")->asShapes(); if( pShapes ) { pShapes->Assign(Parameters("INPUT")->asShapes()); } else { pShapes = Parameters("INPUT")->asShapes(); } //----------------------------------------------------- int xField = pShapes->Get_Field_Count(); pShapes->Add_Field("X", SG_DATATYPE_Double); int yField = pShapes->Get_Field_Count(); pShapes->Add_Field("Y", SG_DATATYPE_Double); int zField = 0, mField = 0; if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { zField = pShapes->Get_Field_Count(); pShapes->Add_Field("Z", SG_DATATYPE_Double); if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { mField = pShapes->Get_Field_Count(); pShapes->Add_Field("M", SG_DATATYPE_Double); } } //----------------------------------------------------- for(int i=0; i<pShapes->Get_Count(); i++) { CSG_Shape *pShape = pShapes->Get_Shape(i); pShape->Set_Value(xField, pShape->Get_Point(0).x); pShape->Set_Value(yField, pShape->Get_Point(0).y); if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { pShape->Set_Value(zField, pShape->Get_Z(0)); if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { pShape->Set_Value(mField, pShape->Get_M(0)); } } } DataObject_Update(pShapes); return( true ); }
//--------------------------------------------------------- bool CPolygon_Geometrics::On_Execute(void) { //------------------------------------------------- int bParts = Parameters("BPARTS") ->asBool() ? 0 : -1; int bPoints = Parameters("BPOINTS") ->asBool() ? 0 : -1; int bLength = Parameters("BLENGTH") ->asBool() ? 0 : -1; int bArea = Parameters("BAREA") ->asBool() ? 0 : -1; if( bParts && bPoints && bLength && bArea ) { Error_Set(_TL("no properties selected")); return( false ); } //------------------------------------------------- CSG_Shapes *pPolygons = Parameters("POLYGONS")->asShapes(); if( !pPolygons->is_Valid() || pPolygons->Get_Count() <= 0 ) { Error_Set(_TL("invalid lines layer")); return( false ); } if( Parameters("OUTPUT")->asShapes() && Parameters("OUTPUT")->asShapes() != pPolygons ) { pPolygons = Parameters("OUTPUT")->asShapes(); pPolygons->Create(*Parameters("POLYGONS")->asShapes()); } //------------------------------------------------- if( !bParts ) { bParts = pPolygons->Get_Field_Count(); pPolygons->Add_Field(SG_T("NPARTS") , SG_DATATYPE_Int ); } if( !bPoints ) { bPoints = pPolygons->Get_Field_Count(); pPolygons->Add_Field(SG_T("NPOINTS") , SG_DATATYPE_Int ); } if( !bLength ) { bLength = pPolygons->Get_Field_Count(); pPolygons->Add_Field(SG_T("PERIMETER"), SG_DATATYPE_Double); } if( !bArea ) { bArea = pPolygons->Get_Field_Count(); pPolygons->Add_Field(SG_T("AREA") , SG_DATATYPE_Double); } //------------------------------------------------- for(int i=0; i<pPolygons->Get_Count() && Set_Progress(i, pPolygons->Get_Count()); i++) { CSG_Shape *pPolygon = pPolygons->Get_Shape(i); if( bParts >= 0 ) pPolygon->Set_Value(bParts , pPolygon->Get_Part_Count()); if( bPoints >= 0 ) pPolygon->Set_Value(bPoints, pPolygon->Get_Point_Count()); if( bLength >= 0 ) pPolygon->Set_Value(bLength, ((CSG_Shape_Polygon *)pPolygon)->Get_Perimeter()); if( bArea >= 0 ) pPolygon->Set_Value(bArea , ((CSG_Shape_Polygon *)pPolygon)->Get_Area()); } //------------------------------------------------- if( pPolygons == Parameters("POLYGONS")->asShapes() ) { DataObject_Update(pPolygons); } return( true ); }
//--------------------------------------------------------- bool CSelectByTheme::On_Execute(void) { bool *WasSelected; int i, iMethod, iCondition; CSG_Shapes *pShapes, *pShapes2; pShapes = Parameters("SHAPES") ->asShapes(); pShapes2 = Parameters("SHAPES2") ->asShapes(); iCondition = Parameters("CONDITION") ->asInt(); iMethod = Parameters("METHOD") ->asInt(); //----------------------------------------------------- if( iMethod == METHOD_SELECT_FROM_SEL ) { WasSelected = new bool[pShapes->Get_Count()]; for(i=0; i<pShapes->Get_Count() && Set_Progress(i, pShapes->Get_Count()); i++) { WasSelected[i] = pShapes->Get_Record(i)->is_Selected(); } } if( iMethod != METHOD_ADD_TO_SEL ) { pShapes->Select(); } //----------------------------------------------------- if( Select(pShapes, pShapes2, iCondition, false) ) { for(i=0; i<m_Selection.size() && Set_Progress(i, m_Selection.size()); i++) { int iSelection = m_Selection[i]; if( !pShapes->Get_Record(iSelection)->is_Selected() ) { if( iMethod != METHOD_SELECT_FROM_SEL || WasSelected[iSelection] ) { ((CSG_Table *)pShapes)->Select(iSelection, true); } } } } //----------------------------------------------------- if( iMethod == METHOD_SELECT_FROM_SEL ) { delete(WasSelected); } Message_Add(CSG_String::Format(SG_T("%s: %d"), _TL("selected shapes"), m_Selection.size())); DataObject_Update(pShapes); return( true ); }
bool CSinuosity::On_Execute(void){ m_pDEM = Parameters("DEM")->asGrid(); m_pSinuosity = Parameters("SINUOS")->asGrid(); DataObject_Update(m_pSinuosity, true); return true; }//method
//--------------------------------------------------------- bool CFlow_AreaUpslope_Interactive::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode) { if( Mode == MODULE_INTERACTIVE_LDOWN && m_Calculator.Get_Area(Get_xGrid(), Get_yGrid()) ) { DataObject_Update(Parameters("AREA")->asGrid(), 0.0, 100.0, true); return( true ); } return( false ); }
//--------------------------------------------------------- bool CGrid_Profile::Set_Profile(void) { int i; TSG_Point A, B; CSG_Shape *pLine; //----------------------------------------------------- m_pPoints->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name())); m_pPoints->Add_Field("ID" , SG_DATATYPE_Int); m_pPoints->Add_Field(_TL("Distance") , SG_DATATYPE_Double); m_pPoints->Add_Field(_TL("Distance Overland") , SG_DATATYPE_Double); m_pPoints->Add_Field("X" , SG_DATATYPE_Double); m_pPoints->Add_Field("Y" , SG_DATATYPE_Double); m_pPoints->Add_Field("Z" , SG_DATATYPE_Double); for(i=0; i<m_pValues->Get_Count(); i++) { m_pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double); } //----------------------------------------------------- if( (pLine = m_pLine->Get_Shape(0)) != NULL && pLine->Get_Point_Count(0) > 1 ) { B = pLine->Get_Point(0); for(i=1; i<pLine->Get_Point_Count(0); i++) { A = B; B = pLine->Get_Point(i); Set_Profile(A, B); } } //----------------------------------------------------- DataObject_Update(m_pLine); DataObject_Update(m_pPoints); return( m_pPoints->Get_Count() > 0 ); }
//--------------------------------------------------------- bool CLine_Properties::On_Execute(void) { //------------------------------------------------- int bParts = Parameters("BPARTS") ->asBool() ? 0 : -1; int bPoints = Parameters("BPOINTS") ->asBool() ? 0 : -1; int bLength = Parameters("BLENGTH") ->asBool() ? 0 : -1; if( bParts && bPoints && bLength ) { Error_Set(_TL("no properties selected")); return( false ); } //------------------------------------------------- CSG_Shapes *pLines = Parameters("LINES")->asShapes(); if( !pLines->is_Valid() || pLines->Get_Count() <= 0 ) { Error_Set(_TL("invalid lines layer")); return( false ); } if( Parameters("OUTPUT")->asShapes() && Parameters("OUTPUT")->asShapes() != pLines ) { pLines = Parameters("OUTPUT")->asShapes(); pLines->Create(*Parameters("LINES")->asShapes()); } //------------------------------------------------- if( !bParts ) { bParts = pLines->Get_Field_Count(); pLines->Add_Field(SG_T("NPARTS") , SG_DATATYPE_Int ); } if( !bPoints ) { bPoints = pLines->Get_Field_Count(); pLines->Add_Field(SG_T("NPOINTS"), SG_DATATYPE_Int ); } if( !bLength ) { bLength = pLines->Get_Field_Count(); pLines->Add_Field(SG_T("LENGTH") , SG_DATATYPE_Double); } //------------------------------------------------- for(int i=0; i<pLines->Get_Count() && Set_Progress(i, pLines->Get_Count()); i++) { CSG_Shape *pLine = pLines->Get_Shape(i); if( bParts >= 0 ) pLine->Set_Value(bParts , pLine->Get_Part_Count()); if( bPoints >= 0 ) pLine->Set_Value(bPoints, pLine->Get_Point_Count()); if( bLength >= 0 ) pLine->Set_Value(bLength, ((CSG_Shape_Line *)pLine)->Get_Length()); } //------------------------------------------------- if( pLines == Parameters("LINES")->asShapes() ) { DataObject_Update(pLines); } return( true ); }
//--------------------------------------------------------- bool CSelection_Invert::On_Execute(void) { CSG_Shapes *pInput; pInput = Parameters("INPUT") ->asShapes(); pInput->Inv_Selection(); DataObject_Update(pInput); return( true ); }
//--------------------------------------------------------- bool CKinWav_D8::Initialize(double Roughness) { m_Flow_Last .Create(*Get_System(), SG_DATATYPE_Float); m_Alpha .Create(*Get_System(), SG_DATATYPE_Float); m_Direction .Create(*Get_System(), SG_DATATYPE_Char); m_Direction .Set_NoData_Value(-1); m_pFlow->Assign(0.0); DataObject_Set_Colors(m_pFlow, 100, SG_COLORS_WHITE_BLUE); DataObject_Update(m_pFlow, 0.0, 100.0, SG_UI_DATAOBJECT_SHOW); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( !m_pDEM->is_NoData(x, y) ) { int i, ix, iy, iMax; double z, d, dMax; for(i=0, iMax=-1, dMax=0.0, z=m_pDEM->asDouble(x, y); i<8; i++) { ix = Get_xTo(i, x); iy = Get_yTo(i, y); if( is_InGrid(ix, iy) && (d = (z - m_pDEM->asDouble(ix, iy)) / Get_Length(i)) > dMax ) { dMax = d; iMax = i; } } if( iMax < 0 ) { m_Direction .Set_NoData(x, y); } else { m_Direction .Set_Value(x, y, iMax); m_Alpha .Set_Value(x, y, pow(Roughness / sqrt(dMax), Beta_0)); if( m_Alpha.asDouble(x, y) > 10 ) m_Alpha.Set_Value(x, y, 10); } } } } return( true ); }
//--------------------------------------------------------- bool CLandsat_Import::On_Execute(void) { CSG_Strings Files; if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) || Files.Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- CSG_Parameter_Grid_List *pBands = Parameters("BANDS")->asGridList(); pBands->Del_Items(); for(int i=0; i<Files.Get_Count(); i++) { Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("loading"), SG_File_Get_Name(Files[i], false).c_str())); CSG_Grid *pBand = Get_Band(Files[i]); if( pBand ) { pBands->Add_Item(pBand); DataObject_Add(pBand); DataObject_Set_Colors(pBand, 11, SG_COLORS_BLACK_WHITE); } } //----------------------------------------------------- if( Parameters("SHOW_RGB")->is_Enabled() && Parameters("SHOW_RGB")->asBool() ) { CSG_Grid *pR = pBands->asGrid(Parameters("SHOW_R")->asInt()); CSG_Grid *pG = pBands->asGrid(Parameters("SHOW_G")->asInt()); CSG_Grid *pB = pBands->asGrid(Parameters("SHOW_B")->asInt()); if( pR && pG && pB ) { DataObject_Set_Parameter(pR, "COLORS_TYPE" , 5); // _TL("RGB Overlay") // CLASSIFY_OVERLAY DataObject_Set_Parameter(pR, "OVERLAY_MODE", 0); // _TL("red=this, green=1, blue=2") DataObject_Set_Parameter(pR, "OVERLAY_G" , pG); DataObject_Set_Parameter(pR, "OVERLAY_B" , pB); DataObject_Update(pR, true); } } //----------------------------------------------------- return( true ); }
void CMine_Sweeper::Show_GameBoard(bool ShowMines) { int x,y; if (ShowMines) { for( y = 0; y < Mine_NY; y++) for( x = 0; x < Mine_NX; x++) { if(GameBoard->asInt(x, y) & isBomb) { if (FlagBoard->asInt(x,y) == FLAG) SetSprite(x,y,SPRITE_FLAG); else SetSprite(x,y,SPRITE_BOMB); } else { if (GameBoard->asInt(x, y) == isOpen ) SetSprite(x,y,SPRITE_NUMMER(Get_Number_of_Bombs(x,y))); else SetSprite(x,y,SPRITE_CLOSE); } if (GameBoard->asInt(x, y) & isBumm) SetSprite(x,y,SPRITE_BOMB_BUMM); if ( !(GameBoard->asInt(x, y) & isBomb) && (FlagBoard->asInt(x,y) == FLAG)) SetSprite(x,y,SPRITE_BOMB_NO); } } else for( y = 0; y < Mine_NY; y++) for( x = 0; x < Mine_NX; x++) { if(GameBoard->asInt(x, y) == isOpen) { SetSprite(x,y,SPRITE_NUMMER(Get_Number_of_Bombs(x,y))); } else { if(FlagBoard->asInt(x,y)) SetSprite(x,y,FlagBoard->asInt(x,y)); else SetSprite(x,y,SPRITE_CLOSE); } } DataObject_Update(pInput, 0.0, 15.0); }
//--------------------------------------------------------- bool CGrid_Flow_Profile::On_Execute(void) { m_pDEM = Parameters("DEM" )->asGrid(); m_pValues = Parameters("VALUES")->asGridList(); m_pPoints = Parameters("POINTS")->asShapes(); m_pLines = Parameters("LINE" )->asShapes(); //----------------------------------------------------- m_pPoints->Create(SHAPE_TYPE_Point, CSG_String::Format("%s [%s]", m_pDEM->Get_Name(), _TL("Profile"))); m_pPoints->Add_Field("ID" , SG_DATATYPE_Int); m_pPoints->Add_Field(_TL("Distance"), SG_DATATYPE_Double); m_pPoints->Add_Field(_TL("Overland"), SG_DATATYPE_Double); m_pPoints->Add_Field("X" , SG_DATATYPE_Double); m_pPoints->Add_Field("Y" , SG_DATATYPE_Double); m_pPoints->Add_Field("Z" , SG_DATATYPE_Double); for(int i=0; i<m_pValues->Get_Count(); i++) { m_pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double); } //----------------------------------------------------- m_pLines->Create(SHAPE_TYPE_Line, CSG_String::Format("%s [%s]", m_pDEM->Get_Name(), _TL("Profile"))); m_pLines->Add_Field("ID" , SG_DATATYPE_Int); m_pLine = m_pLines->Add_Shape(); m_pLine->Set_Value(0, 1); //----------------------------------------------------- DataObject_Update(m_pDEM , SG_UI_DATAOBJECT_SHOW_NEW_MAP ); DataObject_Update(m_pLines, SG_UI_DATAOBJECT_SHOW_LAST_MAP); Set_Drag_Mode(TOOL_INTERACTIVE_DRAG_NONE); return( true ); }