//--------------------------------------------------------- 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 ); }
bool Cdodproperror::SaveGridsAsTIFF(CSG_Grid** grids, CSG_Strings paths) { TSG_Data_Type Type; CSG_String FilePath; CSG_Grid* Grid; // SAVE TIFFS for (int i = 0; i < paths.Get_Count(); i++) { FilePath = paths[i]; Grid = grids[i]; Type = Grid->Get_Type(); if( !GDALDataSet.Open_Write(FilePath, GDALDriver, GDALOptions, Type, 1, *Get_System(), Projection) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), FilePath.c_str())); return( false ); } GDALDataSet.Write(0, Grid); if( !GDALDataSet.Close() ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to close file after writing: "), FilePath.c_str())); return( false ); } } 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 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 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 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 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 ); }
//--------------------------------------------------------- CSG_Grid * CLandsat_Import::Get_Band(const CSG_String &File) { CSG_Data_Manager tmpMgr; if( !tmpMgr.Add(File) || !tmpMgr.Get_Grid_System(0) || !tmpMgr.Get_Grid_System(0)->Get(0) ) { Error_Set(CSG_String::Format(SG_T("%s: %s"), _TL("could not load file"), File.c_str())); return( NULL ); } tmpMgr.Get_Grid_System(0)->Get(0)->Set_NoData_Value(0); // landsat 8 pretends to use a value of 65535 (2^16 - 1) CSG_Grid *pBand = NULL; //----------------------------------------------------- if( !tmpMgr.Get_Grid_System(0)->Get(0)->Get_Projection().is_Okay() ) { // undefined coordinate system, nothing to do be done further... } //----------------------------------------------------- else if( Parameters("PROJECTION")->asInt() == 2 ) // Geographic Coordinates { pBand = Get_Projection((CSG_Grid *)tmpMgr.Get_Grid_System(0)->Get(0), "+proj=longlat +ellps=WGS84 +datum=WGS84"); } //----------------------------------------------------- else // UTM { CSG_Grid *pTmp = (CSG_Grid *)tmpMgr.Get_Grid_System(0)->Get(0); CSG_String Projection = pTmp->Get_Projection().Get_Proj4(); if( Projection.Find("+proj=utm") >= 0 && ( (Projection.Find("+south") >= 0 && Parameters("PROJECTION")->asInt() == 0) || (Projection.Find("+south") < 0 && Parameters("PROJECTION")->asInt() == 1)) && (pBand = SG_Create_Grid(pTmp->Get_Type(), pTmp->Get_NX(), pTmp->Get_NY(), pTmp->Get_Cellsize(), pTmp->Get_XMin(), pTmp->Get_YMin() + (Parameters("PROJECTION")->asInt() == 1 ? 10000000 : -10000000) )) != NULL ) { if( Parameters("PROJECTION")->asInt() == 1 ) Projection.Append (" +south"); else Projection.Replace(" +south", ""); pBand->Get_Projection().Create(Projection, SG_PROJ_FMT_Proj4); pBand->Set_Name (pTmp->Get_Name()); pBand->Set_Description (pTmp->Get_Description()); pBand->Set_NoData_Value_Range(pTmp->Get_NoData_Value(), pTmp->Get_NoData_hiValue()); pBand->Set_Scaling (pTmp->Get_Scaling(), pTmp->Get_Offset()); #pragma omp parallel for for(int y=0; y<pBand->Get_NY(); y++) { for(int x=0; x<pBand->Get_NX(); x++) { pBand->Set_Value(x, y, pTmp->asDouble(x, y)); } } } } //----------------------------------------------------- if( !pBand ) { pBand = (CSG_Grid *)tmpMgr.Get_Grid_System(0)->Get(0); tmpMgr.Delete(tmpMgr.Get_Grid_System(0)->Get(0), true); // make permanent, detach from temporary data manager } return( pBand ); }
//--------------------------------------------------------- bool CWRF_Import::Load(const CSG_String &File) { //----------------------------------------------------- // 00001-00600.00001-00600 // 01234567890123456789012 CSG_String Name = SG_File_Get_Name(File, true); if( Name.Length() != 23 || Name[5] != SG_T('-') || Name[11] != SG_T('.') || Name[17] != SG_T('-') ) { Error_Set(_TL("invalid geogrid file name")); return( false ); } int xOffset = Name.asInt() - 1; int yOffset = Name.AfterFirst(SG_T('.')).asInt() - 1; //----------------------------------------------------- CSG_File Stream; if( !Stream.Open(File, SG_FILE_R) ) { Error_Set(_TL("data file could not be openend")); return( false ); } //----------------------------------------------------- TSG_Data_Type Type; switch( m_Index.m_WORDSIZE ) { default: Error_Set(_TL("invalid word size")); return( false ); case 1: Type = m_Index.m_SIGNED == false ? SG_DATATYPE_Byte : SG_DATATYPE_Char; break; case 2: Type = m_Index.m_SIGNED == false ? SG_DATATYPE_Word : SG_DATATYPE_Short; break; case 4: Type = m_Index.m_SIGNED == false ? SG_DATATYPE_DWord : SG_DATATYPE_Int; break; } //----------------------------------------------------- char *pLine, *pValue; int x, y, nBytes_Line; nBytes_Line = (m_Index.m_TILE_X + 2 * m_Index.m_TILE_BDR) * m_Index.m_WORDSIZE; pLine = (char *)SG_Malloc(nBytes_Line); //----------------------------------------------------- for(int z=m_Index.m_TILE_Z_START; z<=m_Index.m_TILE_Z_END && !Stream.is_EOF() && Process_Get_Okay(); z++) { CSG_Grid *pGrid = SG_Create_Grid( Type, m_Index.m_TILE_X + 2 * m_Index.m_TILE_BDR, m_Index.m_TILE_Y + 2 * m_Index.m_TILE_BDR, m_Index.m_DX, m_Index.m_KNOWN_LON + (xOffset - m_Index.m_TILE_BDR) * m_Index.m_DX, m_Index.m_KNOWN_LAT + (yOffset - m_Index.m_TILE_BDR) * m_Index.m_DY ); pGrid->Set_Name (CSG_String::Format(SG_T("%s_%02d"), SG_File_Get_Name(File, false).c_str(), z)); pGrid->Set_Description (m_Index.m_DESCRIPTION); pGrid->Set_Unit (m_Index.m_UNITS); pGrid->Set_NoData_Value (m_Index.m_MISSING_VALUE); pGrid->Set_Scaling (m_Index.m_SCALE_FACTOR); Parameters("GRIDS")->asGridList()->Add_Item(pGrid); //------------------------------------------------- for(y=0; y<pGrid->Get_NY() && !Stream.is_EOF() && Set_Progress(y, pGrid->Get_NY()); y++) { int yy = m_Index.m_ROW_ORDER == VAL_TOP_BOTTOM ? pGrid->Get_NY() - 1 - y : y; Stream.Read(pLine, sizeof(char), nBytes_Line); for(x=0, pValue=pLine; x<pGrid->Get_NX(); x++, pValue+=m_Index.m_WORDSIZE) { if( m_Index.m_ENDIAN == VAL_ENDIAN_BIG ) { SG_Swap_Bytes(pValue, m_Index.m_WORDSIZE); } switch( pGrid->Get_Type() ) { case SG_DATATYPE_Byte: pGrid->Set_Value(x, yy, *(unsigned char *)pValue); break; // 1 Byte Integer (unsigned) case SG_DATATYPE_Char: pGrid->Set_Value(x, yy, *(signed char *)pValue); break; // 1 Byte Integer (signed) case SG_DATATYPE_Word: pGrid->Set_Value(x, yy, *(unsigned short *)pValue); break; // 2 Byte Integer (unsigned) case SG_DATATYPE_Short: pGrid->Set_Value(x, yy, *(signed short *)pValue); break; // 2 Byte Integer (signed) case SG_DATATYPE_DWord: pGrid->Set_Value(x, yy, *(unsigned int *)pValue); break; // 4 Byte Integer (unsigned) case SG_DATATYPE_Int: pGrid->Set_Value(x, yy, *(signed int *)pValue); break; // 4 Byte Integer (signed) } } } } //----------------------------------------------------- SG_Free(pLine); 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( (pX = m_Grid_Target.Get_Grid("OUT_X")) != NULL ) { pX->Assign_NoData(); pX->Set_Name(_TL("X Coordinates")); pX->Get_Projection().Create(m_Projector.Get_Target()); } if( (pY = m_Grid_Target.Get_Grid("OUT_Y")) != NULL ) { pY->Assign_NoData(); pY->Set_Name(_TL("Y Coordinates")); 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); bool bKeepType = m_Resampling == GRID_RESAMPLING_NearestNeighbour || Parameters("KEEP_TYPE")->asBool(); //----------------------------------------------------- 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, bKeepType ? pSource->Get_Type() : SG_DATATYPE_Float); if( pTarget ) { pTargets->Add_Item(pTarget); pTarget->Set_NoData_Value_Range (pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue()); pTarget->Set_Scaling (pSource->Get_Scaling(), pSource->Get_Offset()); pTarget->Set_Name (pSource->Get_Name()); pTarget->Set_Unit (pSource->Get_Unit()); pTarget->Get_Projection().Create(m_Projector.Get_Target()); pTarget->Assign_NoData(); CSG_Parameters Parms; if( DataObject_Get_Parameters(pSource, Parms) ) { DataObject_Add(pTarget); DataObject_Set_Parameters(pTarget, Parms); } } } //------------------------------------------------- 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( bGeogCS_Adjust ) { if( xSource < 0.0 ) { xSource += 360.0; } else if( xSource >= 360.0 ) { xSource -= 360.0; } } if( pX ) pX->Set_Value(x, y, xSource); if( pY ) pY->Set_Value(x, y, ySource); for(i=0; i<pSources->Get_Count(); i++) { if( pSources->asGrid(i)->Get_Value(xSource, ySource, z, m_Resampling, false, true) ) { pTargets->asGrid(n + i)->Set_Value(x, y, z); } } } } } //----------------------------------------------------- m_Target_Area.Destroy(); return( true ); }
//--------------------------------------------------------- bool CGeoref_Grid::Get_Conversion(void) { //----------------------------------------------------- CSG_Rect Extent; CSG_Grid *pSource = Parameters("GRID")->asGrid(); //----------------------------------------------------- if( !Get_Target_Extent(Extent, true) || !m_Grid_Target.Set_User_Defined(Get_Parameters("TARGET"), Extent, pSource->Get_NY()) ) { Error_Set(_TL("failed to estimate target extent")); return( false ); } if( !Dlg_Parameters("TARGET") ) { return( false ); } //----------------------------------------------------- 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; } CSG_Grid *pReferenced = m_Grid_Target.Get_Grid(Resampling == GRID_RESAMPLING_NearestNeighbour ? pSource->Get_Type() : SG_DATATYPE_Float); if( !pReferenced ) { Error_Set(_TL("failed to initialize target grid")); return( false ); } //----------------------------------------------------- if( !Set_Grid(pSource, pReferenced, Resampling) ) { Error_Set(_TL("failed to project target grid")); return( false ); } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pSource, P) ) { DataObject_Add(pReferenced); DataObject_Set_Parameters(pReferenced, P); } //----------------------------------------------------- return( true ); }