//--------------------------------------------------------- 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_CVA::On_Execute(void){ double a1,a2,b1,b2; double dDist, dAngle; CSG_Grid* pA1 = Parameters("A1")->asGrid(); CSG_Grid* pA2 = Parameters("A2")->asGrid(); CSG_Grid* pB1 = Parameters("B1")->asGrid(); CSG_Grid* pB2 = Parameters("B2")->asGrid(); CSG_Grid* pDist = Parameters("DIST")->asGrid(); CSG_Grid* pAngle = Parameters("ANGLE")->asGrid(); pDist->Assign(0.0); pAngle->Assign(0.0); for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ a1 = pA1->asDouble(x,y); a2 = pA2->asDouble(x,y); b1 = pB1->asDouble(x,y); b2 = pB2->asDouble(x,y); dDist = sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)); dAngle = atan((a1-a2)/(b1-b2)); pDist->Set_Value(x,y,dDist); pAngle->Set_Value(x,y,dAngle); }// for }// for return true; }//method
//--------------------------------------------------------- bool CConvergence::On_Execute(void) { bool bGradient; int Neighbours; CSG_Grid *pConvergence; m_pDTM = Parameters("ELEVATION") ->asGrid(); pConvergence = Parameters("RESULT") ->asGrid(); Neighbours = Parameters("NEIGHBOURS") ->asInt(); bGradient = Parameters("METHOD") ->asInt() == 1; DataObject_Set_Colors(pConvergence, 100, SG_COLORS_RED_GREY_BLUE, true); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( m_pDTM->is_InGrid(x, y) ) { switch( Neighbours ) { case 0: default: pConvergence->Set_Value(x, y, Get_2x2(x, y, bGradient)); break; case 1: pConvergence->Set_Value(x, y, Get_9x9(x, y, bGradient)); break; } } else { pConvergence->Set_NoData(x, y); } } } return( true ); }
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 CFilter_Resample::On_Execute(void) { //----------------------------------------------------- CSG_Grid *pGrid = Parameters("GRID" )->asGrid(); CSG_Grid *pLoPass = Parameters("LOPASS")->asGrid(); CSG_Grid *pHiPass = Parameters("HIPASS")->asGrid(); double Cellsize = Parameters("SCALE" )->asDouble() * Get_Cellsize(); //----------------------------------------------------- if( Cellsize > 0.5 * SG_Get_Length(Get_System().Get_XRange(), Get_System().Get_YRange()) ) { Error_Set(_TL("resampling cell size is too large")); return( false ); } //----------------------------------------------------- CSG_Grid Grid(CSG_Grid_System(Cellsize, Get_XMin(), Get_YMin(), Get_XMax(), Get_YMax()), SG_DATATYPE_Float); Grid.Assign(pGrid, GRID_RESAMPLING_Mean_Cells); //----------------------------------------------------- pLoPass->Fmt_Name("%s [%s]", pGrid->Get_Name(), _TL("Low Pass" )); pHiPass->Fmt_Name("%s [%s]", pGrid->Get_Name(), _TL("High Pass")); CSG_Colors Colors; DataObject_Get_Colors(pGrid , Colors); DataObject_Set_Colors(pLoPass, Colors); DataObject_Set_Colors(pHiPass, 11, SG_COLORS_RED_GREY_BLUE); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { double py = Get_YMin() + y * Get_Cellsize(); #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double z, px = Get_XMin() + x * Get_Cellsize(); if( !pGrid->is_NoData(x, y) && Grid.Get_Value(px, py, z) ) { pLoPass->Set_Value(x, y, z); pHiPass->Set_Value(x, y, pGrid->asDouble(x, y) - z); } else { pLoPass->Set_NoData(x, y); pHiPass->Set_NoData(x, y); } } } //----------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CGrid_Division::On_Execute(void) { //----------------------------------------------------- CSG_Grid *pA = Parameters("A")->asGrid(); CSG_Grid *pB = Parameters("B")->asGrid(); CSG_Grid *pC = Parameters("C")->asGrid(); DataObject_Set_Colors(pC, 11, SG_COLORS_RED_GREY_BLUE); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( pA->is_NoData(x, y) || pB->is_NoData(x, y) || pB->asDouble(x, y) == 0.0 ) { pC->Set_NoData(x, y); } else { pC->Set_Value(x, y, pA->asDouble(x, y) / pB->asDouble(x, y)); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool Copy_RGBGrid_VIGRA_to_SAGA (CSG_Grid &Grid, BRGBImage &Image, bool bCreate) { if( bCreate ) { Grid.Create(Grid.Get_Type(), Image.width(), Image.height()); } if( Grid.Get_NX() != Image.width() || Grid.Get_NY() != Image.height() ) { return( false ); } for(int y=0; y<Grid.Get_NY() && SG_UI_Process_Set_Progress(y, Grid.Get_NY()); y++) { for(int x=0; x<Grid.Get_NX(); x++) { RGBValue<unsigned char> rgb = Image(x, y); Grid.Set_Value(x, y, SG_GET_RGB(rgb.red(), rgb.green(), rgb.blue())); } } SG_UI_Process_Set_Progress(0.0, 1.0); return( true ); }
//--------------------------------------------------------- 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 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 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 CGrids_Product::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS" )->asGridList(); if( pGrids->Get_Count() < 1 ) { Error_Set(_TL("no grid in list")); return( false ); } //----------------------------------------------------- CSG_Grid *pResult = Parameters("RESULT")->asGrid(); bool bNoData = Parameters("NODATA")->asBool(); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { int n = 0; double d = 0.0; for(int i=0; i<pGrids->Get_Count(); i++) { if( pGrids->asGrid(i)->is_InGrid(x, y) ) { if( n++ < 1 ) { d = pGrids->asGrid(i)->asDouble(x, y); } else { d *= pGrids->asGrid(i)->asDouble(x, y); } } } if( bNoData ? n > 0 : n == pGrids->Get_Count() ) { pResult->Set_Value(x, y, d); } else { pResult->Set_NoData(x, y); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_RGB_Split::On_Execute(void) { CSG_Grid *pRGB = Parameters("RGB")->asGrid(); if( SG_Data_Type_Get_Size(pRGB->Get_Type()) < 4 ) { Message_Add(_TL("warning, input uses less than 4 bytes per value")); } bool bNoData = Parameters("NODATA")->asBool(); CSG_Grid *pR = Parameters("R")->asGrid(); if( bNoData && pR ) pR->Set_NoData_Value(-1); CSG_Grid *pG = Parameters("G")->asGrid(); if( bNoData && pG ) pG->Set_NoData_Value(-1); CSG_Grid *pB = Parameters("B")->asGrid(); if( bNoData && pB ) pB->Set_NoData_Value(-1); CSG_Grid *pA = Parameters("A")->asGrid(); if( bNoData && pA ) pA->Set_NoData_Value(-1); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( bNoData || !pRGB->is_NoData(x, y) ) { int RGB = pRGB->asInt(x, y); if( pR ) pR->Set_Value(x, y, SG_GET_R(RGB)); if( pG ) pG->Set_Value(x, y, SG_GET_G(RGB)); if( pB ) pB->Set_Value(x, y, SG_GET_B(RGB)); if( pA ) pA->Set_Value(x, y, SG_GET_A(RGB)); } else { if( pR ) pR->Set_NoData(x, y); if( pG ) pG->Set_NoData(x, y); if( pB ) pB->Set_NoData(x, y); if( pA ) pA->Set_NoData(x, y); } } } return( true ); }
//--------------------------------------------------------- bool CGrid_Plotter::On_Execute(void) { //----------------------------------------------------- CSG_Formula Formula; if( !Formula.Set_Formula(Parameters("FORMULA")->asString()) ) { CSG_String Message; if( !Formula.Get_Error(Message) ) { Message = _TL("unknown errror parsing formula"); } Error_Set(Message); return( false ); } //----------------------------------------------------- CSG_Grid *pFunction = m_Grid_Target.Get_Grid("FUNCTION"); if( !pFunction ) { Error_Set(_TL("could not create target grid")); return( false ); } //----------------------------------------------------- double xMin = Parameters("X_RANGE")->asRange()->Get_LoVal(); double xRange = Parameters("X_RANGE")->asRange()->Get_HiVal() - xMin; double yMin = Parameters("Y_RANGE")->asRange()->Get_LoVal(); double yRange = Parameters("Y_RANGE")->asRange()->Get_HiVal() - yMin; //----------------------------------------------------- for(int y=0; y<pFunction->Get_NY() && Set_Progress(y); y++) { double py = yMin + yRange * (y / (double)pFunction->Get_NY()); #pragma omp parallel for for(int x=0; x<pFunction->Get_NX(); x++) { double px = xMin + xRange * (x / (double)pFunction->Get_NX()); pFunction->Set_Value(x, y, Formula.Get_Value(SG_T("xy"), px, py)); } } //----------------------------------------------------- return( true ); }
bool CGrid_Pattern::On_Execute(void){ m_pInput = Parameters("INPUT")->asGrid(); CSG_Grid *pRelative = Parameters("RELATIVE")->asGrid(); CSG_Grid *pDominance = Parameters("DOMINANCE")->asGrid(); CSG_Grid *pDiversity = Parameters("DIVERSITY")->asGrid(); CSG_Grid *pFragmentation = Parameters("FRAGMENTATION")->asGrid(); CSG_Grid *pNDC = Parameters("NDC")->asGrid(); CSG_Grid *pCVN = Parameters("CVN")->asGrid(); m_iWinSize = Parameters("WINSIZE")->asInt()*2+3; m_iNumClasses = Parameters("MAXNUMCLASS")->asInt(); for(int y=m_iWinSize-2; y<Get_NY()-m_iWinSize+2 && Set_Progress(y); y++){ for(int x=m_iWinSize-2; x<Get_NX()-m_iWinSize+2; x++){ double dDiversity = getDiversity(x,y); int iNumClasses = getNumberOfClasses(x,y); pRelative->Set_Value(x,y,((double)iNumClasses)/((double)m_iNumClasses)*100.0); pDominance->Set_Value(x,y,log((double)iNumClasses)-dDiversity); pDiversity->Set_Value(x,y,dDiversity); pFragmentation->Set_Value(x,y,((double)(iNumClasses-1))/((double)(m_iWinSize*m_iWinSize-1))); pNDC->Set_Value(x,y,iNumClasses); pCVN->Set_Value(x,y,getCVN(x,y)); }// for }// for return true; }//method
bool CInvertNoData::On_Execute(void){ int x,y; CSG_Grid* pInput = Parameters("INPUT")->asGrid(); CSG_Grid* pOutput = Parameters("OUTPUT")->asGrid(); pOutput->Set_NoData_Value_Range(-9999,0); for(y=0; y<Get_NY() && Set_Progress(y); y++){ for(x=0; x<Get_NX(); x++){ if (pInput->is_NoData(x,y)){ pOutput->Set_Value(x, y, 1.0); }//if else{ pOutput->Set_Value(x, y, -9999.0); }//else }//if }//for return true; }//method
//--------------------------------------------------------- bool CGrid_Normalise::On_Execute(void) { CSG_Grid *pGrid = Parameters("INPUT")->asGrid(); if( pGrid->Get_StdDev() <= 0.0 ) { return( false ); } if( pGrid != Parameters("OUTPUT")->asGrid() ) { pGrid = Parameters("OUTPUT")->asGrid(); pGrid ->Assign(Parameters("INPUT")->asGrid()); } pGrid->Fmt_Name("%s (%s)", pGrid->Get_Name(), _TL("Normalized")); //----------------------------------------------------- double Minimum, Maximum, Offset, Scale; Minimum = Parameters("RANGE")->asRange()->Get_Min(); Maximum = Parameters("RANGE")->asRange()->Get_Max(); Offset = pGrid->Get_Min(); Scale = (Maximum - Minimum) / pGrid->Get_Range(); for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++) { for(int x=0; x<Get_NX(); x++) { if( !pGrid->is_NoData(x, y) ) { pGrid->Set_Value(x, y, Minimum + Scale * (pGrid->asDouble(x, y) - Offset)); } } } //----------------------------------------------------- if( pGrid == Parameters("INPUT")->asGrid() ) { DataObject_Update(pGrid); } return( true ); }
//--------------------------------------------------------- bool CGWR_Grid_Downscaling::Set_Model(void) { CSG_Grid *pRegression = Parameters("REGRESSION" )->asGrid(); CSG_Grid *pReg_ResCorr = Parameters("REG_RESCORR")->asGrid(); pRegression->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pDependent->Get_Name(), _TL("GWR"))); if( pReg_ResCorr ) { pReg_ResCorr->Set_Name(CSG_String::Format(SG_T("%s [%s, %s]"), m_pDependent->Get_Name(), _TL("GWR"), _TL("Residual Correction"))); } for(int y=0; y<Get_NY() && Set_Progress(y); y++) { double p_y = Get_YMin() + y * Get_Cellsize(); #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double Value, Residual, p_x = Get_XMin() + x * Get_Cellsize(); if( Set_Model(p_x, p_y, Value, Residual) ) { pRegression->Set_Value(x, y, Value); if( pReg_ResCorr ) { pReg_ResCorr->Set_Value(x, y, Value + Residual); } } else { pRegression->Set_NoData(x, y); if( pReg_ResCorr ) { pReg_ResCorr->Set_NoData(x, y); } } } } return( true ); }
bool CImage_VI_Slope::On_Execute(void){ double dRed, dNIR; CSG_Grid* pNIR = Parameters("NIR")->asGrid(); CSG_Grid* pRed = Parameters("RED")->asGrid(); CSG_Grid* pNDVI = Parameters("NDVI")->asGrid(); CSG_Grid* pRatio = Parameters("RATIO")->asGrid(); CSG_Grid* pTVI = Parameters("TVI")->asGrid(); CSG_Grid* pTTVI = Parameters("TTVI")->asGrid(); CSG_Grid* pCTVI = Parameters("CTVI")->asGrid(); CSG_Grid* pNRatio = Parameters("NRATIO")->asGrid(); for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ dNIR = pNIR->asDouble(x,y); dRed = pRed->asDouble(x,y); pNDVI->Set_Value(x,y,getNDVI(dRed, dNIR)); if (pRatio){ if (dRed!=0){ pRatio->Set_Value(x,y,getRatio(dRed,dNIR)); }//if else{ pRatio->Set_Value(x,y,pRatio->Get_NoData_Value()); }//else }//if if (pTVI){ pTVI->Set_Value(x,y,getTVI(dRed,dNIR,pTVI)); }//if if (pCTVI){ pCTVI->Set_Value(x,y,getCTVI(dRed,dNIR)); }//if if (pTTVI){ pTTVI->Set_Value(x,y,getTTVI(dRed,dNIR)); }//if if (pNRatio){ pNRatio->Set_Value(x,y,getNRatio(dRed,dNIR)); }//if }// for }// for return true; }//method
//--------------------------------------------------------- bool CGrid_Standardise::On_Execute(void) { CSG_Grid *pGrid = Parameters("INPUT")->asGrid(); if( pGrid->Get_StdDev() <= 0.0 ) { return( false ); } if( pGrid != Parameters("OUTPUT")->asGrid() ) { pGrid = Parameters("OUTPUT")->asGrid(); pGrid ->Assign(Parameters("INPUT")->asGrid()); } pGrid->Fmt_Name("%s (%s)", pGrid->Get_Name(), _TL("Standard Score")); //----------------------------------------------------- double Mean = pGrid->Get_Mean(); double Stretch = Parameters("STRETCH")->asDouble() / pGrid->Get_StdDev(); for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( !pGrid->is_NoData(x, y) ) { pGrid->Set_Value(x, y, Stretch * (pGrid->asDouble(x, y) - Mean)); } } } //----------------------------------------------------- if( pGrid == Parameters("INPUT")->asGrid() ) { DataObject_Update(pGrid); } return( true ); }
//--------------------------------------------------------- bool CTC_Classification::Get_Classes(void) { //----------------------------------------------------- int Level, nLevels = 1 + Parameters("TYPE")->asInt(); CSG_Grid *pLandforms = Parameters("LANDFORMS")->asGrid(); pLandforms->Assign(0.0); pLandforms->Set_NoData_Value(CLASS_FLAG_NODATA); Set_LUT(pLandforms, nLevels); //----------------------------------------------------- for(Level=1; Level<=nLevels && Process_Get_Okay(); Level++) { Process_Set_Text(CSG_String::Format("%s: %d", _TL("Level"), Level)); m_Mean_Slope = Level == 1 ? m_pSlope ->Get_Mean() : m_Stat_Slope .Get_Mean(); m_Mean_Convexity = Level == 1 ? m_pConvexity->Get_Mean() : m_Stat_Convexity.Get_Mean(); m_Mean_Texture = Level == 1 ? m_pTexture ->Get_Mean() : m_Stat_Texture .Get_Mean(); m_Stat_Slope .Invalidate(); m_Stat_Convexity.Invalidate(); m_Stat_Texture .Invalidate(); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( pLandforms->asInt(x, y) == 0 ) { pLandforms->Set_Value(x, y, Get_Class(Level, x, y, Level == nLevels)); } } } } //----------------------------------------------------- return( true ); }
bool CCombineGrids::On_Execute(void){ int x,y; int i; int iCellValue1, iCellValue2; int iTableValue1, iTableValue2; int iResultValue; CSG_Grid *pGrid1 = Parameters("GRID1")->asGrid(); CSG_Grid *pGrid2 = Parameters("GRID2")->asGrid(); CSG_Grid *pResult = Parameters("RESULT")->asGrid(); ; CSG_Table *pLookup; CSG_Table_Record *pRecord; pLookup = Parameters("LOOKUP")->asTable(); for(y=0; y<Get_NY() && Set_Progress(y); y++){ for(x=0; x<Get_NX(); x++){ iCellValue1 = pGrid1->asInt(x,y); iCellValue2 = pGrid2->asInt(x,y); for (i = 0; i < pLookup->Get_Record_Count(); i++){ pRecord = pLookup->Get_Record(i); iTableValue1 = pRecord->asInt(0); iTableValue2 = pRecord->asInt(1); if (iTableValue1 == iCellValue1){ if (iTableValue2 == iCellValue2){ iResultValue = pRecord->asInt(2); pResult->Set_Value(x,y,iResultValue); break; }//if }//if }//for if (i >= pLookup->Get_Record_Count()){ pResult->Set_NoData(x,y); }//if }//for }//for return true; }//method
//--------------------------------------------------------- bool CGrid_Invert::On_Execute(void) { CSG_Grid *pGrid = Parameters("INVERSE")->asGrid(); if( pGrid == NULL ) { pGrid = Parameters("GRID")->asGrid(); } else if( pGrid != Parameters("GRID")->asGrid() ) { pGrid->Create(*Parameters("GRID")->asGrid()); pGrid->Fmt_Name("%s [%s]", pGrid->Get_Name(), _TL("Inverse")); } //----------------------------------------------------- double zMin = pGrid->Get_Min(); double zMax = pGrid->Get_Max(); for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( !pGrid->is_NoData(x, y) ) { pGrid->Set_Value(x, y, zMax - (pGrid->asDouble(x, y) - zMin)); } } } //----------------------------------------------------- if( pGrid == Parameters("GRID")->asGrid() ) { DataObject_Update(pGrid); } return( true ); }
//--------------------------------------------------------- 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 CRealArea::On_Execute(void) { CSG_Grid *pDEM = Parameters("DEM" )->asGrid(); CSG_Grid *pArea = Parameters("AREA")->asGrid(); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { double s, a; if( pDEM->Get_Gradient(x, y, s, a) ) { pArea->Set_Value(x, y, Get_System()->Get_Cellarea() / cos(s)); } else { pArea->Set_NoData(x,y); } } } return( true ); }
//--------------------------------------------------------- bool CDecision_Tree::On_Execute(void) { CSG_Grid *pClasses; //----------------------------------------------------- pClasses = Parameters("CLASSES") ->asGrid(); pClasses ->Set_NoData_Value(-1); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { pClasses->Set_Value(x, y, Get_Class(Parameters("ROOT")->asParameters(), Get_System()->Get_Grid_to_World(x, y))); } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pClasses, P) && P("COLORS_TYPE") && P("LUT") ) { CSG_Table *pTable = P("LUT")->asTable(); pTable->Del_Records(); Get_Class(Parameters("ROOT")->asParameters(), pTable); P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pClasses, P); } //----------------------------------------------------- return( true ); }
bool CProtectionIndex::On_Execute(void){ int x,y; double dProtectionIndex; CSG_Grid* pProtectionIndex = Parameters("PROTECTION")->asGrid(); m_dRadius = Parameters("RADIUS")->asDouble(); m_pDEM = Parameters("DEM")->asGrid(); for(y=0; y<Get_NY() && Set_Progress(y); y++){ for(x=0; x<Get_NX(); x++){ dProtectionIndex = getProtectionIndex(x,y); if (dProtectionIndex == NO_DATA){ pProtectionIndex->Set_NoData(x,y); }//if else{ pProtectionIndex->Set_Value(x,y, dProtectionIndex); }//else }//for }//for return true; }//method
//--------------------------------------------------------- bool CPanSharp_IHS::On_Execute(void) { //----------------------------------------------------- TSG_Grid_Resampling Resampling = Get_Resampling(Parameters("RESAMPLING")->asInt()); //----------------------------------------------------- int y; CSG_Grid *pPan = Parameters("PAN")->asGrid(); //----------------------------------------------------- Process_Set_Text("%s: %s ...", _TL("Resampling"), Parameters("R")->asGrid()->Get_Name()); CSG_Grid *pR = Parameters("R_SHARP")->asGrid(); pR->Assign (Parameters("R")->asGrid(), Resampling); pR->Set_Name(Parameters("R")->asGrid()->Get_Name()); Process_Set_Text("%s: %s ...", _TL("Resampling"), Parameters("G")->asGrid()->Get_Name()); CSG_Grid *pG = Parameters("G_SHARP")->asGrid(); pG->Assign (Parameters("G")->asGrid(), Resampling); pG->Set_Name(Parameters("G")->asGrid()->Get_Name()); Process_Set_Text("%s: %s ...", _TL("Resampling"), Parameters("B")->asGrid()->Get_Name()); CSG_Grid *pB = Parameters("B_SHARP")->asGrid(); pB->Assign (Parameters("B")->asGrid(), Resampling); pB->Set_Name(Parameters("B")->asGrid()->Get_Name()); //----------------------------------------------------- Process_Set_Text(_TL("RGB to IHS")); double rMin = pR->Get_Min(), rRange = pR->Get_Range(); double gMin = pG->Get_Min(), gRange = pG->Get_Range(); double bMin = pB->Get_Min(), bRange = pB->Get_Range(); for(y=0; y<pPan->Get_NY() && Set_Progress(y, pPan->Get_NY()); y++) { #pragma omp parallel for for(int x=0; x<pPan->Get_NX(); x++) { bool bNoData = true; if( pPan->is_NoData(x, y) || pR->is_NoData(x, y) || pG->is_NoData(x, y) || pB->is_NoData(x, y) ) { pR->Set_NoData(x, y); pG->Set_NoData(x, y); pB->Set_NoData(x, y); } else { double r = (pR->asDouble(x, y) - rMin) / rRange; if( r < 0.0 ) r = 0.0; else if( r > 1.0 ) r = 1.0; double g = (pG->asDouble(x, y) - gMin) / gRange; if( g < 0.0 ) g = 0.0; else if( g > 1.0 ) g = 1.0; double b = (pB->asDouble(x, y) - bMin) / bRange; if( b < 0.0 ) b = 0.0; else if( b > 1.0 ) b = 1.0; double h, s, i = r + g + b; if( i <= 0.0 ) { h = 0.0; s = 0.0; } else { if( r == g && g == b ) { h = 0.0; } else if( b < r && b < g ) { h = (g - b) / (i - 3 * b) ; } else if( r < g && r < b ) { h = (b - r) / (i - 3 * r) + 1; } else { h = (r - g) / (i - 3 * g) + 2; } if ( 0.0 <= h && h < 1.0 ) { s = (i - 3 * b) / i; } else if( 1.0 <= h && h < 2.0 ) { s = (i - 3 * r) / i; } else { s = (i - 3 * g) / i; } } pR->Set_Value(x, y, i); pG->Set_Value(x, y, s); pB->Set_Value(x, y, h); } } } //----------------------------------------------------- double Offset_Pan, Offset, Scale; if( Parameters("PAN_MATCH")->asInt() == 0 ) { Offset_Pan = pPan->Get_Min(); Offset = pR->Get_Min(); Scale = pR->Get_Range() / pPan->Get_Range(); } else { Offset_Pan = pPan->Get_Mean(); Offset = pR->Get_Mean(); Scale = pR->Get_StdDev() / pPan->Get_StdDev(); } //----------------------------------------------------- Process_Set_Text(_TL("IHS to RGB")); for(y=0; y<pPan->Get_NY() && Set_Progress(y, pPan->Get_NY()); y++) { #pragma omp parallel for for(int x=0; x<pPan->Get_NX(); x++) { if( !pR->is_NoData(x, y) ) { double i = Offset + Scale * (pPan->asDouble(x, y) - Offset_Pan); double s = pG ->asDouble(x, y); double h = pB ->asDouble(x, y); double r, g, b; if ( 0.0 <= h && h < 1.0 ) { r = i * (1 + 2 * s - 3 * s * h) / 3; g = i * (1 - s + 3 * s * h) / 3; b = i * (1 - s ) / 3; } else if( 1.0 <= h && h < 2.0 ) { r = i * (1 - s ) / 3; g = i * (1 + 2 * s - 3 * s * (h - 1)) / 3; b = i * (1 - s + 3 * s * (h - 1)) / 3; } else { r = i * (1 - s + 3 * s * (h - 2)) / 3; g = i * (1 - s ) / 3; b = i * (1 + 2 * s - 3 * s * (h - 2)) / 3; } pR->Set_Value(x, y, rMin + r * rRange); pG->Set_Value(x, y, gMin + g * gRange); pB->Set_Value(x, y, bMin + b * bRange); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_Value_Type::On_Execute(void) { //----------------------------------------------------- CSG_Grid *pOutput = Parameters("OUTPUT")->asGrid(); CSG_Grid *pInput = Parameters("INPUT" )->asGrid(), Input; if( pOutput == NULL || pOutput == pInput ) { Input.Create(*pInput); pOutput = pInput; pInput = &Input; } //----------------------------------------------------- double Offset = Parameters("OFFSET")->asDouble(); double Scale = Parameters("SCALE" )->asDouble(); if( Scale == 0.0 ) { Error_Set(_TL("scale factor must not equal zero")); return( false ); } //----------------------------------------------------- switch( Parameters("TYPE")->asInt() ) { default: Error_Set(_TL("undefined data type")); return( false ); case 0: pOutput->Create(*Get_System(), SG_DATATYPE_Bit ); break; case 1: pOutput->Create(*Get_System(), SG_DATATYPE_Byte ); break; case 2: pOutput->Create(*Get_System(), SG_DATATYPE_Char ); break; case 3: pOutput->Create(*Get_System(), SG_DATATYPE_Word ); break; case 4: pOutput->Create(*Get_System(), SG_DATATYPE_Short ); break; case 5: pOutput->Create(*Get_System(), SG_DATATYPE_DWord ); break; case 6: pOutput->Create(*Get_System(), SG_DATATYPE_Int ); break; case 7: pOutput->Create(*Get_System(), SG_DATATYPE_Float ); break; case 8: pOutput->Create(*Get_System(), SG_DATATYPE_Double); break; } pOutput->Set_Name (pInput->Get_Name ()); pOutput->Set_Description(pInput->Get_Description()); pOutput->Set_Unit (pInput->Get_Unit ()); pOutput->Set_Scaling (Scale, Offset); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( pInput->is_NoData(x, y) ) { pOutput->Set_NoData(x, y); } else { pOutput->Set_Value(x, y, pInput->asDouble(x, y)); } } } //----------------------------------------------------- if( pOutput == Parameters("INPUT")->asGrid() ) { DataObject_Update(pOutput); } return( true ); }
//--------------------------------------------------------- bool CGrid_RGB_Composite::On_Execute(void) { double rMin, rRange, gMin, gRange, bMin, bRange, aMin, aRange; //----------------------------------------------------- CSG_Grid *pR = _Get_Grid(Parameters("R_GRID")->asGrid(), Parameters("R_METHOD")->asInt(), Parameters("R_RANGE")->asRange(), Parameters("R_PERCTL")->asRange(), Parameters("R_STDDEV")->asDouble(), rMin, rRange); CSG_Grid *pG = _Get_Grid(Parameters("G_GRID")->asGrid(), Parameters("G_METHOD")->asInt(), Parameters("G_RANGE")->asRange(), Parameters("G_PERCTL")->asRange(), Parameters("G_STDDEV")->asDouble(), gMin, gRange); CSG_Grid *pB = _Get_Grid(Parameters("B_GRID")->asGrid(), Parameters("B_METHOD")->asInt(), Parameters("B_RANGE")->asRange(), Parameters("B_PERCTL")->asRange(), Parameters("B_STDDEV")->asDouble(), bMin, bRange); CSG_Grid *pA = _Get_Grid(Parameters("A_GRID")->asGrid(), Parameters("A_METHOD")->asInt(), Parameters("A_RANGE")->asRange(), Parameters("A_PERCTL")->asRange(), Parameters("A_STDDEV")->asDouble(), aMin, aRange); //----------------------------------------------------- CSG_Grid *pRGB = Parameters("RGB")->asGrid(); pRGB->Create(pRGB->Get_System(), SG_DATATYPE_Int); pRGB->Set_Name(_TL("Composite")); CSG_String s; s += CSG_String(_TL("Red" )) + ": " + pR->Get_Name() + "\n"; s += CSG_String(_TL("Green")) + ": " + pG->Get_Name() + "\n"; s += CSG_String(_TL("Blue" )) + ": " + pB->Get_Name() + "\n"; if( pA ) { s += CSG_String(_TL("Alpha")) + ": " + pA->Get_Name() + "\n"; } pRGB->Set_Description(s); DataObject_Set_Colors (pRGB, 100, SG_COLORS_BLACK_WHITE); DataObject_Set_Parameter(pRGB, "COLORS_TYPE", 5); // Color Classification Type: RGB Coded Values //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( pR->is_NoData(x, y) || pG->is_NoData(x, y) || pB->is_NoData(x, y) || (pA && pA->is_NoData(x, y)) ) { pRGB->Set_NoData(x, y); } else { int r = (int)(rRange * (pR->asDouble(x, y) - rMin)); if( r > 255 ) r = 255; else if( r < 0 ) r = 0; int g = (int)(gRange * (pG->asDouble(x, y) - gMin)); if( g > 255 ) g = 255; else if( g < 0 ) g = 0; int b = (int)(bRange * (pB->asDouble(x, y) - bMin)); if( b > 255 ) b = 255; else if( b < 0 ) b = 0; if( pA ) { int a = (int)(aRange * (pA->asDouble(x, y) - aMin)); if( a > 255 ) a = 255; else if( a < 0 ) a = 0; pRGB->Set_Value(x, y, SG_GET_RGBA(r, g, b, a)); } else { pRGB->Set_Value(x, y, SG_GET_RGB (r, g, b)); } } } } return( true ); }