//--------------------------------------------------------- bool CGrid_Merge::Set_Target(CSG_Parameters *pParameters, CSG_Parameter_Grid_List *pGrids) { if( pParameters && pGrids && pGrids->Get_Count() > 0 ) { double d = pGrids->asGrid(0)->Get_Cellsize(); CSG_Rect r = pGrids->asGrid(0)->Get_Extent(); for(int i=1; i<pGrids->Get_Count(); i++) { if( d > pGrids->asGrid(i)->Get_Cellsize() ) { d = pGrids->asGrid(i)->Get_Cellsize(); } r.Union(pGrids->asGrid(i)->Get_Extent()); } int nx = 1 + (int)(r.Get_XRange() / d); int ny = 1 + (int)(r.Get_YRange() / d); m_Grid_Target.Set_User_Defined(pParameters, r.Get_XMin(), r.Get_YMin(), d, nx, ny); } return( false ); }
//--------------------------------------------------------- bool CGCS_Graticule::Get_Extent(const CSG_Rect &Extent, CSG_Rect &r) { if( m_Projector.Set_Inverse() ) { double x, y, d; CSG_Point p(Extent.Get_XMin(), Extent.Get_YMin()); m_Projector.Get_Projection(p); r.Assign(p, p); d = Extent.Get_XRange() / 10.0; for(y=Extent.Get_YMin(), x=Extent.Get_XMin(); x<=Extent.Get_XMax(); x+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } for(y=Extent.Get_YMax(), x=Extent.Get_XMin(); x<=Extent.Get_XMax(); x+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } d = Extent.Get_YRange() / 10.0; for(x=Extent.Get_XMin(), y=Extent.Get_YMin(); y<=Extent.Get_YMax(); y+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } for(x=Extent.Get_XMax(), y=Extent.Get_YMin(); y<=Extent.Get_YMax(); y+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } m_Projector.Set_Inverse(false); if( r.Get_XMin() < -180 ) r.m_rect.xMin = -180; else if( r.Get_XMax() > 180 ) r.m_rect.xMax = 180; if( r.Get_YMin() < -90 ) r.m_rect.yMin = -90; else if( r.Get_YMax() > 90 ) r.m_rect.yMax = 90; return( r.Get_XRange() > 0.0 && r.Get_YRange() > 0.0 ); } return( false ); }
//--------------------------------------------------------- inline void CGeoref_Grid::Add_Target_Extent(CSG_Rect &Extent, double x, double y) { if( m_Engine.Get_Converted(x, y) ) { if( Extent.Get_XRange() >= 0.0 && Extent.Get_YRange() >= 0.0 ) { Extent.Union(CSG_Point(x, y)); } else { Extent.Assign(x, y, x, y); } } }
//--------------------------------------------------------- bool CGrid_Rectangle_Clip::On_Execute(void) { CSG_Grid *pGrid_in, *pGrid_out; CSG_Shapes *pShapes; int iMethod; //----------------------------------------------------- pGrid_in = Parameters("INPUT") ->asGrid(); pShapes = Parameters("SHAPES") ->asShapes(); iMethod = Parameters("BORDER") ->asInt(); //----------------------------------------------------- CSG_Rect Extent; if( pShapes->Get_Selection_Count() > 0 ) { bool bFirst = true; for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { if( pShapes->Get_Shape(iShape)->is_Selected() ) { if( bFirst ) { Extent = pShapes->Get_Shape(iShape)->Get_Extent(); bFirst = false; } else { Extent.Union(pShapes->Get_Shape(iShape)->Get_Extent()); } } } } else Extent = pShapes->Get_Extent(); //----------------------------------------------------- if( iMethod == 0 ) { Extent.Deflate(0.5 * pGrid_in->Get_Cellsize(), 0.5 * pGrid_in->Get_Cellsize(), false); } else if( iMethod == 2 ) { double d, minX, minY; d = Extent.Get_XMin() - pGrid_in->Get_XMin(true); minX = pGrid_in->Get_XMin(true) + floor(d / pGrid_in->Get_Cellsize()) * pGrid_in->Get_Cellsize() + 0.5 * pGrid_in->Get_Cellsize(); d = Extent.Get_YMin() - pGrid_in->Get_YMin(true); minY = pGrid_in->Get_YMin(true) + floor(d / pGrid_in->Get_Cellsize()) * pGrid_in->Get_Cellsize() + 0.5 * pGrid_in->Get_Cellsize(); Extent.Set_BottomLeft(minX, minY); } CSG_Grid_System GridSystem(pGrid_in->Get_Cellsize(), Extent); pGrid_out = SG_Create_Grid(GridSystem, pGrid_in->Get_Type()); pGrid_out->Set_NoData_Value(pGrid_in->Get_NoData_Value()); pGrid_out->Set_Name(CSG_String::Format(SG_T("%s_clip"), pGrid_in->Get_Name())); pGrid_out->Assign_NoData(); //----------------------------------------------------- for(int y=0; y<pGrid_out->Get_NY() && Set_Progress(y, pGrid_out->Get_NY()); y++) { #pragma omp parallel for for(int x=0; x<pGrid_out->Get_NX(); x++) { double xWorld = GridSystem.Get_xGrid_to_World(x); double yWorld = GridSystem.Get_yGrid_to_World(y); int xGrid, yGrid; pGrid_in->Get_System().Get_World_to_Grid(xGrid, yGrid, xWorld, yWorld); if (pGrid_in->is_InGrid(xGrid, yGrid)) pGrid_out->Set_Value(x, y, pGrid_in->asDouble(xGrid, yGrid)); } } //----------------------------------------------------- Parameters("OUTPUT")->Set_Value(pGrid_out); return( true ); }