⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geotrans_grid.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			pParameters->Get_Parameter("YMAX")->Set_Value((yMax = yMin + ((int)((yMax - yMin) / size)) * size));
		}
		else 
		{
			if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMIN")) )
			{
				if( xMin >= xMax )
				{
					xMin	= xMax - pParameters->Get_Parameter("NX")->asInt() * size;
					pParameter->Set_Value(xMin);
				}

				pParameters->Get_Parameter("XMAX")->Set_Value(xMin + ((int)((xMax - xMin) / size)) * size);
			}
			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMAX")) )
			{
				if( xMin >= xMax )
				{
					xMax	= xMin + pParameters->Get_Parameter("NX")->asInt() * size;
					pParameter->Set_Value(xMax);
				}

				pParameters->Get_Parameter("XMIN")->Set_Value(xMax - ((int)((xMax - xMin) / size)) * size);
			}
			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMIN")) )
			{
				if( yMin >= yMax )
				{
					yMin	= yMax - pParameters->Get_Parameter("NY")->asInt() * size;
					pParameter->Set_Value(yMin);
				}

				pParameters->Get_Parameter("YMAX")->Set_Value(yMin + ((int)((yMax - yMin) / size)) * size);
			}
			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMAX")) )
			{
				if( yMin >= yMax )
				{
					yMax	= yMin + pParameters->Get_Parameter("NY")->asInt() * size;
					pParameter->Set_Value(yMax);
				}

				pParameters->Get_Parameter("YMIN")->Set_Value(yMax - ((int)((yMax - yMin) / size)) * size);
			}
		}

		pParameters->Get_Parameter("NX")->Set_Value(1 + (int)((xMax - xMin) / size));
		pParameters->Get_Parameter("NY")->Set_Value(1 + (int)((yMax - yMin) / size));

		return( true );
	}

	return( false );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
inline void CGEOTRANS_Grid::Get_MinMax(double &xMin, double &xMax, double &yMin, double &yMax, TSG_Point Point)
{
	if( Get_Converted(Point) )
	{
		if( xMin > xMax )
		{
			xMin	= xMax	= Point.x;
		}
		else if( xMin > Point.x )
		{
			xMin	= Point.x;
		}
		else if( xMax < Point.x )
		{
			xMax	= Point.x;
		}

		if( yMin > yMax )
		{
			yMin	= yMax	= Point.y;
		}
		else if( yMin > Point.y )
		{
			yMin	= Point.y;
		}
		else if( yMax < Point.y )
		{
			yMax	= Point.y;
		}
	}
}

//---------------------------------------------------------
CSG_Grid * CGEOTRANS_Grid::Get_Target_Userdef(CSG_Grid *pSource, bool bNearest)
{
	int			x, y;
	double		xMin, yMin, xMax, yMax, size;
	TSG_Point	Pt_Source;
	CSG_Grid		*pTarget;
	CSG_Parameters	*pParameters;

	pTarget	= NULL;

	if( pSource )
	{
		//-------------------------------------------------
		xMin	= yMin	= 1.0;
		xMax	= yMax	= 0.0;

		for(y=0, Pt_Source.y=pSource->Get_YMin(); y<pSource->Get_NY(); y++, Pt_Source.y+=pSource->Get_Cellsize())
		{
			Pt_Source.x	= pSource->Get_XMin();
			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);

			Pt_Source.x	= pSource->Get_XMax();
			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
		}

		for(x=0, Pt_Source.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, Pt_Source.x+=pSource->Get_Cellsize())
		{
			Pt_Source.y	= pSource->Get_YMin();
			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);

			Pt_Source.y	= pSource->Get_YMax();
			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
		}

		//-------------------------------------------------
		if( xMin < xMax && yMin < yMax )
		{
			pParameters	= Get_Parameters("GET_USER");

			pParameters->Get_Parameter("XMIN")->Set_Value(xMin);
			pParameters->Get_Parameter("XMAX")->Set_Value(xMax);
			pParameters->Get_Parameter("YMIN")->Set_Value(yMin);
			pParameters->Get_Parameter("YMAX")->Set_Value(yMax);
			size	= (xMax - xMin) / 100.0;
			pParameters->Get_Parameter("SIZE")->Set_Value(size);
			pParameters->Get_Parameter("NX")->Set_Value(1 + (int)((xMax - xMin) / size));
			pParameters->Get_Parameter("NY")->Set_Value(1 + (int)((yMax - yMin) / size));

			if( Dlg_Parameters("GET_USER") )
			{
				size	= pParameters->Get_Parameter("SIZE")->asDouble();

				pTarget	= SG_Create_Grid(
					bNearest ? pSource->Get_Type() : GRID_TYPE_Float,
					pParameters->Get_Parameter("NX")->asInt(),
					pParameters->Get_Parameter("NY")->asInt(),
					size,
					pParameters->Get_Parameter("XMIN")->asDouble(),
					pParameters->Get_Parameter("YMIN")->asDouble()
				);
			}
		}
	}

	return( pTarget );
}

//---------------------------------------------------------
CSG_Grid * CGEOTRANS_Grid::Get_Target_Autofit(CSG_Grid *pSource, double Grid_Size, int AutoExtMode, bool bNearest)
{
	int			x, y;
	double		xMin, yMin, xMax, yMax;
	TSG_Point	Pt_Source;
	CSG_Grid		*pTarget;

	pTarget	= NULL;

	if( pSource )
	{
		xMin	= yMin	= 1.0;
		xMax	= yMax	= 0.0;

		//---------------------------------------------
		switch( AutoExtMode )
		{
		case 0:	default:
			for(y=0, Pt_Source.y=pSource->Get_YMin(); y<pSource->Get_NY(); y++, Pt_Source.y+=pSource->Get_Cellsize())
			{
				Pt_Source.x	= pSource->Get_XMin();
				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);

				Pt_Source.x	= pSource->Get_XMax();
				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
			}

			for(x=0, Pt_Source.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, Pt_Source.x+=pSource->Get_Cellsize())
			{
				Pt_Source.y	= pSource->Get_YMin();
				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);

				Pt_Source.y	= pSource->Get_YMax();
				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
			}

			break;

		//---------------------------------------------
		case 1:
			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) )
					{
						Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
					}
				}
			}

			break;
		}

		//---------------------------------------------
		if( is_Progress() && xMin < xMax && yMin < yMax )
		{
			pTarget	= SG_Create_Grid(
				bNearest ? pSource->Get_Type() : GRID_TYPE_Float,
				1 + (int)((xMax - xMin) / Grid_Size),
				1 + (int)((yMax - yMin) / Grid_Size),
				Grid_Size,
				xMin, yMin
			);
		}
	}

	return( pTarget );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
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_ZFactor(pSource->Get_ZFactor());
		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(), GRID_TYPE_Float);
			pX->Assign_NoData();
			pX->Set_Name(_TL("X-Coordinate"));
			Parameters("OUT_X")->Set_Value(pX);

			pY	= SG_Create_Grid(pTarget->Get_System(), GRID_TYPE_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 );
}

//---------------------------------------------------------
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->Get_Table().Add_Field("Z", TABLE_FIELDTYPE_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->Get_Record()->Set_Value(0, pSource->asDouble(x, y));
					}
				}
			}
		}

		return( true );
	}

	return( false );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -