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

📄 georef_grid.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------
bool CGeoref_Grid::Get_Conversion(void)
{
	int			Interpolation;
	TSG_Grid_Type	Type;
	CSG_Grid		*pSource, *pGrid;
	CSG_Shapes		*pShapes;

	//-----------------------------------------------------
	pSource			= Parameters("SOURCE")->asGrid();

	pGrid			= NULL;
	pShapes			= NULL;

	Interpolation	= Parameters("INTERPOLATION")->asInt();
	Type			= Interpolation == 0 ? pSource->Get_Type() : GRID_TYPE_Float;

	//-----------------------------------------------------
	switch( Parameters("TARGET_TYPE")->asInt() )
	{
	case 0:	// create new user defined grid...
		pGrid	= Get_Target_Userdef(pSource, Type);
		break;

	case 1:	// create new with chosen grid size and fitted extent...
		if( Dlg_Parameters("GET_AUTOFIT") )
		{
			pGrid	= Get_Target_Autofit(
						pSource,
						Get_Parameters("GET_AUTOFIT")->Get_Parameter("GRIDSIZE")		->asDouble(),
						Get_Parameters("GET_AUTOFIT")->Get_Parameter("AUTOEXTMODE")	->asInt(),
						Type
					);
		}
		break;

	case 2:	// select grid project...
		if( Dlg_Parameters("GET_SYSTEM") )
		{
			pGrid	= SG_Create_Grid(
						*Get_Parameters("GET_SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System()
					);
		}
		break;

	case 3:	// select grid...
		if( Dlg_Parameters("GET_GRID") )
		{
			pGrid	= Get_Parameters("GET_GRID")->Get_Parameter("GRID")->asGrid();
		}
		break;

	case 4:	// shapes...
		if( Dlg_Parameters("GET_SHAPES") )
		{
			pShapes	= Get_Parameters("GET_SHAPES")->Get_Parameter("SHAPES")->asShapes();
		}
		break;

	default:
		return( false );
	}

	//-----------------------------------------------------
	if( pShapes )
	{
		Set_Shapes	(pSource, pShapes);

		Parameters("SHAPES")	->Set_Value(pShapes);
	}


	//-----------------------------------------------------
	if( pGrid )
	{
		Set_Grid	(pSource, pGrid, Interpolation);

		Parameters("GRID")		->Set_Value(pGrid);
	}

	//-----------------------------------------------------
	return( true );
}


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

//---------------------------------------------------------
CSG_Grid * CGeoref_Grid::Get_Target_Userdef(CSG_Grid *pSource, TSG_Grid_Type Type)
{
	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=0; y<pSource->Get_NY(); y++, Pt_Source.y+=1)
		{
			Pt_Source.x	= 0;
			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);

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

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

			Pt_Source.y	= pSource->Get_NY();
			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(
					Type,
					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 * CGeoref_Grid::Get_Target_Autofit(CSG_Grid *pSource, double Grid_Size, int AutoExtMode, TSG_Grid_Type Type)
{
	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=0; y<pSource->Get_NY(); y++, Pt_Source.y+=1)
			{
				Pt_Source.x	= 0;
				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);

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

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

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

			break;

		//---------------------------------------------
		case 1:
			for(y=0, Pt_Source.y=0; y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=1)
			{
				for(x=0, Pt_Source.x=0; x<pSource->Get_NX(); x++, Pt_Source.x+=1)
				{
					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(
				Type,
				1 + (int)((xMax - xMin) / Grid_Size),
				1 + (int)((yMax - yMin) / Grid_Size),
				Grid_Size,
				xMin, yMin
			);
		}
	}

	return( pTarget );
}

//---------------------------------------------------------
inline void CGeoref_Grid::Get_MinMax(double &xMin, double &xMax, double &yMin, double &yMax, TSG_Point Point)
{
	if( m_Engine.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;
		}
	}
}


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

//---------------------------------------------------------
bool CGeoref_Grid::Set_Grid(CSG_Grid *pSource, CSG_Grid *pTarget, int Interpolation)
{
	int			x, y;
	double		z;
	TSG_Point	Pt_Source, Pt_Target;

	if( pSource && pTarget )
	{
		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();

		//-------------------------------------------------
		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( m_Engine.Get_Converted(Pt_Source, true) )
				{
					z	= pSource->Get_Value(
							pSource->Get_XMin() + Pt_Source.x * pSource->Get_Cellsize(),
							pSource->Get_YMin() + Pt_Source.y * pSource->Get_Cellsize(),
							Interpolation
						);

					if( !pSource->is_NoData_Value(z) )
					{
						pTarget->Set_Value(x, y, z);
					}
				}
			}
		}

		return( true );
	}

	return( false );
}

//---------------------------------------------------------
bool CGeoref_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=0; y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=1)
		{
			for(x=0, Pt_Source.x=0; x<pSource->Get_NX(); x++, Pt_Source.x+=1)
			{
				if( !pSource->is_NoData(x, y) )
				{
					Pt_Target	= Pt_Source;

					if( m_Engine.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 + -