示例#1
0
//---------------------------------------------------------
int CSG_Network::_Add_Node(CSG_PRQuadTree &Search, int Edge_ID, const TSG_Point &Node_Point, const TSG_Point &Dir_Point)
{
	int					Node_ID;
	double				Distance;
	CSG_PRQuadTree_Leaf	*pLeaf	= Search.Get_Nearest_Leaf(Node_Point, Distance);

	if( !pLeaf || Distance > 0.0 )//00001 )
	{
		Node_ID	= Get_Node_Count();

		m_Nodes.Inc_Array();

		((CSG_Network_Node **)m_Nodes.Get_Array())[Node_ID]	= new CSG_Network_Node(Node_ID, Node_Point);

		Search.Add_Point(Node_Point.x, Node_Point.y, Node_ID);
	}
	else
	{
		Node_ID	= (int)pLeaf->Get_Z();
	}

	Get_Node(Node_ID).Add_Edge(Edge_ID, SG_Get_Angle_Of_Direction(Node_Point, Dir_Point));

	return( Node_ID );
}
//---------------------------------------------------------
bool CGrid_Proximity::On_Execute(void)
{
	int				x, y;
	double			z, d;
	TSG_Point		p;
	CSG_Grid		*pFeatures, *pDistance, *pDirection, *pAllocation;
	CSG_PRQuadTree	Search;

	//-----------------------------------------------------
	pFeatures	= Parameters("FEATURES")	->asGrid();
	pDistance	= Parameters("DISTANCE")	->asGrid();
	pDirection	= Parameters("DIRECTION")	->asGrid();
	pAllocation	= Parameters("ALLOCATION")	->asGrid();

	//-----------------------------------------------------
	Process_Set_Text(_TL("preparing distance calculation..."));

	Search.Create(CSG_Rect(-1, -1, Get_NX(), Get_NY()));

	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( pFeatures->is_NoData(x, y) )
			{
				pDistance->Set_Value(x, y, -1.0);
			}
			else
			{
				pDistance->Set_Value(x, y,  0.0);

				if( pDirection )
				{
					pDirection->Set_NoData(x, y);
				}

				if( pAllocation )
				{
					pAllocation->Set_Value(x, y, pFeatures->asDouble(x, y));
				}

				//-----------------------------------------
				bool	bBorder	= false;

				for(int i=0; i<8 && !bBorder; i++)
				{
					int	ix	= Get_xTo(i, x);
					int	iy	= Get_yTo(i, y);

					if( is_InGrid(ix, iy) && pFeatures->is_NoData(ix, iy) )
					{
						bBorder	= true;
					}
				}

				if( bBorder )
				{
					Search.Add_Point(x, y, pFeatures->asDouble(x, y));
				}
			}
		}
	}

	if( !Search.is_Okay() || Search.Get_Point_Count() <= 0 || Search.Get_Point_Count() >= Get_NCells() )
	{
		Message_Add(_TL("no features to buffer."));

		return( false );
	}

	//-----------------------------------------------------
	Process_Set_Text(_TL("performing distance calculation..."));

	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( pDistance->asDouble(x, y) < 0.0 && Search.Get_Nearest_Point(x, y, p, z, d) )
			{
				pDistance->Set_Value(x, y, d * Get_Cellsize());

				if( pDirection )
				{
					if( d > 0.0 )
					{
						pDirection->Set_Value(x, y, SG_Get_Angle_Of_Direction(x, y, p.x, p.y) * M_RAD_TO_DEG);
					}
					else
					{
						pDirection->Set_NoData(x, y);
					}
				}

				if( pAllocation )
				{
					pAllocation->Set_Value(x, y, z);
				}
			}
		}
	}

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