//--------------------------------------------------------- bool C_Kriging_Base::_Get_Grid(void) { CSG_Shapes *pShapes = Parameters("SHAPES")->asShapes(); m_pGrid = NULL; m_pVariance = NULL; //------------------------------------------------- switch( Parameters("TARGET")->asInt() ) { case 0: // user defined... if( Dlg_Parameters("USER") ) { m_pGrid = _Get_Grid(pShapes->Get_Extent()); } break; case 1: // grid system... if( Dlg_Parameters("SYSTEM") ) { m_pGrid = SG_Create_Grid(*Get_Parameters("SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System(), SG_DATATYPE_Float); } break; case 2: // grid... if( Dlg_Parameters("GRID") ) { m_pGrid = Get_Parameters("GRID")->Get_Parameter("GRID") ->asGrid(); m_pVariance = Get_Parameters("GRID")->Get_Parameter("VARIANCE") ->asGrid(); } break; } //------------------------------------------------- if( m_pGrid ) { if( !m_pVariance && Parameters("BVARIANCE")->asBool() ) { m_pVariance = SG_Create_Grid(m_pGrid, SG_DATATYPE_Float); } m_pGrid->Set_Name(CSG_String::Format(SG_T("%s (%s)"), pShapes->Get_Name(), Get_Name())); Parameters("GRID")->Set_Value(m_pGrid); if( m_pVariance ) { m_pVariance->Set_Name(CSG_String::Format(SG_T("%s (%s - %s)"), pShapes->Get_Name(), Get_Name(), _TL("Variance"))); Parameters("VARIANCE")->Set_Value(m_pVariance); } if( Parameters("TARGET")->asInt() == 2 ) { Get_Parameters("GRID")->Get_Parameter("VARIANCE")->Set_Value(m_pVariance); } } //----------------------------------------------------- return( m_pGrid != NULL ); }
//--------------------------------------------------------- bool CGrid_3D_Image::On_Execute(void) { //----------------------------------------------------- m_pDEM = Parameters("DEM" )->asGrid(); m_pImage = Parameters("IMAGE" )->asGrid(); m_Projection = Parameters("PROJECTION" )->asInt(); m_ZExagg = Parameters("ZEXAGG" )->asDouble(); m_ZExagg_Min = Parameters("ZEXAGG_MIN" )->asDouble() / 100.0; m_ZMean = Parameters("X_ROTATE_LEVEL")->asInt() == 0 ? 0.0 : m_pDEM->Get_Min() + m_pDEM->Get_Range() / 2.0; m_XRotate = Parameters("X_ROTATE" )->asDouble() * M_DEG_TO_RAD; m_ZRotate = Parameters("Z_ROTATE" )->asDouble() * M_DEG_TO_RAD; m_PanoramaBreak = Parameters("PANBREAK" )->asDouble() / 100.0; //----------------------------------------------------- m_pRGB = Parameters("RGB" )->asGrid(); m_pRGB_Z = Parameters("RGB_Z")->asGrid(); if( !m_pRGB ) { int nx, ny; nx = Parameters("NX")->asInt(); ny = Parameters("NY")->asInt(); m_pRGB = SG_Create_Grid(SG_DATATYPE_Int , nx, ny, 1.0); } if( !m_pRGB_Z || !m_pRGB_Z->is_Compatible(m_pRGB->Get_System()) ) { m_pRGB_Z = SG_Create_Grid(m_pRGB, SG_DATATYPE_Float); } m_pRGB ->Set_Name(_TL("3D Image")); m_pRGB ->Assign(Parameters("BKCOLOR")->asDouble()); m_pRGB_Z ->Set_Name(_TL("3D Image Height")); m_pRGB_Z ->Set_NoData_Value_Range(-999999, -999999); m_pRGB_Z ->Assign_NoData(); //----------------------------------------------------- m_XScale = (double)m_pRGB->Get_NX() / (double)Get_NX(); m_YScale = (double)m_pRGB->Get_NY() / (double)Get_NY(); //----------------------------------------------------- _Set_Grid(); CSG_Parameter_Shapes_List *pShapes = Parameters("SHAPES")->asShapesList(); for(int i=0; i<pShapes->Get_Item_Count(); i++) { _Set_Shapes(pShapes->Get_Shapes(i)); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- void CPit_Eliminator::Create_goRoute(void) { int x, y; goRoute = SG_Create_Grid(pRoute); for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { if( !is_InGrid(x,y) ) { goRoute->Set_NoData(x, y); } else if( pRoute->asChar(x, y) > 0 ) { goRoute->Set_Value(x, y, pRoute->asChar(x, y) % 8 ); } else { goRoute->Set_Value(x, y, pDTM->Get_Gradient_NeighborDir(x, y)); } } } }
//--------------------------------------------------------- bool CExercise_10::On_Execute(void) { bool bAlive; int x, y, i; CSG_Colors Colors; //----------------------------------------------------- // General initialisations... m_pLife = Parameters("RESULT")->asGrid(); m_nColors = Parameters("COLORS")->asInt(); Colors.Set_Count(m_nColors + 1); Colors.Set_Ramp(SG_GET_RGB(127, 127, 127), SG_GET_RGB(0, 0, 0)); Colors.Set_Color(0, SG_GET_RGB(255, 255, 255)); DataObject_Set_Colors(m_pLife, Colors); //----------------------------------------------------- // Initialise life's world... if( Parameters("REFRESH")->asBool() ) { srand((unsigned)time(NULL)); for(y=0; y<Get_NY(); y++) { for(x=0; x<Get_NX(); x++) { m_pLife->Set_Value(x, y, rand() > RAND_MAX / 2 ? 0 : 1); } } } //----------------------------------------------------- // Execution... m_pTemp = SG_Create_Grid(m_pLife, SG_DATATYPE_Byte); for(i=1, bAlive=true; bAlive && Process_Get_Okay(true); i++) { Process_Set_Text(CSG_String::Format(SG_T("%d %s"), i, _TL("Life Cycle"))); if( (bAlive = Next_Step()) == false ) { Message_Add(CSG_String::Format(SG_T("%s %d %s\n"), _TL("Dead after"), i, _TL("Life Cycles"))); } } delete(m_pTemp); //----------------------------------------------------- // Finish... return( true ); }
//--------------------------------------------------------- bool CMandelbrot::On_Execute(void) { //----------------------------------------------------- m_Extent.Assign( Parameters("XRANGE")->asRange()->Get_LoVal(), Parameters("YRANGE")->asRange()->Get_LoVal(), Parameters("XRANGE")->asRange()->Get_HiVal(), Parameters("YRANGE")->asRange()->Get_HiVal() ); m_maxIterations = Parameters("MAXITER") ->asInt(); m_maxDistance = 4.0; m_Method = Parameters("METHOD") ->asInt(); m_xJulia = Parameters("JULIA_X") ->asDouble(); m_yJulia = Parameters("JULIA_Y") ->asDouble(); m_pGrid = SG_Create_Grid(SG_DATATYPE_Int, Parameters("NX")->asInt(), Parameters("NY")->asInt()); m_pGrid->Set_Name(m_Method == 0 ? _TL("Mandelbrot Set") : _TL("Julia Set")); Parameters("GRID")->Set_Value(m_pGrid); //----------------------------------------------------- Calculate(); //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- void CGrid_Import::Set_Transformation(CSG_Grid **ppImage, double ax, double ay, double dx, double dy, double rx, double ry) { int x, y; double z; TSG_Rect r; CSG_Vector A(2), XSrc(2), XTgt(2); CSG_Matrix D(2, 2), DInv; CSG_Grid *pSource, *pTarget; //----------------------------------------------------- pSource = *ppImage; A[0] = ax; A[1] = ay; D[0][0] = dx; D[0][1] = rx; D[1][0] = ry; D[1][1] = dy; DInv = D.Get_Inverse(); //----------------------------------------------------- XSrc[0] = pSource->Get_XMin(); XSrc[1] = pSource->Get_YMin(); XTgt = D * XSrc + A; r.xMin = r.xMax = XTgt[0]; r.yMin = r.yMax = XTgt[1]; XSrc[0] = pSource->Get_XMin(); XSrc[1] = pSource->Get_YMax(); XTgt = D * XSrc + A; if( r.xMin > XTgt[0] ) r.xMin = XTgt[0]; else if( r.xMax < XTgt[0] ) r.xMax = XTgt[0]; if( r.yMin > XTgt[1] ) r.yMin = XTgt[1]; else if( r.yMax < XTgt[1] ) r.yMax = XTgt[1]; XSrc[0] = pSource->Get_XMax(); XSrc[1] = pSource->Get_YMax(); XTgt = D * XSrc + A; if( r.xMin > XTgt[0] ) r.xMin = XTgt[0]; else if( r.xMax < XTgt[0] ) r.xMax = XTgt[0]; if( r.yMin > XTgt[1] ) r.yMin = XTgt[1]; else if( r.yMax < XTgt[1] ) r.yMax = XTgt[1]; XSrc[0] = pSource->Get_XMax(); XSrc[1] = pSource->Get_YMin(); XTgt = D * XSrc + A; if( r.xMin > XTgt[0] ) r.xMin = XTgt[0]; else if( r.xMax < XTgt[0] ) r.xMax = XTgt[0]; if( r.yMin > XTgt[1] ) r.yMin = XTgt[1]; else if( r.yMax < XTgt[1] ) r.yMax = XTgt[1]; z = fabs(dx) < fabs(dy) ? fabs(dx) : fabs(dy); // guess a suitable cellsize; could be improved... x = 1 + (int)((r.xMax - r.xMin) / z); y = 1 + (int)((r.yMax - r.yMin) / z); //----------------------------------------------------- pTarget = *ppImage = SG_Create_Grid(pSource->Get_Type(), x, y, z, r.xMin, r.yMin); for(y=0, XTgt[1]=pTarget->Get_YMin(); y<pTarget->Get_NY() && Set_Progress(y, pTarget->Get_NY()); y++, XTgt[1]+=pTarget->Get_Cellsize()) { for(x=0, XTgt[0]=pTarget->Get_XMin(); x<pTarget->Get_NX(); x++, XTgt[0]+=pTarget->Get_Cellsize()) { XSrc = DInv * (XTgt - A); if( pSource->Get_Value(XSrc[0], XSrc[1], z, GRID_INTERPOLATION_NearestNeighbour, false, true) ) { pTarget->Set_Value(x, y, z); } else { pTarget->Set_NoData(x, y); } } } delete(pSource); }
//--------------------------------------------------------- bool CSG_Grid_Pyramid::_Get_Next_Level(CSG_Grid *pGrid) { if( (m_nMaxLevels <= 0 || m_nLevels < m_nMaxLevels) ) { int nx, ny; double Cellsize; switch( m_Grow_Type ) { case GRID_PYRAMID_Arithmetic: Cellsize = pGrid->Get_Cellsize() + m_Grow; break; case GRID_PYRAMID_Geometric: Cellsize = pGrid->Get_Cellsize() * m_Grow; break; default: Cellsize = pGrid->Get_Cellsize() * m_Grow; break; } nx = (int)(1.5 + m_pGrid->Get_XRange() / Cellsize); if( nx < 1 ) nx = 1; ny = (int)(1.5 + m_pGrid->Get_YRange() / Cellsize); if( ny < 1 ) ny = 1; if( nx > 1 || ny > 1 ) { CSG_Grid *pNext = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, Cellsize, pGrid->Get_XMin(), pGrid->Get_YMin()); pNext->Set_NoData_Value(pGrid->Get_NoData_Value()); pNext->Assign(pGrid); m_pLevels = (CSG_Grid **)SG_Realloc(m_pLevels, (m_nLevels + 1) * sizeof(CSG_Grid *)); m_pLevels[m_nLevels++] = pNext; _Get_Next_Level(pNext); return( true ); } } return( false ); }
//--------------------------------------------------------- bool CSG_Grid_Pyramid::_Get_Next_Level(CSG_Grid *pGrid, double Cellsize) { if( (m_nMaxLevels <= 0 || m_nLevels < m_nMaxLevels) ) { int nx, ny; nx = (int)(1.5 + m_pGrid->Get_XRange() / Cellsize); if( nx < 1 ) nx = 1; ny = (int)(1.5 + m_pGrid->Get_YRange() / Cellsize); if( ny < 1 ) ny = 1; if( nx > 1 || ny > 1 ) { CSG_Grid *pNext = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, Cellsize, pGrid->Get_XMin(), pGrid->Get_YMin()); pNext->Set_NoData_Value(pGrid->Get_NoData_Value()); pNext->Assign(pGrid); m_pLevels = (CSG_Grid **)SG_Realloc(m_pLevels, (m_nLevels + 1) * sizeof(CSG_Grid *)); m_pLevels[m_nLevels++] = pNext; _Get_Next_Level(pNext); return( true ); } } return( false ); }
//--------------------------------------------------------- bool CWatershed_Segmentation::Get_Borders(void) { Process_Set_Text(_TL("Borders")); CSG_Grid *pBorders = SG_Create_Grid(SG_DATATYPE_Byte, Get_NX() + 2, Get_NY() + 2, Get_Cellsize(), Get_XMin() - 0.5 * Get_Cellsize(), Get_YMin() - 0.5 * Get_Cellsize()); pBorders->Set_NoData_Value(0); Parameters("BORDERS")->Set_Value(pBorders); for(int y=0, yy=1; yy<Get_NY() && Set_Progress(yy); y++, yy++) { for(int x=0, xx=1; xx<Get_NX(); x++, xx++) { int id = m_pSegments->asInt(x, y); if( id != m_pSegments->asInt(xx, y) ) { pBorders->Set_Value(xx, y, 1); } if( id != m_pSegments->asInt( x, yy) ) { pBorders->Set_Value( x, yy, 1); } if( id != m_pSegments->asInt(xx, yy) ) { pBorders->Set_Value(xx, yy, 1); } } } return( true ); }
//--------------------------------------------------------- bool CGrid_Geometric_Figures::On_Execute(void) { int NXY; double DXY; CSG_Grid *pGrid; //----------------------------------------------------- NXY = Parameters("CELL_COUNT") ->asInt(); DXY = Parameters("CELL_SIZE") ->asDouble(); Parameters("RESULT")->asGridList()->Add_Item( pGrid = SG_Create_Grid(SG_DATATYPE_Float, NXY, NXY, DXY) ); //----------------------------------------------------- switch( Parameters("FIGURE")->asInt() ) { case 0: default: Create_Cone (pGrid, true); break; case 1: Create_Cone (pGrid, false); break; case 2: Create_Plane (pGrid, Parameters("PLANE")->asDouble()); break; } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGaussian_Landscapes::On_Execute(void) { int nx, ny, n; double h, s, r; //----------------------------------------------------- nx = Parameters("NX")->asInt(); ny = Parameters("NY")->asInt(); m_pGrid = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, 1.0, 0.0, 0.0); m_pGrid->Set_Name(_TL("Gaussian Landscape")); m_pGrid->Assign_NoData(); Parameters("GRID")->Set_Value(m_pGrid); m_Method = Parameters("METHOD") ->asInt(); m_M = Parameters("M") ->asDouble(); //----------------------------------------------------- nx = nx > ny ? nx : ny; ny = 1; do { n = (int)pow(2.0, ny++); } while( n < nx ); h = Parameters("H") ->asDouble(); r = 1.0 / pow(2.0, h); s = n * r; //----------------------------------------------------- Set_Values(0, 0, n, n, 0.0, 0.0, 0.0, 0.0, s, r); //----------------------------------------------------- return( true ); }
bool CFilterClumps::On_Execute(void){ int x,y; int iArea; m_pInputGrid = Parameters("GRID")->asGrid(); m_pOutputGrid = Parameters("OUTPUT")->asGrid(); m_pMaskGrid = SG_Create_Grid(m_pInputGrid); m_pMaskGridB = SG_Create_Grid(m_pInputGrid); int iThreshold = Parameters("THRESHOLD")->asInt(); m_CentralPoints .Clear(); m_AdjPoints .Clear(); m_pMaskGrid->Assign((double)0); m_pMaskGridB->Assign(1); for (x = 1; x < Get_NX()-1; x++){ for (y = 1; y < Get_NY()-1; y++){ if (!m_pInputGrid->is_NoData(x,y) && m_pMaskGrid->asInt(x,y) == 0){ m_CentralPoints.Clear(); m_CentralPoints.Add(x,y); m_pMaskGrid->Set_Value(x,y,1); iArea = CalculateCellBlockArea(); if (iArea < iThreshold){ m_CentralPoints.Clear(); m_CentralPoints.Add(x,y); m_pMaskGridB->Set_NoData(x,y); EliminateClump(); }//if }//if }//for }//for for (x = 0; x < Get_NX(); x++){ for (y = 0; y < Get_NY(); y++){ if (m_pMaskGridB->is_NoData(x,y)){ m_pOutputGrid->Set_NoData(x,y); }//if else{ m_pOutputGrid->Set_Value(x,y,m_pInputGrid->asDouble(x,y)); }//else }//for }//for return true; }//method
bool CGrid_Aggregate::On_Execute(void) { int x,y; int x2,y2; int i,j; int iNX, iNY; int iSize = Parameters("SIZE")->asInt(); int iMethod = Parameters("METHOD")->asInt(); double dMin,dMax; double dSum; double dValue; iNX = (int) (Get_NX() / iSize); iNY = (int) (Get_NY() / iSize); CSG_Grid *pGrid = Parameters("INPUT")->asGrid(); CSG_Grid *pOutput = SG_Create_Grid(pGrid->Get_Type(), iNX, iNY, pGrid->Get_Cellsize() * iSize, pGrid->Get_XMin(), pGrid->Get_YMin()); pOutput->Set_Name(pGrid->Get_Name()); for (y = 0, y2 = 0; y2 < iNY; y+=iSize, y2++){ for (x = 0, x2 = 0; x2 < iNX; x+=iSize, x2++){ dMax = dMin = pGrid->asDouble(x,y); dSum = 0; for (i = 0; i < iSize; i++){ for (j = 0; j < iSize; j++){ dValue = pGrid->asDouble(x+i,y+j); if (dValue > dMax){ dMax = dValue; }//if if (dValue < dMin){ dMin = dValue; }//if dSum += dValue; }//for }//for switch (iMethod){ case SUM: pOutput->Set_Value(x2,y2,dSum); break; case MIN: pOutput->Set_Value(x2,y2,dMin); break; case MAX: pOutput->Set_Value(x2,y2,dMax); break; default: break; } }//for }//for DataObject_Add(pOutput); return true; }
//--------------------------------------------------------- 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 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 CErosion_LS_Fields::On_Execute(void) { //----------------------------------------------------- m_Method = Parameters("METHOD" )->asInt(); m_Method_Slope = Parameters("METHOD_SLOPE" )->asInt(); m_Method_Area = Parameters("METHOD_AREA" )->asInt(); m_bStopAtEdge = Parameters("STOP_AT_EDGE" )->asBool(); m_Erosivity = Parameters("EROSIVITY" )->asDouble(); m_Stability = Parameters("STABILITY" )->asInt(); m_pDEM = Parameters("DEM" )->asGrid(); m_pUp_Area = Parameters("UPSLOPE_AREA" )->asGrid(); m_pUp_Length = Parameters("UPSLOPE_LENGTH")->asGrid(); m_pUp_Slope = Parameters("UPSLOPE_SLOPE" )->asGrid(); m_pLS = Parameters("LS_FACTOR" )->asGrid(); DataObject_Set_Colors(m_pUp_Area , 11, SG_COLORS_WHITE_BLUE , false); DataObject_Set_Colors(m_pUp_Length, 11, SG_COLORS_YELLOW_RED , false); DataObject_Set_Colors(m_pUp_Slope , 11, SG_COLORS_YELLOW_RED , false); DataObject_Set_Colors(m_pLS , 11, SG_COLORS_RED_GREY_GREEN, true ); if( m_pUp_Area == NULL ) m_pUp_Area = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float); if( m_pUp_Length == NULL ) m_pUp_Length = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float); if( m_pUp_Slope == NULL ) m_pUp_Slope = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float); //----------------------------------------------------- bool bResult = Set_Fields() && Get_Flow() && Get_LS(); if( bResult ) { Get_Statistics(); Get_Balance(); } //----------------------------------------------------- if( m_pUp_Area && Parameters("UPSLOPE_AREA" )->asGrid() == NULL ) delete(m_pUp_Area ); if( m_pUp_Length && Parameters("UPSLOPE_LENGTH")->asGrid() == NULL ) delete(m_pUp_Length); if( m_pUp_Slope && Parameters("UPSLOPE_SLOPE" )->asGrid() == NULL ) delete(m_pUp_Slope ); m_Fields.Destroy(); return( bResult ); }
//--------------------------------------------------------- bool CFilter_LoG::On_Execute(void) { CSG_Grid *pResult; //----------------------------------------------------- m_pInput = Parameters("INPUT") ->asGrid(); pResult = Parameters("RESULT") ->asGrid(); //----------------------------------------------------- if( Initialise() ) { if( !pResult || pResult == m_pInput ) { pResult = SG_Create_Grid(m_pInput); } else { pResult->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pInput->Get_Name(), _TL("Laplace Filter"))); pResult->Set_NoData_Value(m_pInput->Get_NoData_Value()); } //------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( m_pInput->is_InGrid(x, y) ) { pResult->Set_Value(x, y, Get_Value(x, y)); } else { pResult->Set_NoData(x, y); } } } //------------------------------------------------- if( !Parameters("RESULT")->asGrid() || Parameters("RESULT")->asGrid() == m_pInput ) { m_pInput->Assign(pResult); delete(pResult); pResult = m_pInput; } DataObject_Set_Colors(pResult, 100, SG_COLORS_BLACK_WHITE); m_Kernel.Destroy(); return( true ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool CSRTM30_Import::On_Execute(void) { char x_sTile[9][5] = { "W180", "W140", "W100", "W060", "W020", "E020", "E060", "E100", "E140" }, y_sTile[3][4] = { "S10", "N40", "N90" }; double dSize = 30.0 / (60.0 * 60.0); //----------------------------------------------------- int xTile, yTile; double xMin, xMax, yMin, yMax; TSG_Rect rOut, rTile; CSG_String sTile; CSG_Grid *pOut; //----------------------------------------------------- xMin = Parameters("XMIN")->asInt(); xMax = Parameters("XMAX")->asInt(); yMin = Parameters("YMIN")->asInt(); yMax = Parameters("YMAX")->asInt(); rOut.xMin = (180 + xMin) / 40.0 * X_WIDTH; rOut.xMax = rOut.xMin + (int)((xMax - xMin) / dSize); rOut.yMin = ( 60 + yMin) / 50.0 * Y_WIDTH; rOut.yMax = rOut.yMin + (int)((yMax - yMin) / dSize); //----------------------------------------------------- pOut = SG_Create_Grid(SG_DATATYPE_Short, (int)(rOut.xMax - rOut.xMin), (int)(rOut.yMax - rOut.yMin), dSize, xMin + 0.5 * dSize, yMin + 0.5 * dSize ); pOut->Set_NoData_Value(-9999); pOut->Assign_NoData(); pOut->Set_Name(SG_T("SRTM30")); pOut->Get_Projection().Create(SG_T("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]")); //----------------------------------------------------- for(yTile=0, rTile.yMin=0, rTile.yMax=Y_WIDTH; yTile<3; yTile++, rTile.yMin+=Y_WIDTH, rTile.yMax+=Y_WIDTH) { for(xTile=0, rTile.xMin=0, rTile.xMax=X_WIDTH; xTile<9; xTile++, rTile.xMin+=X_WIDTH, rTile.xMax+=X_WIDTH) { sTile.Printf(SG_T("Tile: %s%s"), x_sTile[xTile], y_sTile[yTile]); Process_Set_Text(sTile); sTile.Printf(SG_T("%s%s%s.dem"), Parameters("PATH")->asString(), x_sTile[xTile], y_sTile[yTile]); Tile_Load(sTile, rTile, pOut, rOut); } } //----------------------------------------------------- Parameters("GRID")->Set_Value(pOut); return( true ); }
//--------------------------------------------------------- bool CImport_Clip_Resample::Load_Grid(CSG_Grid *pImport) { CSG_Grid_System System = pImport->Get_System(); //----------------------------------------------------- const CSG_Rect *pClip = Parameters("CLIP")->asShapes() ? &Parameters("CLIP")->asShapes()->Get_Extent() : NULL; if( pClip ) { if( !pClip->Intersects(System.Get_Extent()) ) { return( false ); } TSG_Rect Extent = System.Get_Extent(); if( pClip->Get_XMin() > System.Get_XMin() ) Extent.xMin = System.Fit_xto_Grid_System(pClip->Get_XMin()); if( pClip->Get_XMax() < System.Get_XMax() ) Extent.xMax = System.Fit_xto_Grid_System(pClip->Get_XMax()); if( pClip->Get_YMin() > System.Get_YMin() ) Extent.yMin = System.Fit_yto_Grid_System(pClip->Get_YMin()); if( pClip->Get_YMax() < System.Get_YMax() ) Extent.yMax = System.Fit_yto_Grid_System(pClip->Get_YMax()); System.Assign(System.Get_Cellsize(), Extent); } //----------------------------------------------------- if( Parameters("RESAMPLE")->asBool() ) { double Cellsize = Parameters("CELLSIZE")->asDouble(); if( Cellsize > 0.0 && Cellsize != System.Get_Cellsize() ) { System.Assign(Cellsize, System.Get_Extent()); } } //----------------------------------------------------- if( Parameters("NODATA")->asBool() ) { pImport->Set_NoData_Value(Parameters("NODATA_VAL")->asDouble()); } //----------------------------------------------------- CSG_Grid *pGrid = SG_Create_Grid(System, Parameters("KEEP_TYPE")->asBool() ? pImport->Get_Type() : SG_DATATYPE_Float); if( pGrid ) { pGrid->Assign (pImport); pGrid->Set_Name(pImport->Get_Name()); m_pGrids->Add_Item(pGrid); return( true ); } return( false ); }
//--------------------------------------------------------- bool CPROJ4_Grid::Init_XY(const CSG_Grid_System &System, CSG_Grid **ppX, CSG_Grid **ppY) { if( Parameters("CREATE_XY")->asBool() ) { Parameters("OUT_X")->Set_Value(*ppX = SG_Create_Grid(System, SG_DATATYPE_Float)); (*ppX)->Assign_NoData(); (*ppX)->Set_Name(_TL("X-Coordinate")); Parameters("OUT_Y")->Set_Value(*ppY = SG_Create_Grid(System, SG_DATATYPE_Float)); (*ppY)->Assign_NoData(); (*ppY)->Set_Name(_TL("Y-Coordinate")); return( true ); } *ppX = *ppY = NULL; return( false ); }
bool CFlowDepth::On_Execute(void){ m_pDEM = Parameters("DEM") ->asGrid(); m_pFlowDepth = Parameters("FLOWDEPTH") ->asGrid(); m_dThreshold = Parameters("THRESHOLD") ->asDouble(); m_dFlow = Parameters("FLOW") ->asDouble(); m_pCatchArea = SG_Create_Grid(m_pDEM, SG_DATATYPE_Float); m_pBasinGrid = SG_Create_Grid(m_pDEM, SG_DATATYPE_Int); m_pSlope = SG_Create_Grid(m_pDEM, SG_DATATYPE_Float); m_pAspect = SG_Create_Grid(m_pDEM, SG_DATATYPE_Float); m_pFlowDepth->Set_NoData_Value(0.); Process_Set_Text(_TL("Calculating Catchment Area...")); CalculateFlowAccGrid(m_pCatchArea, m_pDEM); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { double slope, aspect; if( m_pDEM->Get_Gradient(x, y, slope, aspect) ) { m_pSlope ->Set_Value(x, y, slope); m_pAspect ->Set_Value(x, y, aspect); } else { m_pSlope ->Set_NoData(x, y); m_pAspect ->Set_NoData(x, y); } } } //----------------------------------------------------- DataObject_Update(m_pFlowDepth, true); return true; }//method
void g_Add_Grid (CSG_Grid *pGrid) { if( g_pInterpreter ) { CSG_Grid *p = SG_Create_Grid(*pGrid); p->Set_Name(pGrid->Get_Name()); g_pInterpreter->Get_Parameters()->Get_Parameter("OUTPUT")->asGridList()->Add_Item(p); } }
//--------------------------------------------------------- bool CFlow_Distance::On_Execute(void) { bool bSeeds; int x, y, Method; CSG_Grid *pSeed; //------------------------------------------------- m_pDTM = Parameters("ELEVATION") ->asGrid(); pSeed = Parameters("SEED") ->asGrid(); m_pLength = Parameters("LENGTH") ->asGrid(); m_Converge = Parameters("CONVERGENCE") ->asDouble(); bSeeds = Parameters("SEEDS_ONLY") ->asBool(); Method = Parameters("METHOD") ->asInt(); m_pWeight = SG_Create_Grid(m_pLength, SG_DATATYPE_Float); m_pWeight ->Assign(0.0); m_pLength ->Assign(0.0); //------------------------------------------------- for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++) { m_pDTM->Get_Sorted(n, x, y, true, false); if( pSeed && !pSeed->is_NoData(x, y) ) { m_pLength->Set_Value(x, y, 0.0); m_pWeight->Set_Value(x, y, 0.0); } else if( m_pWeight->asDouble(x, y) > 0.0 ) { m_pLength->Set_Value(x, y, m_pLength->asDouble(x, y) / m_pWeight->asDouble(x, y)); } else if( bSeeds ) { m_pLength->Set_NoData(x, y); continue; } switch( Method ) { case 0: Set_Length_D8 (x, y); break; case 1: Set_Length_MFD (x, y); break; } } //------------------------------------------------- delete(m_pWeight); DataObject_Set_Colors(m_pLength, 100, SG_COLORS_WHITE_BLUE); return( true ); }
//--------------------------------------------------------- bool CGrid_Histogram_Surface::Get_Lines(bool bRows) { int i, j, n_i, n_j; CSG_Table Values; CSG_Grid *pHist; //----------------------------------------------------- Parameters("HIST")->Set_Value(pHist = SG_Create_Grid(m_pGrid)); pHist->Set_NoData_Value_Range( m_pGrid->Get_NoData_Value(), m_pGrid->Get_NoData_hiValue() ); n_i = bRows ? Get_NX() : Get_NY(); n_j = bRows ? Get_NY() : Get_NX(); Values.Add_Field(SG_T("Z"), SG_DATATYPE_Double); for(i=0; i<n_i; i++) { Values.Add_Record(); } //----------------------------------------------------- for(j=0; j<n_j && Set_Progress(j, n_j); j++) { for(i=0; i<n_i; i++) { Values.Get_Record(i)->Set_Value(0, bRows ? m_pGrid->asDouble(i, j) : m_pGrid->asDouble(j, i)); } Values.Set_Index(0, TABLE_INDEX_Ascending); for(i=0; i<n_i; i++) { int k = i % 2 ? i / 2 : n_i - 1 - i / 2; if( bRows ) { pHist->Set_Value(k, j, Values.Get_Record_byIndex(i)->asDouble(0)); } else { pHist->Set_Value(j, k, Values.Get_Record_byIndex(i)->asDouble(0)); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- CSG_Grid * C_Kriging_Base::_Get_Grid(TSG_Rect Extent) { CSG_Parameters *P = Get_Parameters("USER"); if( !P->Get_Parameter("FIT_EXTENT")->asBool() ) { Extent.xMin = P->Get_Parameter("X_EXTENT")->asRange()->Get_LoVal(); Extent.yMin = P->Get_Parameter("Y_EXTENT")->asRange()->Get_LoVal(); Extent.xMax = P->Get_Parameter("X_EXTENT")->asRange()->Get_HiVal(); Extent.yMax = P->Get_Parameter("Y_EXTENT")->asRange()->Get_HiVal(); } double d = P->Get_Parameter("CELL_SIZE")->asDouble(); int nx = 1 + (int)((Extent.xMax - Extent.xMin) / d); int ny = 1 + (int)((Extent.yMax - Extent.yMin) / d); return( nx > 1 && ny > 1 ? SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, Extent.xMin, Extent.yMin) : NULL ); }
//--------------------------------------------------------- bool CGrid_Histogram_Surface::Get_Circle(void) { long i; int n; double r; CSG_Grid *pHist; r = sqrt(m_pGrid->Get_NCells() / M_PI); n = 1 + (int)(2.0 * r); //----------------------------------------------------- Parameters("HIST")->Set_Value(pHist = SG_Create_Grid(m_pGrid->Get_Type(), n, n, m_pGrid->Get_Cellsize(), -r * m_pGrid->Get_Cellsize(), -r * m_pGrid->Get_Cellsize())); pHist->Set_NoData_Value_Range( m_pGrid->Get_NoData_Value(), m_pGrid->Get_NoData_hiValue() ); //----------------------------------------------------- for(int y=0; y<n && Set_Progress(y, n); y++) { for(int x=0; x<n; x++) { double d = SG_Get_Distance(x, y, r, r); if( d < r && m_pGrid->Get_Sorted((long)(d*d*M_PI), i) ) { pHist->Set_Value(x, y, m_pGrid->asDouble(i)); } else { pHist->Set_NoData(x, y); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_Gaps::On_Execute(void) { bool bKillInput; //----------------------------------------------------- pInput = Parameters("INPUT") ->asGrid(); pMask = Parameters("MASK") ->asGrid(); if( Parameters("RESULT")->asGrid() == NULL || Parameters("RESULT")->asGrid() == pInput ) { pResult = pInput; Parameters("RESULT")->Set_Value(pResult); pInput = SG_Create_Grid(pInput); pInput->Assign(pResult); bKillInput = true; } else { pResult = Parameters("RESULT")->asGrid(); pResult->Get_History().Assign(pInput->Get_History()); bKillInput = false; } //----------------------------------------------------- Tension_Main(); //----------------------------------------------------- if( bKillInput ) { delete(pInput); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CPanSharp_CN::On_Execute(void) { //----------------------------------------------------- TSG_Grid_Resampling Resampling = Get_Resampling(Parameters("RESAMPLING")->asInt()); //----------------------------------------------------- int i; CSG_Grid *pPan = Parameters("PAN")->asGrid(); CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS" )->asGridList(); CSG_Parameter_Grid_List *pSharp = Parameters("SHARPEN")->asGridList(); //----------------------------------------------------- pSharp->Del_Items(); for(i=0; i<pGrids->Get_Grid_Count(); i++) { Process_Set_Text("%s: %s ...", _TL("Resampling"), pGrids->Get_Grid(i)->Get_Name()); CSG_Grid *pGrid = SG_Create_Grid(Get_System()); pGrid->Set_Name (pGrids->Get_Grid(i)->Get_Name()); pGrid->Assign (pGrids->Get_Grid(i), Resampling); pSharp->Add_Item(pGrid); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for private(i) for(int x=0; x<Get_NX(); x++) { double Sum = 0.0; if( !pPan->is_NoData(x, y) ) { for(i=0; i<pSharp->Get_Grid_Count(); i++) { if( !pSharp->Get_Grid(i)->is_NoData(x, y) ) { Sum += pSharp->Get_Grid(i)->asDouble(x, y); } else { Sum = 0.0; break; } } } if( Sum ) { Sum = pPan->asDouble(x, y) * pSharp->Get_Grid_Count() / (Sum + pSharp->Get_Grid_Count()); for(i=0; i<pSharp->Get_Grid_Count(); i++) { pSharp->Get_Grid(i)->Mul_Value(x, y, Sum); } } else { for(i=0; i<pSharp->Get_Grid_Count(); i++) { pSharp->Get_Grid(i)->Set_NoData(x, y); } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CChannelNetwork::On_Execute(void) { int x, y, ID, Trace_Method, Init_Method; long n; double Init_Threshold; CSG_Grid *Trace_pRoute, *Trace_pWeight, *Init_pGrid; //----------------------------------------------------- pDTM = Parameters("ELEVATION") ->asGrid(); pConvergence = Parameters("DIV_GRID") ->asGrid(); pChannels = Parameters("CHNLNTWRK") ->asGrid(); pChannelRoute = Parameters("CHNLROUTE") ->asGrid(); pShapes = Parameters("SHAPES") ->asShapes(); minLength = Parameters("MINLEN") ->asInt(); maxDivCells = Parameters("DIV_GRID")->asGrid() ? Parameters("DIV_CELLS")->asInt() : -1; //----------------------------------------------------- // 1. Flow Direction... Process_Set_Text(_TL("Channel Network: Pass 1")); pChannels->Assign(); Trace_pRoute = Parameters("SINKROUTE") ->asGrid(); Trace_pWeight = Parameters("TRACE_WEIGHT")->asGrid(); Trace_Method = Trace_pWeight ? 1 : 0; for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { if( Trace_pRoute && (ID = Trace_pRoute->asChar(x, y)) >= 1 && ID <= 8 ) { pChannels->Set_Value(x, y, ID); } else { switch( Trace_Method ) { default: Set_Route_Standard(x, y); break; case 1: Set_Route_Weighted(x, y, Trace_pWeight, 0.0); break; } } } } //----------------------------------------------------- // 2. Initiation... Process_Set_Text(_TL("Channel Network: Pass 2")); pStart = SG_Create_Grid(pDTM, SG_DATATYPE_Char); Init_pGrid = Parameters("INIT_GRID") ->asGrid(); Init_Method = Parameters("INIT_METHOD") ->asInt(); Init_Threshold = Parameters("INIT_VALUE") ->asDouble(); for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++) { switch( Init_Method ) { case 0: if( Init_pGrid->asDouble(n) <= Init_Threshold ) pStart->Set_Value(n, 1); break; case 1: if( Init_pGrid->asDouble(n) == Init_Threshold ) pStart->Set_Value(n, 1); break; case 2: if( Init_pGrid->asDouble(n) >= Init_Threshold ) pStart->Set_Value(n, 1); break; } } //----------------------------------------------------- // 3. Trace Channel Routes... Process_Set_Text(_TL("Channel Network: Pass 3")); pChannelRoute->Assign(); Direction = NULL; Direction_Buffer = 0; for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++) { if( pDTM->Get_Sorted(n,x,y) ) { Set_Channel_Route(x,y); } } if( Direction ) { SG_Free( Direction ); } pChannels->Assign(); delete(pStart); //----------------------------------------------------- Process_Set_Text(_TL("Channel Network: Pass 4")); for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Set_Channel_Order(x,y); } } //----------------------------------------------------- Process_Set_Text(_TL("Channel Network: Pass 5")); for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Set_Channel_Mouth(x,y); } } //----------------------------------------------------- if( pShapes ) { Process_Set_Text(_TL("Channel Network: Pass 6")); pShapes->Create(SHAPE_TYPE_Line, _TL("Channel Network")); pShapes->Add_Field("SegmentID" ,SG_DATATYPE_Int); pShapes->Add_Field("Order" ,SG_DATATYPE_Int); pShapes->Add_Field("Length" ,SG_DATATYPE_Double); Lock_Create(); for(y=0, ID=1; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Set_Vector(x, y, ID++); } } Lock_Destroy(); } //----------------------------------------------------- for(n=0; n<Get_NCells(); n++) { if( pChannels->asInt(n) == 0 ) { pChannels->Set_NoData(n); pChannelRoute->Set_NoData(n); } } //----------------------------------------------------- return( true ); }