//--------------------------------------------------------- bool CPanSharp_Brovey::On_Execute(void) { //----------------------------------------------------- TSG_Grid_Resampling Resampling = Get_Resampling(Parameters("RESAMPLING")->asInt()); //----------------------------------------------------- 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("Sharpening")); for(int 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( !pPan->is_NoData(x, y) && !pR->is_NoData(x, y) && !pG->is_NoData(x, y) && !pB->is_NoData(x, y) ) { double k = (pR->asDouble(x, y) + pG->asDouble(x, y) + pB->asDouble(x, y)); if( k != 0.0 ) { k = pPan->asDouble(x, y) / k; } pR->Mul_Value(x, y, k); pG->Mul_Value(x, y, k); pB->Mul_Value(x, y, k); } else { pR->Set_NoData(x, y); pG->Set_NoData(x, y); pB->Set_NoData(x, y); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CConstantGrid::On_Execute(void) { //----------------------------------------------------- TSG_Data_Type Type = SG_DATATYPE_Float; switch( Parameters("TYPE")->asInt() ) { case 0: Type = SG_DATATYPE_Bit ; break; case 1: Type = SG_DATATYPE_Byte ; break; case 2: Type = SG_DATATYPE_Char ; break; case 3: Type = SG_DATATYPE_Word ; break; case 4: Type = SG_DATATYPE_Short ; break; case 5: Type = SG_DATATYPE_ULong ; break; case 6: Type = SG_DATATYPE_Long ; break; case 7: Type = SG_DATATYPE_Float ; break; case 8: Type = SG_DATATYPE_Double; break; } //----------------------------------------------------- CSG_Grid *pGrid = m_Grid_Target.Get_Grid(Type); if( pGrid == NULL ) { return( false ); } //----------------------------------------------------- pGrid->Set_Name(Parameters("NAME" )->asString()); pGrid->Assign (Parameters("CONST")->asDouble()); 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 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_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 ); }
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 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 CGW_Multi_Regression_Grid::Set_Model(void) { CSG_Grid *pRegression = Parameters("REGRESSION")->asGrid(); CSG_Grid *pQuality = Parameters("QUALITY" )->asGrid(); pRegression->Set_Name(CSG_String::Format(SG_T("%s [%s]" ), m_Points.Get_Name(), _TL("GWR"))); pQuality ->Set_Name(CSG_String::Format(SG_T("%s [%s, %s]"), m_Points.Get_Name(), _TL("GWR"), _TL("Quality"))); if( m_pQuality == Parameters("QUALITY")->asGrid() ) { pQuality = NULL; } //----------------------------------------------------- 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, p_x = Get_XMin() + x * Get_Cellsize(); if( Set_Model(p_x, p_y, Value) ) { GRID_SET_VALUE(pRegression, x, y, Value); GRID_SET_VALUE(pQuality , x, y, m_pQuality->Get_Value(p_x, p_y)); } else { GRID_SET_NODATA(pRegression, x, y); GRID_SET_NODATA(pQuality , x, y); } } } //----------------------------------------------------- Set_Residuals(); return( true ); }
//--------------------------------------------------------- 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->Set_Name(CSG_String::Format("%s [%s]", pGrid->Get_Name(), Parameters("METHOD")->asString())); } //----------------------------------------------------- double zMin = pGrid->Get_ZMin(); double zMax = pGrid->Get_ZMax(); 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 CSet_Grid_Georeference::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); if( pGrids->Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- double xMin, yMin, size; switch( Parameters("DEFINITION")->asInt() ) { case 0: // cellsize and lower left center coordinates size = Parameters("SIZE")->asDouble(); xMin = Parameters("XMIN")->asDouble(); yMin = Parameters("YMIN")->asDouble(); break; case 1: // cellsize and lower left corner coordinates size = Parameters("SIZE")->asDouble(); xMin = Parameters("XMIN")->asDouble() + size * 0.5; yMin = Parameters("YMIN")->asDouble() + size * 0.5; break; case 2: // cellsize and upper left center coordinates size = Parameters("SIZE")->asDouble(); xMin = Parameters("XMIN")->asDouble(); yMin = Parameters("YMAX")->asDouble() - size * Get_NY(); break; case 3: // cellsize and upper left corner coordinates size = Parameters("SIZE")->asDouble(); xMin = Parameters("XMIN")->asDouble() + size * 0.5; yMin = Parameters("YMAX")->asDouble() - size * (0.5 + Get_NY()); break; case 4: // lower left and upper right center coordinates size = (Parameters("XMAX")->asDouble() - Parameters("XMIN")->asDouble()) / Get_NX(); xMin = Parameters("XMIN")->asDouble(); yMin = Parameters("YMIN")->asDouble(); break; case 5: // lower left and upper right corner coordinates size = (Parameters("XMAX")->asDouble() - Parameters("XMIN")->asDouble()) / (Get_NX() + 1); xMin = Parameters("XMIN")->asDouble() + size * 0.5; yMin = Parameters("YMIN")->asDouble() + size * 0.5; break; } //----------------------------------------------------- CSG_Grid_System System; if( !System.Assign(size, xMin, yMin, Get_NX(), Get_NY()) ) { return( false ); } //----------------------------------------------------- Parameters("REFERENCED")->asGridList()->Del_Items(); for(int i=0; i<pGrids->Get_Count() && Process_Get_Okay(); i++) { CSG_Grid *pGrid = pGrids->asGrid(i); CSG_Grid *pReferenced = SG_Create_Grid(System, pGrid->Get_Type()); pReferenced->Set_Name(pGrid->Get_Name()); pReferenced->Set_Unit(pGrid->Get_Unit()); pReferenced->Set_Scaling(pGrid->Get_Scaling(), pGrid->Get_Offset()); pReferenced->Set_NoData_Value_Range(pGrid->Get_NoData_Value(), pGrid->Get_NoData_hiValue()); pReferenced->Get_MetaData () = pGrid->Get_MetaData (); pReferenced->Get_Projection() = pGrid->Get_Projection(); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { pReferenced->Set_Value(x, y, pGrid->asDouble(x, y)); } } Parameters("REFERENCED")->asGridList()->Add_Item(pReferenced); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CDirect_Georeferencing::On_Execute(void) { //----------------------------------------------------- if( !m_Georeferencer.Set_Transformation(Parameters, Get_NX(), Get_NY()) ) { return( false ); } //----------------------------------------------------- CSG_Grid *pDEM = Parameters("DEM" )->asGrid(); double zRef = Parameters("ZREF" )->asDouble(); bool bFlip = Parameters("ROW_ORDER")->asInt() == 1; //----------------------------------------------------- TSG_Grid_Resampling Resampling; switch( Parameters("RESAMPLING")->asInt() ) { default: Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: Resampling = GRID_RESAMPLING_Bilinear; break; case 2: Resampling = GRID_RESAMPLING_BicubicSpline; break; case 3: Resampling = GRID_RESAMPLING_BSpline; break; } //----------------------------------------------------- TSG_Point p[4]; p[0] = m_Georeferencer.Image_to_World( 0, 0, zRef); p[1] = m_Georeferencer.Image_to_World(Get_NX(), 0, zRef); p[2] = m_Georeferencer.Image_to_World(Get_NX(), Get_NY(), zRef); p[3] = m_Georeferencer.Image_to_World( 0, Get_NY(), zRef); CSG_Rect r(p[0], p[1]); r.Union(p[2]); r.Union(p[3]); //----------------------------------------------------- CSG_Shapes *pShapes = Parameters("EXTENT")->asShapes(); if( pShapes ) { pShapes->Create(SHAPE_TYPE_Polygon, _TL("Extent")); pShapes->Add_Field(_TL("OID"), SG_DATATYPE_Int); CSG_Shape *pExtent = pShapes->Add_Shape(); pExtent->Add_Point(p[0]); pExtent->Add_Point(p[1]); pExtent->Add_Point(p[2]); pExtent->Add_Point(p[3]); } //----------------------------------------------------- double Cellsize = SG_Get_Distance(p[0], p[1]) / Get_NX(); CSG_Grid_System System(Cellsize, r); m_Grid_Target.Set_User_Defined(Get_Parameters("TARGET"), r, Get_NX()); if( !Dlg_Parameters("TARGET") ) { return( false ); } System = m_Grid_Target.Get_System(); if( !System.is_Valid() ) { return( false ); } //----------------------------------------------------- CSG_Parameter_Grid_List *pInput = Parameters("INPUT" )->asGridList(); CSG_Parameter_Grid_List *pOutput = Parameters("OUTPUT")->asGridList(); pOutput->Del_Items(); if( pInput->Get_Count() <= 0 ) { return( false ); } else { TSG_Data_Type Type; switch( Parameters("DATA_TYPE")->asInt() ) { case 0: Type = SG_DATATYPE_Byte; break; case 1: Type = SG_DATATYPE_Char; break; case 2: Type = SG_DATATYPE_Word; break; case 3: Type = SG_DATATYPE_Short; break; case 4: Type = SG_DATATYPE_DWord; break; case 5: Type = SG_DATATYPE_Int; break; case 6: Type = SG_DATATYPE_Float; break; case 7: Type = SG_DATATYPE_Double; break; default: Type = SG_DATATYPE_Undefined; break; } for(int i=0; i<pInput->Get_Count(); i++) { CSG_Grid *pGrid = SG_Create_Grid(System, Type != SG_DATATYPE_Undefined ? Type : pInput->asGrid(i)->Get_Type()); if( !pGrid || !pGrid->is_Valid() ) { if( pGrid ) { delete(pGrid); } return( false ); } pOutput->Add_Item(pGrid); pGrid->Set_Name(pInput->asGrid(i)->Get_Name()); } } //----------------------------------------------------- for(int y=0; y<System.Get_NY() && Set_Progress(y, System.Get_NY()); y++) { double py = System.Get_YMin() + y * System.Get_Cellsize(); #pragma omp parallel for for(int x=0; x<System.Get_NX(); x++) { double pz, px = System.Get_XMin() + x * System.Get_Cellsize(); if( !pDEM || !pDEM->Get_Value(px, py, pz) ) { pz = zRef; } TSG_Point p = m_Georeferencer.World_to_Image(px, py, pz); if( bFlip ) { p.y = (Get_NY() - 1) - p.y; } for(int i=0; i<pInput->Get_Count(); i++) { if( pInput->asGrid(i)->Get_Value(p.x, p.y, pz, Resampling) ) { pOutput->asGrid(i)->Set_Value(x, y, pz); } else { pOutput->asGrid(i)->Set_NoData(x, y); } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets, const CSG_Grid_System &Target_System) { if( !m_Projector.Set_Inverse(true) || !pTargets || !pSources || pSources->Get_Count() < 1 ) { return( false ); } //----------------------------------------------------- CSG_Grid *pX, *pY; if( !Parameters("CREATE_XY")->asBool() ) { pX = pY = NULL; } else { Parameters("OUT_X")->Set_Value(pX = SG_Create_Grid(Target_System, SG_DATATYPE_Float)); pX->Assign_NoData(); pX->Set_Name(_TL("X-Coordinate")); pX->Get_Projection().Create(m_Projector.Get_Target()); Parameters("OUT_Y")->Set_Value(pY = SG_Create_Grid(Target_System, SG_DATATYPE_Float)); pY->Assign_NoData(); pY->Set_Name(_TL("Y-Coordinate")); pY->Get_Projection().Create(m_Projector.Get_Target()); } //----------------------------------------------------- bool bGeogCS_Adjust = m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pSources->asGrid(0)->Get_System().Get_XMax() > 180.0; Set_Target_Area(pSources->asGrid(0)->Get_System(), Target_System); //----------------------------------------------------- int i, n = pTargets->Get_Count(); for(i=0; i<pSources->Get_Count(); i++) { CSG_Grid *pSource = pSources->asGrid(i); CSG_Grid *pTarget = SG_Create_Grid(Target_System, m_Interpolation == 0 ? pSource->Get_Type() : SG_DATATYPE_Float); if( pTarget ) { pTarget->Set_NoData_Value_Range (pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue()); pTarget->Set_ZFactor (pSource->Get_ZFactor()); pTarget->Set_Name (CSG_String::Format(SG_T("%s"), pSource->Get_Name())); pTarget->Set_Unit (pSource->Get_Unit()); pTarget->Assign_NoData(); pTarget->Get_Projection().Create(m_Projector.Get_Target()); pTargets->Add_Item(pTarget); } } //------------------------------------------------- for(int y=0; y<Target_System.Get_NY() && Set_Progress(y, Target_System.Get_NY()); y++) { double yTarget = Target_System.Get_YMin() + y * Target_System.Get_Cellsize(); #pragma omp parallel for private(i) for(int x=0; x<Target_System.Get_NX(); x++) { double z, ySource, xSource = Target_System.Get_XMin() + x * Target_System.Get_Cellsize(); if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) ) { if( pX ) pX->Set_Value(x, y, xSource); if( pY ) pY->Set_Value(x, y, ySource); if( bGeogCS_Adjust && xSource < 0.0 ) { xSource += 360.0; } for(i=0; i<pTargets->Get_Count(); i++) { if( pSources->asGrid(i)->Get_Value(xSource, ySource, z, m_Interpolation) ) { pTargets->asGrid(n + i)->Set_Value(x, y, z); } } } } } //----------------------------------------------------- m_Target_Area.Destroy(); return( true ); }
//--------------------------------------------------------- bool CMOLA_Import::On_Execute(void) { bool bDown; int xa, xb, y, yy, NX, NY; short *sLine; double D, xMin, yMin; CSG_File Stream; TSG_Data_Type Type; CSG_Grid *pGrid; CSG_String fName, sName; //----------------------------------------------------- pGrid = NULL; switch( Parameters("TYPE")->asInt() ) { case 0: Type = SG_DATATYPE_Short; break; case 1: default: Type = SG_DATATYPE_Float; break; } bDown = Parameters("ORIENT")->asInt() == 1; //----------------------------------------------------- // MEGpxxnyyyrv // 012345678901 // p indicates the product type (A for areoid, C for counts, R for // radius, and T for topography) // xx is the latitude of the upper left corner of the image // n indicates whether the latitude is north (N) or south (S) // yyy is the east longitude of the upper left corner of the image // r is the map resolution using the pattern // c = 4 pixel per degree // e = 16 pixel per degree // f = 32 pixel per degree // g = 64 pixel per degree // h = 128 pixel per degree // (This convention is consistent with that used for the Mars Digital // Image Model [MDIM] archives.) // v is a letter indicating the product version. fName = SG_File_Get_Name(Parameters("FILE")->asString(), false); fName.Make_Upper(); if( fName.Length() < 12 ) { return( false ); } //----------------------------------------------------- switch( fName[3] ) { default: return( false ); case 'A': sName.Printf(SG_T("MOLA: Areoid v%c") , fName[11]); break; case 'C': sName.Printf(SG_T("MOLA: Counts v%c") , fName[11]); break; case 'R': sName.Printf(SG_T("MOLA: Radius v%c") , fName[11]); break; case 'T': sName.Printf(SG_T("MOLA: Topography v%c") , fName[11]); break; } //----------------------------------------------------- switch( fName[10] ) { default: return( false ); case 'C': // 1/4th degree... D = 1.0 / 4.0; NX = 4 * 360; NY = 4 * 180; yMin = - 90.0; xMin = -180.0; break; case 'D': // 1/8th degree... D = 1.0 / 8.0; NX = 8 * 360; NY = 8 * 180; yMin = - 90.0; xMin = -180.0; break; case 'E': // 1/16th degree... D = 1.0 / 16.0; NX = 16 * 360; NY = 16 * 180; yMin = - 90.0; xMin = -180.0; break; case 'F': // 1/32th degree... D = 1.0 / 32.0; NX = 32 * 360; NY = 32 * 180; yMin = - 90.0; xMin = -180.0; break; case 'G': // 1/64th degree... D = 1.0 / 64.0; NX = 64 * 180; NY = 64 * 90; yMin = (fName[6] == 'S' ? -1.0 : 1.0) * fName.Right(8).asInt(); yMin = bDown ? yMin - NY * D : -yMin; xMin = fName.Right(5).asInt(); if( xMin >= 180.0 ) { xMin -= 360.0; } break; case 'H': // 1/128th degree... D = 1.0 / 128.0; NX = 128 * 90; NY = 128 * 44; yMin = (fName[6] == 'S' ? -1.0 : 1.0) * fName.Right(8).asInt(); yMin = bDown ? yMin - NY * D : -yMin; xMin = fName.Right(5).asInt(); if( xMin >= 180.0 ) { xMin -= 360.0; } break; } //----------------------------------------------------- if( Stream.Open(Parameters("FILE")->asString(), SG_FILE_R, true) ) { if( (pGrid = SG_Create_Grid(Type, NX, NY, D, xMin + D / 2.0, yMin + D / 2.0)) != NULL ) { pGrid->Set_Name(sName); pGrid->Set_NoData_Value(-999999); pGrid->Get_Projection().Create(SG_T("+proj=lonlat +units=m +a=3396200.000000 +b=3376200.000000"), SG_PROJ_FMT_Proj4); //--------------------------------------------- sLine = (short *)SG_Malloc(NX * sizeof(short)); for(y=0; y<NY && !Stream.is_EOF() && Set_Progress(y, NY); y++) { yy = bDown ? NY - 1 - y : y; Stream.Read(sLine, NX, sizeof(short)); if( fName[10] == 'G' || fName[10] == 'H' ) { for(xa=0; xa<NX; xa++) { SG_Swap_Bytes(sLine + xa, sizeof(short)); pGrid->Set_Value(xa, yy, sLine[xa]); } } else { for(xa=0, xb=NX/2; xb<NX; xa++, xb++) { SG_Swap_Bytes(sLine + xa, sizeof(short)); SG_Swap_Bytes(sLine + xb, sizeof(short)); pGrid->Set_Value(xa, yy, sLine[xb]); pGrid->Set_Value(xb, yy, sLine[xa]); } } } //--------------------------------------------- SG_Free(sLine); Parameters("GRID")->Set_Value(pGrid); } } return( pGrid != NULL ); }
//--------------------------------------------------------- bool CGrid_Table_Import::On_Execute(void) { bool bDown; int x, y, nx, ny; double dxy, xmin, ymin, zFactor, zNoData; TSG_Data_Type data_type; CSG_String FileName, Unit; CSG_Grid *pGrid; CSG_Table Table; CSG_Table_Record *pRecord; //----------------------------------------------------- FileName = Parameters("FILE_DATA") ->asString(); dxy = Parameters("DXY") ->asDouble(); xmin = Parameters("XMIN") ->asDouble(); ymin = Parameters("YMIN") ->asDouble(); bDown = Parameters("TOPDOWN") ->asInt() == 1; Unit = Parameters("UNIT") ->asString(); zFactor = Parameters("ZFACTOR") ->asDouble(); zNoData = Parameters("NODATA") ->asDouble(); switch( Parameters("DATA_TYPE")->asInt() ) { default: data_type = SG_DATATYPE_Undefined; break; // not handled case 0: data_type = SG_DATATYPE_Byte; break; // 1 Byte Integer (unsigned) case 1: data_type = SG_DATATYPE_Char; break; // 1 Byte Integer (signed) case 2: data_type = SG_DATATYPE_Word; break; // 2 Byte Integer (unsigned) case 3: data_type = SG_DATATYPE_Short; break; // 2 Byte Integer (signed) case 4: data_type = SG_DATATYPE_DWord; break; // 4 Byte Integer (unsigned) case 5: data_type = SG_DATATYPE_Int; break; // 4 Byte Integer (signed) case 6: data_type = SG_DATATYPE_Float; break; // 4 Byte Floating Point case 7: data_type = SG_DATATYPE_Double; break; // 8 Byte Floating Point } //----------------------------------------------------- if( Table.Create(FileName) && (nx = Table.Get_Field_Count()) > 0 && (ny = Table.Get_Record_Count()) > 0 ) { pGrid = SG_Create_Grid(data_type, nx, ny, dxy, xmin, ymin); for(y=0; y<ny && Set_Progress(y, ny); y++) { pRecord = Table.Get_Record(bDown ? ny - 1 - y : y); for(x=0; x<nx; x++) { pGrid->Set_Value(x, y, pRecord->asDouble(x)); } } pGrid->Set_Unit (Unit); pGrid->Set_ZFactor (zFactor); pGrid->Set_NoData_Value (zNoData); pGrid->Set_Name (SG_File_Get_Name(FileName, false)); Parameters("GRID")->Set_Value(pGrid); return( true ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool CGrid_Value_Replace::On_Execute(void) { //----------------------------------------------------- CSG_Grid *pGrid = Parameters("OUTPUT")->asGrid(); if( !pGrid || pGrid == Parameters("INPUT")->asGrid() ) { pGrid = Parameters("INPUT")->asGrid(); } else { pGrid->Assign(Parameters("INPUT")->asGrid()); DataObject_Set_Parameters(pGrid, Parameters("INPUT")->asGrid()); pGrid->Set_Name(CSG_String::Format("%s [%s]", Parameters("INPUT")->asGrid()->Get_Name(), _TL("Changed"))); } //----------------------------------------------------- int Method = Parameters("METHOD")->asInt(); CSG_Table LUT; switch( Method ) { default: LUT.Create(*Parameters("IDENTITY")->asTable()); break; case 1: LUT.Create(*Parameters("RANGE" )->asTable()); break; case 2: LUT.Create( Parameters("RANGE" )->asTable()); if( SG_UI_Get_Window_Main() // gui only && DataObject_Get_Parameter(Parameters("GRID" )->asGrid(), "LUT") && DataObject_Get_Parameter(Parameters("INPUT")->asGrid(), "LUT") ) { CSG_Table LUTs[2]; LUTs[0].Create(*DataObject_Get_Parameter(Parameters("GRID" )->asGrid(), "LUT")->asTable()); LUTs[1].Create(*DataObject_Get_Parameter(Parameters("INPUT")->asGrid(), "LUT")->asTable()); for(int i=0; i<LUTs[0].Get_Count(); i++) { CSG_String Name = LUTs[0][i].asString(1); for(int j=LUTs[1].Get_Count()-1; j>=0; j--) { if( !Name.Cmp(LUTs[1][j].asString(1)) ) { CSG_Table_Record *pReplace = LUT.Add_Record(); pReplace->Set_Value(0, LUTs[0][i].asDouble(3)); pReplace->Set_Value(1, LUTs[1][j].asDouble(3)); pReplace->Set_Value(2, LUTs[1][j].asDouble(4)); LUTs[1].Del_Record(j); break; } } } for(int j=0; j<LUTs[1].Get_Count(); j++) { LUTs[0].Add_Record(LUTs[1].Get_Record(j)); } DataObject_Add(pGrid); CSG_Parameter *pLUT = DataObject_Get_Parameter(pGrid, "LUT"); pLUT->asTable()->Assign_Values(&LUTs[0]); DataObject_Set_Parameter(pGrid, pLUT); } break; } //----------------------------------------------------- if( LUT.Get_Count() == 0 ) { Error_Set(_TL("empty look-up table, nothing to replace")); return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #ifndef _DEBUG #pragma omp parallel for #endif for(int x=0; x<Get_NX(); x++) { double Value = pGrid->asDouble(x, y); for(int i=0; i<LUT.Get_Count(); i++) { if( Method == 0 ) { if( LUT[i].asDouble(1) == Value ) { pGrid->Set_Value(x, y, LUT[i].asDouble(0)); break; } } else { if( LUT[i].asDouble(1) <= Value && Value <= LUT[i].asDouble(2) ) { pGrid->Set_Value(x, y, LUT[i].asDouble(0)); break; } } } } } //----------------------------------------------------- if( pGrid == Parameters("INPUT")->asGrid() ) { DataObject_Update(pGrid); } return( true ); }
//--------------------------------------------------------- bool CGCS_Grid_Longitude_Range::On_Execute(void) { CSG_Parameter_Grid_List *pInput = Parameters("INPUT" )->asGridList(); CSG_Parameter_Grid_List *pOutput = Parameters("OUTPUT")->asGridList(); if( pInput->Get_Count() <= 0 ) { Message_Dlg(_TL("nothing to do: no data in selection")); return( false ); } pOutput->Del_Items(); //----------------------------------------------------- int xZero; CSG_Grid_System Target; //----------------------------------------------------- if( Parameters("DIRECTION")->asInt() == 0 ) // 0 - 360 >> -180 - 180 { if( Get_XMax() <= 180.0 ) { Message_Add(_TL("Nothing to do. Raster is already within target range.")); return( true ); } else if( Get_XMin() >= 180.0 ) { xZero = 0; Target.Assign(Get_Cellsize(), Get_XMin() - 360.0, Get_YMin(), Get_NX(), Get_NY()); } else if( Get_XMax() - 360.0 < Get_XMin() - Get_Cellsize() ) { Error_Set(_TL("Nothing to do be done. Raster splitting is not supported.")); return( false ); } else { xZero = (int)(0.5 + 180.0 / Get_Cellsize()); Target.Assign(Get_Cellsize(), Get_XMin() - 180.0, Get_YMin(), Get_NX(), Get_NY()); } } //----------------------------------------------------- else // -180 - 180 >> 0 - 360 { if( Get_XMin() >= 0.0 ) { Message_Add(_TL("Nothing to do. Raster is already within target range.")); return( true ); } else if( Get_XMax() <= 0.0 ) { xZero = 0; Target.Assign(Get_Cellsize(), Get_XMin() + 360.0, Get_YMin(), Get_NX(), Get_NY()); } else if( Get_XMin() + 360.0 > Get_XMax() + Get_Cellsize() ) { Error_Set(_TL("Nothing to do be done. Raster splitting is not supported.")); return( false ); } else { xZero = (int)(0.5 + 180.0 / Get_Cellsize()); Target.Assign(Get_Cellsize(), Get_XMin() - 180.0, Get_YMin(), Get_NX(), Get_NY()); } } //----------------------------------------------------- for(int i=0; i<pInput->Get_Count() && Process_Get_Okay(); i++) { CSG_Grid *pIn = pInput->asGrid(i); CSG_Grid *pOut = SG_Create_Grid(Target, pIn->Get_Type()); pOut->Set_Name(pIn->Get_Name()); pOut->Set_NoData_Value_Range(pIn->Get_NoData_Value(), pIn->Get_NoData_hiValue()); pOut->Set_ZFactor(pIn->Get_ZFactor()); pOutput->Add_Item(pOut); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0, xx=xZero; x<Get_NX(); x++, xx++) { if( xx >= Get_NX() ) { xx = 0; } pOut->Set_Value(xx, y, pIn->asDouble(x, y)); } } } //----------------------------------------------------- return( true ); }
bool CCreateGridSystem::On_Execute(void) { CSG_Grid *pDummy; CSG_Shapes *pShapes; CSG_Rect extent; CSG_Parameter_Shapes_List *pShapesList; CSG_Parameter_Grid_List *pGridList; CSG_Grid_System System; double xMin, xMax, yMin, yMax, cellsize, offset_x, offset_y, xRange, yRange, n, initVal; int NX, NY, m_extent, m_adjust, i; bool useoff; xMin = Parameters("XMIN")->asDouble(); yMin = Parameters("YMIN")->asDouble(); xMax = Parameters("XMAX")->asDouble(); yMax = Parameters("YMAX")->asDouble(); NX = Parameters("NX")->asInt(); NY = Parameters("NY")->asInt(); cellsize = Parameters("CELLSIZE")->asDouble(); offset_x = Parameters("XOFFSET")->asDouble(); offset_y = Parameters("YOFFSET")->asDouble(); useoff = Parameters("USEOFF")->asBool(); m_extent = Parameters("M_EXTENT")->asInt(); m_adjust = Parameters("ADJUST")->asInt(); initVal = Parameters("INIT")->asDouble(); pShapesList = Parameters("SHAPESLIST")->asShapesList(); pGridList = Parameters("GRIDLIST")->asGridList(); if( useoff ) { xMin += offset_x; yMin += offset_y; xMax += offset_x; yMax += offset_y; } switch( m_extent ) { case 0: // xMin, yMin, NX, NY System.Assign(cellsize, xMin, yMin, NX, NY); break; case 1: // xMin, yMin, xMax, yMax if( xMin > xMax || yMin > yMax ) { Message_Add(CSG_String::Format(_TL("\nError: Please verify your xMin, yMin, xMax, yMax settings!\n"))); return false; } xRange = xMax - xMin; yRange = yMax - yMin; if( m_adjust == 0 ) // extent to cellsize { if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) floor(xRange / cellsize + 0.5); xMax = xMin + NX * cellsize; } if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) floor(yRange / cellsize + 0.5); yMax = yMin + NY * cellsize; } } else if( m_adjust == 1) // cellsize to W-E extent { if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) (xRange/cellsize); cellsize = xRange/NX; } if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) floor(yRange / cellsize + 0.5); yMax = yMin + NY * cellsize; } } else // cellsize to S-N extent { if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) (yRange/cellsize); cellsize = yRange/NY; } if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) floor(xRange / cellsize + 0.5); xMax = xMin + NX * cellsize; } } System.Assign(cellsize, xMin, yMin, xMax, yMax); break; case 2: // Shape(s) if( pShapesList == NULL || pShapesList->Get_Count() == 0) { Message_Add(CSG_String::Format(_TL("\nError: the method Extent by Shape(s) requires shape(s) as input!\n"))); return false; } for (i=0; i<pShapesList->Get_Count(); i++) { pShapes = pShapesList->asShapes(i); extent = pShapes->Get_Extent(); if (i==0) { xMin = extent.Get_XMin(); yMin = extent.Get_YMin(); xMax = extent.Get_XMax(); yMax = extent.Get_YMax(); } else { xMin = (extent.Get_XMin() < xMin) ? extent.Get_XMin() : xMin; yMin = (extent.Get_YMin() < yMin) ? extent.Get_YMin() : yMin; xMax = (extent.Get_XMax() > xMax) ? extent.Get_XMax() : xMax; yMax = (extent.Get_YMax() > yMax) ? extent.Get_YMax() : yMax; } } if( useoff ) { xMin += offset_x; xMax += offset_x; yMin += offset_y; yMax += offset_y; } xRange = xMax - xMin; yRange = yMax - yMin; if( m_adjust == 0 ) // extent to cellsize { if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) floor(xRange / cellsize + 0.5); xMax = xMin + NX * cellsize; } if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) floor(yRange / cellsize + 0.5); yMax = yMin + NY * cellsize; } } else if( m_adjust == 1) // cellsize to W-E extent { if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) (xRange/cellsize); cellsize = xRange/NX; } if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) floor(yRange / cellsize + 0.5); yMax = yMin + NY * cellsize; } } else // cellsize to S-N extent { if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) (yRange/cellsize); cellsize = yRange/NY; } if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) floor(xRange / cellsize + 0.5); xMax = xMin + NX * cellsize; } } System.Assign(cellsize, xMin, yMin, xMax, yMax); break; case 3: // Grid(s) if( pGridList == NULL || pGridList->Get_Count() == 0) { Message_Add(CSG_String::Format(_TL("\nError: the method Extent by Grid(s) requires grid(s) as input!\n"))); return false; } for (i=0; i<pGridList->Get_Count(); i++) { pDummy = pGridList->asGrid(i); extent = pDummy->Get_Extent(); if (i==0) { xMin = extent.Get_XMin(); yMin = extent.Get_YMin(); xMax = extent.Get_XMax(); yMax = extent.Get_YMax(); } else { xMin = (extent.Get_XMin() < xMin) ? extent.Get_XMin() : xMin; yMin = (extent.Get_YMin() < yMin) ? extent.Get_YMin() : yMin; xMax = (extent.Get_XMax() > xMax) ? extent.Get_XMax() : xMax; yMax = (extent.Get_YMax() > yMax) ? extent.Get_YMax() : yMax; } } if( useoff ) { xMin += offset_x; xMax += offset_x; yMin += offset_y; yMax += offset_y; } xRange = xMax - xMin; yRange = yMax - yMin; if( m_adjust == 0 ) // extent to cellsize { if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) floor(xRange / cellsize + 0.5); xMax = xMin + NX * cellsize; } if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) floor(yRange / cellsize + 0.5); yMax = yMin + NY * cellsize; } } else if( m_adjust == 1) // cellsize to W-E extent { if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) (xRange/cellsize); cellsize = xRange/NX; } if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) floor(yRange / cellsize + 0.5); yMax = yMin + NY * cellsize; } } else // cellsize to S-N extent { if( modf((yRange/cellsize), &n) != 0.0 ) { NY = (int) (yRange/cellsize); cellsize = yRange/NY; } if( modf((xRange/cellsize), &n) != 0.0 ) { NX = (int) floor(xRange / cellsize + 0.5); xMax = xMin + NX * cellsize; } } System.Assign(cellsize, xMin, yMin, xMax, yMax); break; } pDummy = SG_Create_Grid(System, SG_DATATYPE_Double); pDummy->Assign(initVal); pDummy->Set_Name(_TL("Dummy Grid")); Parameters("GRID")->Set_Value(pDummy); return (true); }
//--------------------------------------------------------- bool CGrid_Import::On_Execute(void) { bool bTransform; int x, y, yy, Method; double ax, ay, dx, dy, rx, ry, xMin, yMin, Cellsize; CSG_Colors Colors; CSG_String fImage, fWorld, Name; CSG_Grid *pImage; CSG_File Stream; wxImage Image; wxImageHistogram Histogram; //----------------------------------------------------- fImage = Parameters("FILE") ->asString(); Method = Parameters("METHOD") ->asInt(); Name = SG_File_Get_Name(fImage, false); //----------------------------------------------------- wxImageHandler *pImgHandler = NULL; if( !SG_UI_Get_Window_Main() ) { CSG_String fName = SG_File_Get_Name(fImage, true); if( SG_File_Cmp_Extension(fName, SG_T("jpg")) ) pImgHandler = new wxJPEGHandler; else if( SG_File_Cmp_Extension(fName, SG_T("pcx")) ) pImgHandler = new wxPCXHandler; else if( SG_File_Cmp_Extension(fName, SG_T("tif")) ) pImgHandler = new wxTIFFHandler; else if( SG_File_Cmp_Extension(fName, SG_T("gif")) ) pImgHandler = new wxGIFHandler; else if( SG_File_Cmp_Extension(fName, SG_T("pnm")) ) pImgHandler = new wxPNMHandler; else if( SG_File_Cmp_Extension(fName, SG_T("xpm")) ) pImgHandler = new wxXPMHandler; #ifdef _SAGA_MSW else if( SG_File_Cmp_Extension(fName, SG_T("bmp")) ) pImgHandler = new wxBMPHandler; #endif else // if( SG_File_Cmp_Extension(fName, SG_T("png")) ) pImgHandler = new wxPNGHandler; wxImage::AddHandler(pImgHandler); } if( !Image.LoadFile(fImage.c_str()) ) { return( false ); } //----------------------------------------------------- if( SG_File_Cmp_Extension(fImage, SG_T("bmp")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("bpw")); } else if( SG_File_Cmp_Extension(fImage, SG_T("jpg")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("jgw")); } else if( SG_File_Cmp_Extension(fImage, SG_T("png")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("pgw")); } else if( SG_File_Cmp_Extension(fImage, SG_T("tif")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("tfw")); } else { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("world")); } bTransform = false; xMin = 0.0; yMin = 0.0; Cellsize = 1.0; if( Stream.Open(fWorld, SG_FILE_R, false) && fscanf(Stream.Get_Stream(), "%lf %lf %lf %lf %lf %lf ", &dx, &ry, &rx, &dy, &ax, &ay) == 6 ) { if( dx != -dy || rx != 0.0 || ry != 0.0 ) { bTransform = true; } else { xMin = ax; yMin = ay + dy * (Image.GetHeight() - 1); Cellsize = dx; } } //----------------------------------------------------- // color look-up table... if( Method == 0 && (yy = Image.ComputeHistogram(Histogram)) <= 256 ) { Colors.Set_Count(yy); for(wxImageHistogram::iterator i=Histogram.begin(); i!=Histogram.end(); ++i) { Colors.Set_Color(i->second.index, SG_GET_R(i->first), SG_GET_G(i->first), SG_GET_B(i->first)); } pImage = SG_Create_Grid(yy <= 2 ? SG_DATATYPE_Bit : SG_DATATYPE_Byte, Image.GetWidth(), Image.GetHeight(), Cellsize, xMin, yMin); for(y=0; y<pImage->Get_NY() && Set_Progress(y, pImage->Get_NY()); y++) { yy = bTransform ? y : pImage->Get_NY() - 1 - y; for(x=0; x<pImage->Get_NX(); x++) { pImage->Set_Value(x, y, Histogram[SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy))].index); } } if( bTransform ) { Set_Transformation(&pImage, ax, ay, dx, dy, rx, ry); } pImage->Set_Name(Name); pImage->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); Parameters("OUT_GRID")->Set_Value(pImage); DataObject_Set_Colors(pImage, Colors); DataObject_Update(pImage, 0, Colors.Get_Count() - 1); } //----------------------------------------------------- else // true color... { pImage = SG_Create_Grid(SG_DATATYPE_Int, Image.GetWidth(), Image.GetHeight(), Cellsize, xMin, yMin); pImage ->Set_Name(Name); for(y=0; y<pImage->Get_NY() && Set_Progress(y, pImage->Get_NY()); y++) { yy = bTransform ? y : pImage->Get_NY() - 1 - y; for(x=0; x<pImage->Get_NX(); x++) { pImage->Set_Value(x, y, SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy))); } } if( bTransform ) { Set_Transformation(&pImage, ax, ay, dx, dy, rx, ry); } //------------------------------------------------- if( Method != 1 ) // true color... { pImage->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pImage->Set_Name(Name); pImage->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); Parameters("OUT_GRID")->Set_Value(pImage); DataObject_Set_Colors(pImage, 100, SG_COLORS_BLACK_WHITE); DataObject_Set_Parameter(pImage, "COLORS_TYPE", 6); // Color Classification Type: RGB } //------------------------------------------------- else // split channels... { CSG_Grid *pR, *pG, *pB; pR = SG_Create_Grid(pImage->Get_System(), SG_DATATYPE_Byte); pG = SG_Create_Grid(pImage->Get_System(), SG_DATATYPE_Byte); pB = SG_Create_Grid(pImage->Get_System(), SG_DATATYPE_Byte); for(y=0; y<pImage->Get_NY() && Set_Progress(y, pImage->Get_NY()); y++) { for(x=0; x<pImage->Get_NX(); x++) { pR->Set_Value(x, y, SG_GET_R(pImage->asInt(x, y))); pG->Set_Value(x, y, SG_GET_G(pImage->asInt(x, y))); pB->Set_Value(x, y, SG_GET_B(pImage->asInt(x, y))); } } pR->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pG->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pB->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pR->Set_Name(CSG_String::Format(SG_T("%s [R]"), Name.c_str())); pG->Set_Name(CSG_String::Format(SG_T("%s [G]"), Name.c_str())); pB->Set_Name(CSG_String::Format(SG_T("%s [B]"), Name.c_str())); pR->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); pG->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); pB->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); Parameters("OUT_RED") ->Set_Value(pR); Parameters("OUT_GREEN") ->Set_Value(pG); Parameters("OUT_BLUE") ->Set_Value(pB); DataObject_Set_Colors(pR, 100, SG_COLORS_BLACK_RED); DataObject_Set_Colors(pG, 100, SG_COLORS_BLACK_GREEN); DataObject_Set_Colors(pB, 100, SG_COLORS_BLACK_BLUE); } } //----------------------------------------------------- if( !SG_UI_Get_Window_Main() && pImgHandler != NULL) { wxImage::RemoveHandler(pImgHandler->GetName()); } //----------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CCropToData::On_Execute(void) { CSG_Parameter_Grid_List *pGrids = Parameters("INPUT")->asGridList(); //----------------------------------------------------- if( pGrids->Get_Count() <= 0 ) { Error_Set(_TL("no grids in selection")); return( false ); } //----------------------------------------------------- bool bCrop = false; int xMin, yMin, xMax, yMax; //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { bool bData = false; for(int i=0; i<pGrids->Get_Count() && !bData; i++) { if( !pGrids->asGrid(i)->is_NoData(x, y) ) { bData = true; } } if( bData ) { if( bCrop == false ) { bCrop = true; xMin = xMax = x; yMin = yMax = y; } else { if( xMin > x ) { xMin = x; } else if( xMax < x ) { xMax = x; } if( yMin > y ) { yMin = y; } else if( yMax < y ) { yMax = y; } } } } } //----------------------------------------------------- if( bCrop == false ) { Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("nothing to crop"), _TL("no valid data found in grid(s)"))); } else if( (1 + xMax - xMin) == Get_NX() && (1 + yMax - yMin) == Get_NY() ) { Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("nothing to crop"), _TL("valid data cells match original grid extent"))); } else { CSG_Parameter_Grid_List *pCropped = Parameters("OUTPUT")->asGridList(); pCropped->Del_Items(); for(int i=0; i<pGrids->Get_Count(); i++) { CSG_Grid *pGrid = SG_Create_Grid( pGrids->asGrid(i)->Get_Type(), 1 + xMax - xMin, 1 + yMax - yMin, Get_Cellsize(), Get_XMin() + xMin * Get_Cellsize(), Get_YMin() + yMin * Get_Cellsize() ); pGrid->Assign(pGrids->asGrid(i), GRID_INTERPOLATION_NearestNeighbour); pGrid->Set_Name(pGrids->asGrid(i)->Get_Name()); pCropped->Add_Item(pGrid); } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_Calculator::On_Execute(void) { double Result, *Values; CSG_Formula Formula; CSG_Parameter_Grid_List *pGrids; CSG_Grid *pResult; //----------------------------------------------------- pResult = Parameters("RESULT") ->asGrid(); pGrids = Parameters("GRIDS") ->asGridList(); //----------------------------------------------------- if( pGrids->Get_Count() <= 0 ) { Message_Add(_TL("No grid in list")); return( false ); } //----------------------------------------------------- if( !Formula.Set_Formula(Parameters("FORMULA")->asString()) ) { int Position; CSG_String Message, s; s += _TL("Error in formula"); s += SG_T("\n") + Formula.Get_Formula(); if( Formula.Get_Error(&Position, &Message) ) { s += SG_T("\n") + Message; s += CSG_String::Format(SG_T("\n%s: %d"), _TL("Position") , Position); if( Position >= 0 && Position < (int)Formula.Get_Formula().Length() ) { s += SG_T("\n") + Formula.Get_Formula().Left(Position - 1) + SG_T("[") + Formula.Get_Formula()[Position] + SG_T("]") + Formula.Get_Formula().Right(Formula.Get_Formula().Length() - (Position + 1)); } } Message_Add(s, false); return( false ); } //----------------------------------------------------- pResult->Set_Name(Formula.Get_Formula()); Values = new double[pGrids->Get_Count()]; for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { bool bNoData = false; for(int i=0; i<pGrids->Get_Count() && !bNoData; i++) { if( pGrids->asGrid(i)->is_NoData(x, y) ) { bNoData = true; } else { Values[i] = pGrids->asGrid(i)->asDouble(x, y); } } if( bNoData || _finite(Result = Formula.Get_Value(Values, pGrids->Get_Count())) == false ) { pResult->Set_NoData(x, y); } else { pResult->Set_Value(x, y, Result); } } } delete[](Values); //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CWMS_Import::Get_Map(wxHTTP *pServer, const CSG_String &Directory, CWMS_Capabilities &Cap) { bool bResult = false; int i, n; CSG_Rect r(Cap.m_Extent); CSG_Parameters p; //----------------------------------------------------- // if( Cap.m_MaxWidth > 2 && NX > Cap.m_MaxWidth ) NX = Cap.m_MaxWidth; // if( Cap.m_MaxHeight > 2 && NY > Cap.m_MaxHeight ) NY = Cap.m_MaxHeight; p.Add_Range (NULL , "X_RANGE" , _TL("X Range") , _TL(""), r.Get_XMin(), r.Get_XMax(), r.Get_XMin(), r.Get_XRange() > 0.0, r.Get_XMax(), r.Get_XRange() > 0.0); p.Add_Range (NULL , "Y_RANGE" , _TL("Y Range") , _TL(""), r.Get_YMin(), r.Get_YMax(), r.Get_YMin(), r.Get_YRange() > 0.0, r.Get_YMax(), r.Get_YRange() > 0.0); p.Add_Value (NULL , "CELLSIZE", _TL("Cellsize") , _TL(""), PARAMETER_TYPE_Double, r.Get_XRange() / 2001.0, 0.0, true); p.Add_Choice(NULL , "FORMAT" , _TL("Format") , _TL(""), Cap.m_Formats); p.Add_Choice(NULL , "PROJ" , _TL("Projections"), _TL(""), Cap.m_Projections); CSG_Parameter *pNode = p("FORMAT"); for(i=0; i<pNode->asChoice()->Get_Count(); i++) { CSG_String s(pNode->asChoice()->Get_Item(i)); if( !s.CmpNoCase(SG_T("image/png")) ) pNode->Set_Value(i); } for(i=0; i<Cap.m_Layers_Name.Get_Count(); i++) { p.Add_Value(NULL, Cap.m_Layers_Name[i], Cap.m_Layers_Title[i], "", PARAMETER_TYPE_Bool, false); } //----------------------------------------------------- if( pServer && Dlg_Parameters(&p, _TL("WMS Import")) ) { int NX, NY; double Cellsize; CSG_String Layers, Format; //------------------------------------------------- r.Assign( p("X_RANGE")->asRange()->Get_LoVal(), p("Y_RANGE")->asRange()->Get_LoVal(), p("X_RANGE")->asRange()->Get_HiVal(), p("Y_RANGE")->asRange()->Get_HiVal() ); Cellsize = p("CELLSIZE") ->asDouble(); NX = 1 + (int)(r.Get_XRange() / Cellsize); NY = 1 + (int)(r.Get_YRange() / Cellsize); //------------------------------------------------- Layers.Clear(); for(i=0, n=0; i<Cap.m_Layers_Name.Get_Count(); i++) { if( p(Cap.m_Layers_Name[i])->asBool() ) { if( n++ > 0 ) Layers += ","; Layers += Cap.m_Layers_Name[i]; } } if( n == 0 ) { return( false ); } //------------------------------------------------- wxBitmapType tFormat; Format = p("FORMAT")->asString(); if( Format.Contains(SG_T("image/gif" )) ) tFormat = wxBITMAP_TYPE_GIF ; else if( Format.Contains(SG_T("image/jpeg")) ) tFormat = wxBITMAP_TYPE_JPEG; else if( Format.Contains(SG_T("image/png" )) ) tFormat = wxBITMAP_TYPE_PNG ; else if( Format.Contains(SG_T("image/wbmp")) ) tFormat = wxBITMAP_TYPE_BMP ; else if( Format.Contains(SG_T("image/bmp" )) ) tFormat = wxBITMAP_TYPE_BMP ; else if( Format.Contains(SG_T("image/tiff")) ) tFormat = wxBITMAP_TYPE_TIF ; else if( Format.Contains(SG_T("GIF" )) ) tFormat = wxBITMAP_TYPE_GIF ; else if( Format.Contains(SG_T("JPEG" )) ) tFormat = wxBITMAP_TYPE_JPEG; else if( Format.Contains(SG_T("PNG" )) ) tFormat = wxBITMAP_TYPE_PNG ; else { return( false ); } //------------------------------------------------- CSG_String sRequest(Directory); sRequest += SG_T("?SERVICE=WMS"); sRequest += SG_T("&VERSION=") + Cap.m_Version; sRequest += SG_T("&REQUEST=GetMap"); sRequest += SG_T("&LAYERS=") + Layers; if( Cap.m_Projections.Length() > 0 ) sRequest += CSG_String(S_SRS(Cap.m_Version)) + p("PROJ")->asString(); sRequest += SG_T("&FORMAT=") + Format; sRequest += CSG_String::Format(SG_T("&WIDTH=%d&HEIGHT=%d"), NX, NY); sRequest += CSG_String::Format(SG_T("&BBOX=%f,%f,%f,%f"), r.m_rect.xMin, r.m_rect.yMin, r.m_rect.xMax, r.m_rect.yMax); Message_Add(sRequest, true); //------------------------------------------------- wxInputStream *pStream; if( (pStream = pServer->GetInputStream(sRequest.c_str())) == NULL ) { Message_Add(_TL("could not open GetMap stream")); } else { wxImage Image; if( Image.LoadFile(*pStream, tFormat) == false ) { Message_Add(_TL("could not read image")); CSG_String s = SG_T("\n"); pStream->SeekI(0, wxFromStart); while( !pStream->Eof() ) { s += (char)pStream->GetC(); } Message_Add(s); } else { CSG_Grid *pGrid = SG_Create_Grid(SG_DATATYPE_Int, Image.GetWidth(), Image.GetHeight(), Cellsize, r.m_rect.xMin, r.m_rect.yMin); for(int y=0, yy=pGrid->Get_NY()-1; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, yy--) { for(int x=0; x<pGrid->Get_NX(); x++) { pGrid->Set_Value(x, y, SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy))); } } //----------------------------------------- pGrid->Set_Name(Cap.m_Title); Parameters("MAP")->Set_Value(pGrid); DataObject_Set_Colors(pGrid, 100, SG_COLORS_BLACK_WHITE); CSG_Parameters Parms; if( DataObject_Get_Parameters(pGrid, Parms) && Parms("COLORS_TYPE") ) { Parms("COLORS_TYPE")->Set_Value(3); // Color Classification Type: RGB DataObject_Set_Parameters(pGrid, Parms); } bResult = true; } delete(pStream); } } return( bResult ); }
//--------------------------------------------------------- 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_Table_Import::On_Execute(void) { //----------------------------------------------------- CSG_Table Table; if( !Table.Create(Parameters("FILE")->asString()) ) { Error_Fmt("%s [%s]", _TL("could not open table file"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- int nx, ny, nHeadLines = Parameters("HEADLINES")->asInt(); if( (nx = Table.Get_Field_Count()) < 1 || (ny = Table.Get_Record_Count()) < 1 ) { Error_Fmt("%s [%s]", _TL("no data in table file"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- TSG_Data_Type Type; switch( Parameters("DATA_TYPE")->asInt() ) { case 0: Type = SG_DATATYPE_Byte ; break; // 1 Byte Integer (unsigned) case 1: Type = SG_DATATYPE_Char ; break; // 1 Byte Integer (signed) case 2: Type = SG_DATATYPE_Word ; break; // 2 Byte Integer (unsigned) case 3: Type = SG_DATATYPE_Short ; break; // 2 Byte Integer (signed) case 4: Type = SG_DATATYPE_DWord ; break; // 4 Byte Integer (unsigned) case 5: Type = SG_DATATYPE_Int ; break; // 4 Byte Integer (signed) default: Type = SG_DATATYPE_Float ; break; // 4 Byte Floating Point case 7: Type = SG_DATATYPE_Double; break; // 8 Byte Floating Point } //----------------------------------------------------- CSG_Grid *pGrid = SG_Create_Grid(Type, nx, ny, Parameters("CELLSIZE")->asDouble(), Parameters("XMIN" )->asDouble(), Parameters("YMIN" )->asDouble() ); pGrid->Set_Name (SG_File_Get_Name(Parameters("FILE")->asString(), false)); pGrid->Set_Unit (Parameters("UNIT" )->asString()); pGrid->Set_NoData_Value(Parameters("NODATA" )->asDouble()); pGrid->Set_Scaling (Parameters("ZFACTOR")->asDouble()); Parameters("GRID")->Set_Value(pGrid); //----------------------------------------------------- bool bDown = Parameters("TOPDOWN")->asInt() == 1; for(int y=0; y<ny && Set_Progress(y, ny); y++) { CSG_Table_Record *pRecord = Table.Get_Record(y + nHeadLines); for(int x=0, yy=bDown?ny-1-y:y; x<nx; x++) { pGrid->Set_Value(x, yy, pRecord->asDouble(x)); } } //----------------------------------------------------- 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 CKriging_Regression::On_Execute(void) { //----------------------------------------------------- CSG_Shapes Points(SHAPE_TYPE_Point); CSG_Grid *pPrediction = Parameters("PREDICTION")->asGrid(); CSG_Grid *pRegression = Parameters("REGRESSION")->asGrid(); CSG_Grid *pResiduals = Parameters("RESIDUALS" )->asGrid(); CSG_Grid *pVariance = Parameters("VARIANCE" )->asGrid(); //----------------------------------------------------- if( !pResiduals ) { pResiduals = pPrediction; } //----------------------------------------------------- SG_RUN_MODULE_ExitOnError("statistics_regression", 1, // Multiple Regression Analysis (Points and Predictor Grids) SG_MODULE_PARAMETER_SET("PREDICTORS", Parameters("PREDICTORS")) && SG_MODULE_PARAMETER_SET("POINTS" , Parameters("POINTS" )) && SG_MODULE_PARAMETER_SET("ATTRIBUTE" , Parameters("FIELD" )) && SG_MODULE_PARAMETER_SET("INFO_COEFF", Parameters("INFO_COEFF")) && SG_MODULE_PARAMETER_SET("INFO_MODEL", Parameters("INFO_MODEL")) && SG_MODULE_PARAMETER_SET("INFO_STEPS", Parameters("INFO_STEPS")) && SG_MODULE_PARAMETER_SET("RESAMPLING", Parameters("RESAMPLING")) && SG_MODULE_PARAMETER_SET("COORD_X" , Parameters("COORD_X" )) && SG_MODULE_PARAMETER_SET("COORD_Y" , Parameters("COORD_Y" )) && SG_MODULE_PARAMETER_SET("INTERCEPT" , Parameters("INTERCEPT" )) && SG_MODULE_PARAMETER_SET("METHOD" , Parameters("METHOD" )) && SG_MODULE_PARAMETER_SET("P_VALUE" , Parameters("P_VALUE" )) && SG_MODULE_PARAMETER_SET("REGRESSION", pRegression) && SG_MODULE_PARAMETER_SET("RESIDUALS" , &Points ) ); //----------------------------------------------------- Process_Set_Text(m_OK.Get_Name()); m_OK.Set_Manager(NULL); if( !m_OK.Set_Parameter("POINTS" , &Points) || !m_OK.Set_Parameter("FIELD" , 2) // residual || !m_OK.Set_Parameter("LOG" , Parameters("LOG" )) || !m_OK.Set_Parameter("BLOCK" , Parameters("BLOCK" )) || !m_OK.Set_Parameter("DBLOCK" , Parameters("DBLOCK" )) || !m_OK.Set_Parameter("SEARCH_RANGE" , Parameters("SEARCH_RANGE" )) || !m_OK.Set_Parameter("SEARCH_RADIUS" , Parameters("SEARCH_RADIUS" )) || !m_OK.Set_Parameter("SEARCH_POINTS_ALL", Parameters("SEARCH_POINTS_ALL")) || !m_OK.Set_Parameter("SEARCH_POINTS_MIN", Parameters("SEARCH_POINTS_MIN")) || !m_OK.Set_Parameter("SEARCH_POINTS_MAX", Parameters("SEARCH_POINTS_MAX")) || !m_OK.Set_Parameter("SEARCH_DIRECTION" , Parameters("SEARCH_DIRECTION" )) || !m_OK.Set_Parameter("TARGET_DEFINITION", 1) // grid or grid system || !m_OK.Set_Parameter("PREDICTION" , pResiduals) || !m_OK.Set_Parameter("VARIANCE" , pVariance ) || (!SG_UI_Get_Window_Main() && ( // saga_cmd !m_OK.Set_Parameter("VAR_MAXDIST" , Parameters("VAR_MAXDIST" )) || !m_OK.Set_Parameter("VAR_NCLASSES" , Parameters("VAR_NCLASSES" )) || !m_OK.Set_Parameter("VAR_NSKIP" , Parameters("VAR_NSKIP" )) || !m_OK.Set_Parameter("VAR_MODEL" , Parameters("VAR_MODEL" )))) ) { Error_Set(CSG_String::Format(SG_T("%s [%s].[%s]"), _TL("could not initialize tool"), SG_T("statistics_regression"), m_OK.Get_Name().c_str())); return( false ); } if( !m_OK.Execute() ) { Error_Set(CSG_String::Format(SG_T("%s [%s].[%s]"), _TL("could not execute tool"), SG_T("statistics_regression"), m_OK.Get_Name().c_str()));\ return( false ); } //----------------------------------------------------- #pragma omp parallel for for(int y=0; y<Get_NY(); y++) { for(int x=0; x<Get_NX(); x++) { if( pRegression->is_NoData(x, y) || pResiduals->is_NoData(x, y) ) { pPrediction->Set_NoData(x, y); } else { pPrediction->Add_Value(x, y, pRegression->asDouble(x, y) + pResiduals->asDouble(x, y)); } } } //----------------------------------------------------- pRegression->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Regression"))); pPrediction->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Prediction"))); if( Parameters("RESIDUALS")->asGrid() ) { pResiduals->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Residuals"))); } if( pVariance ) { pVariance ->Set_Name(CSG_String::Format("%s.%s [%s]", Parameters("POINTS")->asGrid()->Get_Name(), Parameters("FIELD")->asString(), _TL("Quality"))); } //----------------------------------------------------- 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 CGridsFromTableAndGrid::On_Execute(void) { int iField, iRecord, iAttribute, nAttributes, *Attribute; sLong iCell, jCell; CSG_Parameter_Grid_List *pGrids; CSG_Grid *pClasses; CSG_Table *pTable; //----------------------------------------------------- pClasses = Parameters("CLASSES" )->asGrid(); pGrids = Parameters("GRIDS" )->asGridList(); pTable = Parameters("TABLE" )->asTable(); iField = Parameters("ID_FIELD")->asInt(); pGrids->Del_Items(); if( !pClasses->Set_Index() ) { Error_Set(_TL("index creation failed")); return( false ); } //----------------------------------------------------- if( pTable->Get_Field_Count() == 0 || pTable->Get_Count() == 0 ) { Message_Add(_TL("selected table contains no valid records")); return( false ); } //----------------------------------------------------- if( !pTable->Set_Index(iField, TABLE_INDEX_Ascending) ) { Message_Add(_TL("failed to create index for table")); return( false ); } //----------------------------------------------------- Attribute = new int[pTable->Get_Field_Count()]; for(iAttribute=0, nAttributes=0; iAttribute<pTable->Get_Field_Count(); iAttribute++) { if( iAttribute != iField && pTable->Get_Field_Type(iAttribute) != SG_DATATYPE_String ) { Attribute[nAttributes++] = iAttribute; CSG_Grid *pGrid = SG_Create_Grid(*Get_System()); pGrid->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pClasses->Get_Name(), pTable->Get_Field_Name(iAttribute))); pGrids->Add_Item(pGrid); } } if( nAttributes == 0 ) { delete[](Attribute); Message_Add(_TL("selected table does not have numeric attributes")); return( false ); } //----------------------------------------------------- CSG_Table_Record *pRecord = pTable->Get_Record_byIndex(0); for(iCell=0, iRecord=0; iCell<Get_NCells() && pRecord && Set_Progress_NCells(iCell); iCell++) { if( pClasses->Get_Sorted(iCell, jCell, false, true) ) { double valClass = pClasses->asDouble(jCell); while( pRecord && pRecord->asDouble(iField) < valClass ) { pRecord = pTable->Get_Record_byIndex(++iRecord); } if( !pRecord || pRecord->asDouble(iField) > valClass ) { for(iAttribute=0; iAttribute<nAttributes; iAttribute++) { pGrids->asGrid(iAttribute)->Set_NoData(jCell); } } else { for(iAttribute=0; iAttribute<nAttributes; iAttribute++) { pGrids->asGrid(iAttribute)->Set_Value(jCell, pRecord->asDouble(Attribute[iAttribute])); } } } } //----------------------------------------------------- delete[](Attribute); return true; }