//--------------------------------------------------------- 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 CCRU_Table_Import::On_Execute(void) { //----------------------------------------------------- CSG_File File; if( !File.Open(Parameters("FILE")->asString(), SG_FILE_R, false) ) { Error_Fmt("%s [%s]", _TL("could not open file"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- CSG_String sLine; if( !File.Read_Line(sLine) ) { Error_Fmt("%s [%s]", _TL("failed to read header"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- int nx, ny, nMonths; double Cellsize, xMin, yMin, xMax, yMax; if( !File.Scan(Cellsize) || !File.Scan(xMin ) || !File.Scan(yMin ) || !File.Scan(xMax ) || !File.Scan(yMax ) || !File.Scan(nx ) || !File.Scan(ny ) || !File.Scan(nMonths ) ) { Error_Fmt("%s [%s]", _TL("failed to read header"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- CSG_Grid_System System(Cellsize, xMin, yMin, nx, ny); if( !System.is_Valid() || System.Get_XMax() != xMax || System.Get_YMax() != yMax ) { Error_Fmt("%s [%s]", _TL("failed to read header"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- bool bShift = Parameters("SHIFT")->asBool(); if( bShift ) { System.Assign(Cellsize, xMin - 180.0, yMin, nx, ny); } //----------------------------------------------------- CSG_String Name = SG_File_Get_Name(Parameters("FILE")->asString(), false); Parameters("GRIDS")->asGridList()->Del_Items(); for(int iMonth=0; iMonth<nMonths && !File.is_EOF() && Process_Get_Okay(); iMonth++) { Process_Set_Text("%s %d", _TL("Band"), 1 + iMonth); CSG_Grid *pGrid = SG_Create_Grid(System, SG_DATATYPE_Short); pGrid->Fmt_Name("%s_%02d", Name.c_str(), 1 + iMonth); pGrid->Set_NoData_Value(-9999); pGrid->Get_Projection().Set_GCS_WGS84(); Parameters("GRIDS")->asGridList()->Add_Item(pGrid); //------------------------------------------------- for(int y=0; y<ny && !File.is_EOF() && Set_Progress(y, ny); y++) { if( File.Read_Line(sLine) && sLine.Length() >= 5. * nx ) { for(int x=0, xx=bShift?nx/2:x, yy=ny-1-y; x<nx; x++, xx++) { double z; CSG_String s = sLine.Mid(x * 5, 5); if( s.asDouble(z) ) { pGrid->Set_Value(xx % nx, yy, z); } else { pGrid->Set_NoData(xx % nx, yy); } } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CCRS_Transform_Grid::On_Execute_Transformation(void) { switch( Parameters("RESAMPLING")->asInt() ) { default: m_Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: m_Resampling = GRID_RESAMPLING_Bilinear ; break; case 2: m_Resampling = GRID_RESAMPLING_BicubicSpline ; break; case 3: m_Resampling = GRID_RESAMPLING_BSpline ; break; } //----------------------------------------------------- if( m_bList ) { int i; CSG_Parameters Grids; CSG_Parameter_Grid_List *pSources, *pTargets, *pGrids; pSources = Parameters("SOURCE")->asGridList(); pTargets = Parameters("GRIDS" )->asGridList(); pTargets->Del_Items(); pGrids = Grids.Add_Grid_List(NULL, "GRD", SG_T(""), SG_T(""), PARAMETER_INPUT, false)->asGridList(); for(i=pSources->Get_Count()-1; i>=0; i--) { if( pSources->asGrid(i)->Get_Projection().is_Okay() ) { pGrids->Add_Item(pSources->asGrid(i)); } else { Error_Fmt("%s: %s\n", _TL("unknown projection"), pSources->asGrid(i)->Get_Name()); } } pSources = Grids.Add_Grid_List(NULL, "SRC", SG_T(""), SG_T(""), PARAMETER_INPUT, false)->asGridList(); while( pGrids->Get_Count() > 0 ) { pSources->Add_Item(pGrids->asGrid(pGrids->Get_Count() - 1)); pGrids ->Del_Item(pGrids->Get_Count() - 1); for(i=pGrids->Get_Count()-1; i>=0; i--) { if( pGrids->asGrid(i)->Get_Projection() == pSources->asGrid(0)->Get_Projection() ) { pSources->Add_Item(pGrids->asGrid(i)); pGrids ->Del_Item(i); } } m_Projector.Set_Inverse(false); Transform(pSources); pSources->Del_Items(); } return( pTargets->Get_Count() > 0 ); } //----------------------------------------------------- else { return( Transform(Parameters("SOURCE")->asGrid()) ); } }