//---------------------------------------------------------
bool CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets, const CSG_Grid_System &Target_System)
{
	if( !m_Projector.Set_Inverse(true) || !pTargets || !pSources || pSources->Get_Count() < 1 )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	*pX, *pY;

	if( !Parameters("CREATE_XY")->asBool() )
	{
		pX	= pY	= NULL;
	}
	else
	{
		Parameters("OUT_X")->Set_Value(pX	= SG_Create_Grid(Target_System, SG_DATATYPE_Float));
		pX->Assign_NoData();
		pX->Set_Name(_TL("X-Coordinate"));
		pX->Get_Projection().Create(m_Projector.Get_Target());

		Parameters("OUT_Y")->Set_Value(pY	= SG_Create_Grid(Target_System, SG_DATATYPE_Float));
		pY->Assign_NoData();
		pY->Set_Name(_TL("Y-Coordinate"));
		pY->Get_Projection().Create(m_Projector.Get_Target());
	}

	//-----------------------------------------------------
	bool	bGeogCS_Adjust	= m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pSources->asGrid(0)->Get_System().Get_XMax() > 180.0;

	Set_Target_Area(pSources->asGrid(0)->Get_System(), Target_System);

	//-----------------------------------------------------
	int	i, n	= pTargets->Get_Count();

	for(i=0; i<pSources->Get_Count(); i++)
	{
		CSG_Grid	*pSource	= pSources->asGrid(i);
		CSG_Grid	*pTarget	= SG_Create_Grid(Target_System, m_Interpolation == 0 ? pSource->Get_Type() : SG_DATATYPE_Float);

		if( pTarget )
		{
			pTarget->Set_NoData_Value_Range	(pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue());
			pTarget->Set_ZFactor			(pSource->Get_ZFactor());
			pTarget->Set_Name				(CSG_String::Format(SG_T("%s"), pSource->Get_Name()));
			pTarget->Set_Unit				(pSource->Get_Unit());
			pTarget->Assign_NoData();
			pTarget->Get_Projection().Create(m_Projector.Get_Target());

			pTargets->Add_Item(pTarget);
		}
	}

	//-------------------------------------------------
	for(int y=0; y<Target_System.Get_NY() && Set_Progress(y, Target_System.Get_NY()); y++)
	{
		double	yTarget	= Target_System.Get_YMin() + y * Target_System.Get_Cellsize();

		#pragma omp parallel for private(i)
		for(int x=0; x<Target_System.Get_NX(); x++)
		{
			double	z, ySource, xSource	= Target_System.Get_XMin() + x * Target_System.Get_Cellsize();

			if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) )
			{
				if( pX )	pX->Set_Value(x, y, xSource);
				if( pY )	pY->Set_Value(x, y, ySource);

				if( bGeogCS_Adjust && xSource < 0.0 )
				{
					xSource	+= 360.0;
				}

				for(i=0; i<pTargets->Get_Count(); i++)
				{
					if( pSources->asGrid(i)->Get_Value(xSource, ySource, z, m_Interpolation) )
					{
						pTargets->asGrid(n + i)->Set_Value(x, y, z);
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	m_Target_Area.Destroy();

	return( true );
}
Example #2
0
//---------------------------------------------------------
bool CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets, const CSG_Grid_System &Target_System)
{
	if( !m_Projector.Set_Inverse(true) || !pTargets || !pSources || pSources->Get_Count() < 1 )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	*pX, *pY;

	if( (pX = m_Grid_Target.Get_Grid("OUT_X")) != NULL )
	{
		pX->Assign_NoData();
		pX->Set_Name(_TL("X Coordinates"));
		pX->Get_Projection().Create(m_Projector.Get_Target());
	}

	if( (pY = m_Grid_Target.Get_Grid("OUT_Y")) != NULL )
	{
		pY->Assign_NoData();
		pY->Set_Name(_TL("Y Coordinates"));
		pY->Get_Projection().Create(m_Projector.Get_Target());
	}

	//-----------------------------------------------------
	bool	bGeogCS_Adjust	= m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pSources->asGrid(0)->Get_System().Get_XMax() > 180.0;

	Set_Target_Area(pSources->asGrid(0)->Get_System(), Target_System);

	bool	bKeepType	= m_Resampling == GRID_RESAMPLING_NearestNeighbour || Parameters("KEEP_TYPE")->asBool();

	//-----------------------------------------------------
	int	i, n	= pTargets->Get_Count();

	for(i=0; i<pSources->Get_Count(); i++)
	{
		CSG_Grid	*pSource	= pSources->asGrid(i);
		CSG_Grid	*pTarget	= SG_Create_Grid(Target_System, bKeepType ? pSource->Get_Type() : SG_DATATYPE_Float);

		if( pTarget )
		{
			pTargets->Add_Item(pTarget);

			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->Get_Projection().Create(m_Projector.Get_Target());
			pTarget->Assign_NoData();

			CSG_Parameters Parms; if( DataObject_Get_Parameters(pSource, Parms) ) { DataObject_Add(pTarget); DataObject_Set_Parameters(pTarget, Parms); }
		}
	}

	//-------------------------------------------------
	for(int y=0; y<Target_System.Get_NY() && Set_Progress(y, Target_System.Get_NY()); y++)
	{
		double	yTarget	= Target_System.Get_YMin() + y * Target_System.Get_Cellsize();

	//	#pragma omp parallel for private(i)
		for(int x=0; x<Target_System.Get_NX(); x++)
		{
			double	z, ySource, xSource	= Target_System.Get_XMin() + x * Target_System.Get_Cellsize();

			if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) )
			{
				if( bGeogCS_Adjust )
				{
					if( xSource < 0.0 )
					{
						xSource	+= 360.0;
					}
					else if( xSource >= 360.0 )
					{
						xSource	-= 360.0;
					}
				}

				if( pX ) pX->Set_Value(x, y, xSource);
				if( pY ) pY->Set_Value(x, y, ySource);

				for(i=0; i<pSources->Get_Count(); i++)
				{
					if( pSources->asGrid(i)->Get_Value(xSource, ySource, z, m_Resampling, false, true) )
					{
						pTargets->asGrid(n + i)->Set_Value(x, y, z);
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	m_Target_Area.Destroy();

	return( true );
}
//---------------------------------------------------------
bool CCRS_Transform_Grid::Transform(CSG_Grid *pGrid, CSG_Grid *pTarget)
{
	if( !m_Projector.Set_Inverse(true) || !pTarget || !pGrid )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	*pX, *pY;

	if( !Parameters("CREATE_XY")->asBool() )
	{
		pX	= pY	= NULL;
	}
	else
	{
		Parameters("OUT_X")->Set_Value(pX	= SG_Create_Grid(pTarget->Get_System(), SG_DATATYPE_Float));
		pX->Assign_NoData();
		pX->Set_Name(_TL("X-Coordinate"));
		pX->Get_Projection().Create(m_Projector.Get_Target());

		Parameters("OUT_Y")->Set_Value(pY	= SG_Create_Grid(pTarget->Get_System(), SG_DATATYPE_Float));
		pY->Assign_NoData();
		pY->Set_Name(_TL("Y-Coordinate"));
		pY->Get_Projection().Create(m_Projector.Get_Target());
	}

	//-----------------------------------------------------
	Set_Target_Area(pGrid->Get_System(), pTarget->Get_System());

	bool	bGeogCS_Adjust	= m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pGrid->Get_XMax() > 180.0;

	//-------------------------------------------------
	pTarget->Set_NoData_Value_Range	(pGrid->Get_NoData_Value(), pGrid->Get_NoData_hiValue());
	pTarget->Set_ZFactor			(pGrid->Get_ZFactor());
	pTarget->Set_Name				(CSG_String::Format(SG_T("%s"), pGrid->Get_Name()));
	pTarget->Set_Unit				(pGrid->Get_Unit());
	pTarget->Assign_NoData();
	pTarget->Get_Projection().Create(m_Projector.Get_Target());

	//-----------------------------------------------------
	for(int y=0; y<pTarget->Get_NY() && Set_Progress(y, pTarget->Get_NY()); y++)
	{
		double	yTarget	= pTarget->Get_YMin() + y * pTarget->Get_Cellsize();

		#pragma omp parallel for
		for(int x=0; x<pTarget->Get_NX(); x++)
		{
			double	z, ySource, xSource	= pTarget->Get_XMin() + x * pTarget->Get_Cellsize();

			if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) )
			{
				if( pX )	pX->Set_Value(x, y, xSource);
				if( pY )	pY->Set_Value(x, y, ySource);

				if( bGeogCS_Adjust && xSource < 0.0 )
				{
					xSource	+= 360.0;
				}

				if( pGrid->Get_Value(xSource, ySource, z, m_Interpolation) )
				{
					pTarget->Set_Value(x, y, z);
				}
			}
		}
	}

	//-----------------------------------------------------
	m_Target_Area.Destroy();

	return( true );
}
Example #4
0
//---------------------------------------------------------
bool CCRS_Transform_Grid::Transform(CSG_Grid *pGrid, CSG_Grid *pTarget)
{
	if( !m_Projector.Set_Inverse(true) || !pTarget || !pGrid )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	*pX, *pY;

	if( (pX = m_Grid_Target.Get_Grid("OUT_X")) != NULL )
	{
		pX->Assign_NoData();
		pX->Set_Name(_TL("X Coordinates"));
		pX->Get_Projection().Create(m_Projector.Get_Target());
	}

	if( (pY = m_Grid_Target.Get_Grid("OUT_Y")) != NULL )
	{
		pY->Assign_NoData();
		pY->Set_Name(_TL("Y Coordinates"));
		pY->Get_Projection().Create(m_Projector.Get_Target());
	}

	//-----------------------------------------------------
	Set_Target_Area(pGrid->Get_System(), pTarget->Get_System());

	bool	bGeogCS_Adjust	= m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pGrid->Get_XMax() > 180.0;

	//-------------------------------------------------
	pTarget->Set_NoData_Value_Range (pGrid->Get_NoData_Value(), pGrid->Get_NoData_hiValue());
	pTarget->Set_Scaling            (pGrid->Get_Scaling(), pGrid->Get_Offset());
	pTarget->Set_Name               (pGrid->Get_Name());
	pTarget->Set_Unit               (pGrid->Get_Unit());
	pTarget->Get_Projection().Create(m_Projector.Get_Target());
	pTarget->Assign_NoData();

//	CSG_Parameters Parms; if( DataObject_Get_Parameters(pGrid, Parms) ) { DataObject_Add(pTarget); DataObject_Set_Parameters(pTarget, Parms); }

	//-----------------------------------------------------
	for(int y=0; y<pTarget->Get_NY() && Set_Progress(y, pTarget->Get_NY()); y++)
	{
		double	yTarget	= pTarget->Get_YMin() + y * pTarget->Get_Cellsize();

	//	#pragma omp parallel for
		for(int x=0; x<pTarget->Get_NX(); x++)
		{
			double	z, ySource, xSource	= pTarget->Get_XMin() + x * pTarget->Get_Cellsize();

			if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) )
			{
				if( bGeogCS_Adjust )
				{
					if( xSource < 0.0 )
					{
						xSource	+= 360.0;
					}
					else if( xSource >= 360.0 )
					{
						xSource	-= 360.0;
					}
				}

				if( pX ) pX->Set_Value(x, y, xSource);
				if( pY ) pY->Set_Value(x, y, ySource);

				if( pGrid->Get_Value(xSource, ySource, z, m_Resampling, false, true) )
				{
					pTarget->Set_Value(x, y, z);
				}
			}
		}
	}

	//-----------------------------------------------------
	m_Target_Area.Destroy();

	return( true );
}