Exemple #1
0
//---------------------------------------------------------
bool CErosion_LS_Fields::Set_Fields(void)
{
	CSG_Shapes	*pFields	= Parameters("FIELDS")->asShapes();

	//-----------------------------------------------------
	if( !pFields || pFields->Get_Count() <= 0 )
	{
		m_Fields.Create(*Get_System(), SG_DATATYPE_Char);
	//	m_Fields.Set_NoData_Value(1.0);
	//	m_Fields.Assign(0.0);

		#pragma omp parallel for
		for(int y=0; y<Get_NY(); y++)
		{
			for(int x=0; x<Get_NX(); x++)
			{
				if( !m_pDEM->is_InGrid(x, y) )
				{
					m_Fields.Set_NoData(x, y);
				}
			}
		}

		return( true );
	}

	//-----------------------------------------------------
	Process_Set_Text(_TL("Initializing Fields"));

	m_nFields	= pFields->Get_Count();

	m_Fields.Create(*Get_System(), m_nFields < pow(2.0, 16.0) - 1.0 ? SG_DATATYPE_Word : SG_DATATYPE_DWord);
	m_Fields.Set_NoData_Value(m_nFields);
	m_Fields.Assign_NoData();

	//-----------------------------------------------------
	for(int iField=0; iField<pFields->Get_Count() && Set_Progress(iField, pFields->Get_Count()); iField++)
	{
		CSG_Shape_Polygon	*pField	= (CSG_Shape_Polygon *)pFields->Get_Shape(iField);

		int	xMin	= Get_System()->Get_xWorld_to_Grid(pField->Get_Extent().Get_XMin()) - 1; if( xMin <  0        ) xMin = 0;
		int	xMax	= Get_System()->Get_xWorld_to_Grid(pField->Get_Extent().Get_XMax()) + 1; if( xMax >= Get_NX() ) xMax = Get_NX() - 1;
		int	yMin	= Get_System()->Get_yWorld_to_Grid(pField->Get_Extent().Get_YMin()) - 1; if( yMin <  0        ) yMin = 0;
		int	yMax	= Get_System()->Get_yWorld_to_Grid(pField->Get_Extent().Get_YMax()) + 1; if( yMax >= Get_NY() ) yMax = Get_NY() - 1;

		for(int y=yMin; y<=yMax; y++)
		{
			for(int x=xMin; x<=xMax; x++)
			{
				if( m_pDEM->is_InGrid(x, y) && pField->Contains(Get_System()->Get_Grid_to_World(x, y)) )
				{
					m_Fields.Set_Value(x, y, iField);
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
//---------------------------------------------------------
void CPolygon_Clip::Clip_Lines(CSG_Shapes *pClips, CSG_Shapes *pInputs, CSG_Shapes *pOutputs)
{
	for(int iClip=0; iClip<pClips->Get_Count() && Set_Progress(iClip, pClips->Get_Count()); iClip++)
	{
		CSG_Shape_Polygon	*pClip	= (CSG_Shape_Polygon *)pClips->Get_Shape(iClip);

		if( pInputs->Select(pClip->Get_Extent()) )
		{
			for(int iInput=0; iInput<pInputs->Get_Selection_Count(); iInput++)
			{
				CSG_Shape	*pNew_Line, *pLine	= pInputs->Get_Selection(iInput);

				for(int iPart=0, jPart=-1; iPart<pLine->Get_Part_Count(); iPart++)
				{
					TSG_Point	B, A	= pLine->Get_Point(0, iPart);
					bool		bIn		= pClip->Contains(A);

					if( bIn )
					{
						pNew_Line	= pOutputs->Add_Shape(pLine, SHAPE_COPY_ATTR);

						pNew_Line->Add_Point(A, ++jPart);
					}

					for(int iPoint=1; iPoint<pLine->Get_Point_Count(iPart); iPoint++)
					{
						B	= A;
						A	= pLine->Get_Point(iPoint, iPart);

						if( bIn )
						{
							if( pClip->Contains(A) )
							{
								pNew_Line->Add_Point(A, jPart);
							}
							else
							{
								pNew_Line->Add_Point(Get_Crossing(pClip, A, B), jPart);

								bIn	= false;
							}
						}
						else if( pClip->Contains(A) )
						{
							if( jPart < 0 )
							{
								pNew_Line	= pOutputs->Add_Shape(pLine, SHAPE_COPY_ATTR);
							}

							pNew_Line->Add_Point(Get_Crossing(pClip, A, B), ++jPart);
							pNew_Line->Add_Point(A, jPart);

							bIn	= true;
						}
					}
				}
			}
		}
	}
}