//--------------------------------------------------------- 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 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( (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 ); }