//--------------------------------------------------------- bool CGEOTRANS_Grid::Get_Target_Extent(CSG_Grid *pSource, TSG_Rect &Extent, bool bEdge) { if( !pSource ) { return( false ); } int x, y; Extent.xMin = Extent.yMin = 1.0; Extent.xMax = Extent.yMax = 0.0; if( bEdge ) { double d; for(y=0, d=pSource->Get_YMin(); y<pSource->Get_NY(); y++, d+=pSource->Get_Cellsize()) { Get_MinMax(Extent, pSource->Get_XMin(), d); Get_MinMax(Extent, pSource->Get_XMax(), d); } for(x=0, d=pSource->Get_XMin(); x<pSource->Get_NX(); x++, d+=pSource->Get_Cellsize()) { Get_MinMax(Extent, d, pSource->Get_YMin()); Get_MinMax(Extent, d, pSource->Get_YMax()); } } else { TSG_Point p; for(y=0, p.y=pSource->Get_YMin(); y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, p.y+=pSource->Get_Cellsize()) { for(x=0, p.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, p.x+=pSource->Get_Cellsize()) { if( !pSource->is_NoData(x, y) ) { Get_MinMax(Extent, p.x, p.y); } } } } return( is_Progress() && Extent.xMin < Extent.xMax && Extent.yMin < Extent.yMax ); }
//--------------------------------------------------------- bool CCRS_Transform_Grid::Get_Target_System(const CSG_Grid_System &System, bool bEdge) { int x, y, Resolution; TSG_Rect Extent; Extent.xMin = Extent.yMin = 1.0; Extent.xMax = Extent.yMax = 0.0; Get_MinMax(Extent, System.Get_XMin(), System.Get_YMin()); Get_MinMax(Extent, System.Get_XMax(), System.Get_YMin()); Get_MinMax(Extent, System.Get_XMin(), System.Get_YMax()); Get_MinMax(Extent, System.Get_XMax(), System.Get_YMax()); Resolution = 256; switch( 1 ) { case 1: // edges { double d; int yStep = 1 + System.Get_NY() / Resolution; for(y=0, d=System.Get_YMin(); y<System.Get_NY(); y+=yStep, d+=yStep*System.Get_Cellsize()) { Get_MinMax(Extent, System.Get_XMin(), d); Get_MinMax(Extent, System.Get_XMax(), d); } int xStep = 1 + System.Get_NX() / Resolution; for(x=0, d=System.Get_XMin(); x<System.Get_NX(); x+=xStep, d+=xStep*System.Get_Cellsize()) { Get_MinMax(Extent, d, System.Get_YMin()); Get_MinMax(Extent, d, System.Get_YMax()); } } break; case 2: // all cells { TSG_Point p; int xStep = 1 + System.Get_NX() / Resolution; int yStep = 1 + System.Get_NY() / Resolution; for(y=0, p.y=System.Get_YMin(); y<System.Get_NY() && Set_Progress(y, System.Get_NY()); y+=yStep, p.y+=yStep*System.Get_Cellsize()) { for(x=0, p.x=System.Get_XMin(); x<System.Get_NX(); x+=xStep, p.x+=xStep*System.Get_Cellsize()) { Get_MinMax(Extent, p.x, p.y); } } } break; } return( is_Progress() && Extent.xMin < Extent.xMax && Extent.yMin < Extent.yMax && m_Grid_Target.Init_User(Extent, System.Get_NY()) && Dlg_Parameters("GET_USER") ); }
//--------------------------------------------------------- bool CPROJ4_Grid::Get_Target_Extent(CSG_Grid *pSource, TSG_Rect &Extent) { if( !pSource ) { return( false ); } int x, y, Resolution; Resolution = 256; Extent.xMin = Extent.yMin = 1.0; Extent.xMax = Extent.yMax = 0.0; switch( 1 ) { case 0: // corners { Get_MinMax(Extent, pSource->Get_XMin(), pSource->Get_YMin()); Get_MinMax(Extent, pSource->Get_XMax(), pSource->Get_YMin()); Get_MinMax(Extent, pSource->Get_XMin(), pSource->Get_YMax()); Get_MinMax(Extent, pSource->Get_XMax(), pSource->Get_YMax()); } break; case 1: // edges { double d; int yStep = 1 + pSource->Get_NY() / Resolution; for(y=0, d=pSource->Get_YMin(); y<pSource->Get_NY(); y+=yStep, d+=yStep*pSource->Get_Cellsize()) { Get_MinMax(Extent, pSource->Get_XMin(), d); Get_MinMax(Extent, pSource->Get_XMax(), d); } int xStep = 1 + pSource->Get_NX() / Resolution; for(x=0, d=pSource->Get_XMin(); x<pSource->Get_NX(); x+=xStep, d+=xStep*pSource->Get_Cellsize()) { Get_MinMax(Extent, d, pSource->Get_YMin()); Get_MinMax(Extent, d, pSource->Get_YMax()); } } break; case 2: // all cells { TSG_Point p; int xStep = 1 + pSource->Get_NX() / Resolution; int yStep = 1 + pSource->Get_NY() / Resolution; for(y=0, p.y=pSource->Get_YMin(); y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y+=yStep, p.y+=yStep*pSource->Get_Cellsize()) { for(x=0, p.x=pSource->Get_XMin(); x<pSource->Get_NX(); x+=xStep, p.x+=xStep*pSource->Get_Cellsize()) { if( !pSource->is_NoData(x, y) ) { Get_MinMax(Extent, p.x, p.y); } } } } break; } return( is_Progress() && Extent.xMin < Extent.xMax && Extent.yMin < Extent.yMax ); }
//--------------------------------------------------------- bool CCRS_Transform_Grid::Set_Target_System(CSG_Parameters *pParameters, int Resolution, bool bEdges) { if( !pParameters || !pParameters->Get_Parameter("SOURCE") || !pParameters->Get_Parameter("CRS_PROJ4") ) { return( false ); } CSG_Grid *pGrid = m_bList ? pParameters->Get_Parameter("SOURCE")->asGridList()->asGrid(0) : pParameters->Get_Parameter("SOURCE")->asGrid(); if( !pGrid || !pGrid->is_Valid() || !pGrid->Get_Projection().is_Okay() || !m_Projector.Set_Target(CSG_Projection(pParameters->Get_Parameter("CRS_PROJ4")->asString(), SG_PROJ_FMT_Proj4)) || !m_Projector.Get_Target().is_Okay() || !m_Projector.Set_Source(pGrid->Get_Projection()) ) { return( false ); } //----------------------------------------------------- int x, y; TSG_Rect Extent; Extent.xMin = Extent.yMin = 1.0; Extent.xMax = Extent.yMax = 0.0; Get_MinMax(Extent, pGrid->Get_XMin(), pGrid->Get_YMin()); Get_MinMax(Extent, pGrid->Get_XMax(), pGrid->Get_YMin()); Get_MinMax(Extent, pGrid->Get_XMin(), pGrid->Get_YMax()); Get_MinMax(Extent, pGrid->Get_XMax(), pGrid->Get_YMax()); //----------------------------------------------------- if( bEdges ) // edges { double d; int yStep = 1 + pGrid->Get_NY() / Resolution; for(y=0, d=pGrid->Get_YMin(); y<pGrid->Get_NY(); y+=yStep, d+=yStep*pGrid->Get_Cellsize()) { Get_MinMax(Extent, pGrid->Get_XMin(), d); Get_MinMax(Extent, pGrid->Get_XMax(), d); } int xStep = 1 + pGrid->Get_NX() / Resolution; for(x=0, d=pGrid->Get_XMin(); x<pGrid->Get_NX(); x+=xStep, d+=xStep*pGrid->Get_Cellsize()) { Get_MinMax(Extent, d, pGrid->Get_YMin()); Get_MinMax(Extent, d, pGrid->Get_YMax()); } } //----------------------------------------------------- else // all cells { TSG_Point p; int xStep = 1 + pGrid->Get_NX() / Resolution; int yStep = 1 + pGrid->Get_NY() / Resolution; for(y=0, p.y=pGrid->Get_YMin(); y<pGrid->Get_NY(); y+=yStep, p.y+=yStep*pGrid->Get_Cellsize()) { for(x=0, p.x=pGrid->Get_XMin(); x<pGrid->Get_NX(); x+=xStep, p.x+=xStep*pGrid->Get_Cellsize()) { Get_MinMax(Extent, p.x, p.y); } } } return( Extent.xMin < Extent.xMax && Extent.yMin < Extent.yMax && m_Grid_Target.Set_User_Defined(pParameters, Extent, pGrid->Get_NY()) && m_Grid_Target.Get_System().is_Valid() ); }