//--------------------------------------------------------- inline void CGEOTRANS_Grid::Get_MinMax(TSG_Rect &r, double x, double y) { if( Get_Converted(x, y) ) { if( r.xMin > r.xMax ) { r.xMin = r.xMax = x; } else if( r.xMin > x ) { r.xMin = x; } else if( r.xMax < x ) { r.xMax = x; } if( r.yMin > r.yMax ) { r.yMin = r.yMax = y; } else if( r.yMin > y ) { r.yMin = y; } else if( r.yMax < y ) { r.yMax = y; } } }
//--------------------------------------------------------- bool CGEOTRANS_Grid::Set_Shapes(CSG_Grid *pSource, CSG_Shapes *pTarget) { int x, y; TSG_Point Pt_Source, Pt_Target; CSG_Shape *pShape; if( pSource && pTarget ) { pTarget->Create(SHAPE_TYPE_Point, pSource->Get_Name()); pTarget->Add_Field("Z", SG_DATATYPE_Double); for(y=0, Pt_Source.y=pSource->Get_YMin(); y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=pSource->Get_Cellsize()) { for(x=0, Pt_Source.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, Pt_Source.x+=pSource->Get_Cellsize()) { if( !pSource->is_NoData(x, y) ) { Pt_Target = Pt_Source; if( Get_Converted(Pt_Target) ) { pShape = pTarget->Add_Shape(); pShape->Add_Point(Pt_Target); pShape->Set_Value(0, pSource->asDouble(x, y)); } } } } return( true ); } return( false ); }
//--------------------------------------------------------- bool CPROJ4_Grid::Set_Shapes(CSG_Parameter_Grid_List *pSources, CSG_Shapes *pTarget) { int x, y, i; double z; TSG_Point Pt_Source, Pt_Target; CSG_Grid *pSource; CSG_Shape *pShape; if( pSources && pSources->Get_Count() > 0 && pTarget ) { pSource = pSources->asGrid(0); pTarget->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pSource->Get_Name(), Get_Proj_Name().c_str())); for(i=0; i<pSources->Get_Count(); i++) { pTarget->Add_Field(pSources->asGrid(i)->Get_Name(), pSources->asGrid(i)->Get_Type()); } for(y=0, Pt_Source.y=pSource->Get_YMin(); y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=pSource->Get_Cellsize()) { for(x=0, Pt_Source.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, Pt_Source.x+=pSource->Get_Cellsize()) { if( !pSource->is_NoData(x, y) ) { Pt_Target = Pt_Source; if( Get_Converted(Pt_Target) ) { pShape = pTarget->Add_Shape(); pShape->Add_Point(Pt_Target); for(i=0; i<pSources->Get_Count(); i++) { if( pSources->asGrid(i)->Get_Value(Pt_Source, z, m_Interpolation) ) { pShape->Set_Value(i, z); } else { pShape->Set_NoData(i); } } } } } } return( true ); } return( false ); }
//--------------------------------------------------------- bool CPROJ4_Shapes::_Get_Conversion(CSG_Shapes *pSource, CSG_Shapes *pTarget) { if( pSource && pSource->is_Valid() && pTarget ) { int nDropped = 0; Process_Set_Text(CSG_String::Format(SG_T("%s: %s"), _TL("Processing"), pSource->Get_Name())); pTarget->Create(pSource->Get_Type(), CSG_String::Format(SG_T("%s [%s]"), pSource->Get_Name(), Get_Proj_Name().c_str()), pSource); for(int iShape=0; iShape<pSource->Get_Count() && Set_Progress(iShape, pSource->Get_Count()); iShape++) { CSG_Shape *pShape_Source = pSource->Get_Shape(iShape); CSG_Shape *pShape_Target = pTarget->Add_Shape(pShape_Source, SHAPE_COPY_ATTR); bool bDropped = false; for(int iPart=0; iPart<pShape_Source->Get_Part_Count() && !bDropped; iPart++) { for(int iPoint=0; iPoint<pShape_Source->Get_Point_Count(iPart) && !bDropped; iPoint++) { TSG_Point Point = pShape_Source->Get_Point(iPoint, iPart); if( Get_Converted(Point.x, Point.y) ) { pShape_Target->Add_Point(Point.x, Point.y, iPart); } else { bDropped = true; } } } if( bDropped ) { nDropped++; pTarget->Del_Shape(pShape_Target); } } if( nDropped > 0 ) { Message_Add(CSG_String::Format(SG_T("%d %s"), nDropped, _TL("shapes have been dropped"))); } return( pTarget->Get_Count() > 0 ); } return( false ); }
//--------------------------------------------------------- bool CPROJ4_Grid::Set_Grids(CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets) { if( !pSources || pSources->Get_Count() < 1 || !pTargets || pTargets->Get_Count() != pSources->Get_Count() || !Set_Inverse() ) { return( false ); } //------------------------------------------------- int x, y, i; double z; TSG_Point Pt_Source, Pt_Target; CSG_Grid_System System; CSG_Grid *pX, *pY; System = pTargets->asGrid(0)->Get_System(); Init_XY(System, &pX, &pY); //------------------------------------------------- for(y=0, Pt_Target.y=System.Get_YMin(); y<System.Get_NY() && Set_Progress(y, System.Get_NY()); y++, Pt_Target.y+=System.Get_Cellsize()) { for(x=0, Pt_Target.x=System.Get_XMin(); x<System.Get_NX(); x++, Pt_Target.x+=System.Get_Cellsize()) { Pt_Source = Pt_Target; if( Get_Converted(Pt_Source) ) { if( pX ) pX->Set_Value(x, y, Pt_Source.x); if( pY ) pY->Set_Value(x, y, Pt_Source.y); for(i=0; i<pSources->Get_Count(); i++) { if( pSources->asGrid(i)->Get_Value(Pt_Source, z, m_Interpolation) ) { pTargets->asGrid(i)->Set_Value(x, y, z); } } } } } return( true ); }
//--------------------------------------------------------- bool CPROJ4_Grid::Set_Grid(CSG_Grid *pSource, CSG_Grid *pTarget) { if( pSource && pTarget && Set_Inverse() ) { int x, y; double z; TSG_Point Pt_Source, Pt_Target; CSG_Grid *pX, *pY; Init_XY(pTarget->Get_System(), &pX, &pY); Init_Target(pSource, pTarget); //------------------------------------------------- for(y=0, Pt_Target.y=pTarget->Get_YMin(); y<pTarget->Get_NY() && Set_Progress(y, pTarget->Get_NY()); y++, Pt_Target.y+=pTarget->Get_Cellsize()) { for(x=0, Pt_Target.x=pTarget->Get_XMin(); x<pTarget->Get_NX(); x++, Pt_Target.x+=pTarget->Get_Cellsize()) { Pt_Source = Pt_Target; if( Get_Converted(Pt_Source) ) { if( pX ) pX->Set_Value(x, y, Pt_Source.x); if( pY ) pY->Set_Value(x, y, Pt_Source.y); if( pSource->Get_Value(Pt_Source, z, m_Interpolation) ) { pTarget->Set_Value(x, y, z); } } } } return( true ); } return( false ); }
//--------------------------------------------------------- bool CGEOTRANS_Grid::Set_Grid(CSG_Grid *pSource, CSG_Grid *pTarget, int Interpol) { int x, y; double z; TSG_Point Pt_Source, Pt_Target; CSG_Grid *pX, *pY; if( pSource && pTarget && Set_Transformation_Inverse() ) { 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->Assign_NoData(); if( Parameters("CREATE_XY")->asBool() ) { pX = SG_Create_Grid(pTarget->Get_System(), SG_DATATYPE_Float); pX->Assign_NoData(); pX->Set_Name(_TL("X-Coordinate")); Parameters("OUT_X")->Set_Value(pX); pY = SG_Create_Grid(pTarget->Get_System(), SG_DATATYPE_Float); pY->Assign_NoData(); pY->Set_Name(_TL("Y-Coordinate")); Parameters("OUT_Y")->Set_Value(pY); } else { pX = pY = NULL; } //------------------------------------------------- for(y=0, Pt_Target.y=pTarget->Get_YMin(); y<pTarget->Get_NY() && Set_Progress(y, pTarget->Get_NY()); y++, Pt_Target.y+=pTarget->Get_Cellsize()) { for(x=0, Pt_Target.x=pTarget->Get_XMin(); x<pTarget->Get_NX(); x++, Pt_Target.x+=pTarget->Get_Cellsize()) { Pt_Source = Pt_Target; if( Get_Converted(Pt_Source) ) { if( pSource->Get_Value(Pt_Source, z, Interpol) ) { pTarget->Set_Value(x, y, z); } if( pX && pY ) { pX->Set_Value(x, y, Pt_Source.x); pY->Set_Value(x, y, Pt_Source.y); } } } } return( true ); } return( false ); }