Beispiel #1
0
//---------------------------------------------------------
double CGrid_Class_Statistics_For_Polygons::Get_Intersection(CSG_Shape_Polygon *pPolygon, TSG_Point p, bool bCenter)
{
	//-----------------------------------------------------
	if( bCenter )
	{
		return( pPolygon->Contains(p) ? Get_Cellarea() : 0.0 );
	}

	//-----------------------------------------------------
	CSG_Shapes	Cells(SHAPE_TYPE_Polygon);
	CSG_Shape	*pCell	= Cells.Add_Shape();
	CSG_Shape	*pArea	= Cells.Add_Shape();

	pCell->Add_Point(p.x - 0.5 * Get_Cellsize(), p.y - 0.5 * Get_Cellsize());
	pCell->Add_Point(p.x - 0.5 * Get_Cellsize(), p.y + 0.5 * Get_Cellsize());
	pCell->Add_Point(p.x + 0.5 * Get_Cellsize(), p.y + 0.5 * Get_Cellsize());
	pCell->Add_Point(p.x + 0.5 * Get_Cellsize(), p.y - 0.5 * Get_Cellsize());

	if( SG_Polygon_Intersection(pPolygon, pCell, pArea) )
	{
		return( ((CSG_Shape_Polygon *)pArea)->Get_Area() );
	}

	return( 0.0 );
}
//---------------------------------------------------------
void CPolygon_Clip::Clip_Polygons(CSG_Shapes *pClips, CSG_Shapes *pInputs, CSG_Shapes *pOutputs)
{
	for(int iClip=0; iClip<pClips->Get_Count() && Process_Get_Okay(); iClip++)
	{
		Process_Set_Text(CSG_String::Format(SG_T("%s: %d/%d"), _TL("clip features"), iClip + 1, pClips->Get_Count()));

		CSG_Shape	*pClip	= pClips->Get_Shape(iClip);

		for(int iInput=0; iInput<pInputs->Get_Count() && Set_Progress(iInput, pInputs->Get_Count()); iInput++)
		{
			CSG_Shape	*pOutput	= pOutputs->Add_Shape(pInputs->Get_Shape(iInput));

			if( !SG_Polygon_Intersection(pOutput, pClip) )
			{
				pOutputs->Del_Shape(pOutputs->Get_Count() - 1);
			}
		}
	}
}
Beispiel #3
0
//---------------------------------------------------------
bool CGCS_Graticule::Get_Graticule(const CSG_Rect &Extent)
{
	double		x, y, Interval;
	CSG_Rect	r;

	if( !Get_Extent(Extent, r) || (Interval = Get_Interval(r)) <= 0.0 )
	{
		return( false );
	}

	//-----------------------------------------------------
	r.m_rect.xMin	= Interval * floor(r.Get_XMin() / Interval);
	r.m_rect.xMax	= Interval * ceil (r.Get_XMax() / Interval);
	r.m_rect.yMin	= Interval * floor(r.Get_YMin() / Interval);
	r.m_rect.yMax	= Interval * ceil (r.Get_YMax() / Interval);

	r.Inflate(Interval, false);

	if( r.Get_XMin() < -180.0 )	r.m_rect.xMin	= -180.0;
	if( r.Get_XMax() >  180.0 )	r.m_rect.xMax	=  180.0;
	if( r.Get_YMin() <  -90.0 )	r.m_rect.yMin	=  -90.0;
	if( r.Get_YMax() >   90.0 )	r.m_rect.yMax	=   90.0;

	//-----------------------------------------------------
	double	Resolution	= Parameters("RESOLUTION")->asDouble();	if( Resolution <= 0.0 )	Resolution	= Interval;

	if( Interval > Resolution )
	{
		Resolution	= Interval / ceil(Interval / Resolution);
	}

	//-----------------------------------------------------
	CSG_Shapes	*pGraticule	= Parameters("GRATICULE")->asShapes();

	pGraticule->Create(SHAPE_TYPE_Line);
	pGraticule->Set_Name(_TL("Graticule"));

	pGraticule->Add_Field("TYPE"  , SG_DATATYPE_String);
	pGraticule->Add_Field("LABEL" , SG_DATATYPE_String);
	pGraticule->Add_Field("DEGREE", SG_DATATYPE_Double);

	//-----------------------------------------------------
	CSG_Shapes	*pCoordinates	= Parameters("COORDS")->asShapes();

	if( pCoordinates )
	{
		pCoordinates->Create(SHAPE_TYPE_Point);
		pCoordinates->Set_Name(_TL("Coordinates"));

		pCoordinates->Add_Field("TYPE" , SG_DATATYPE_String);
		pCoordinates->Add_Field("LABEL", SG_DATATYPE_String);
	}

	//-----------------------------------------------------
	CSG_Shapes	Clip(SHAPE_TYPE_Polygon);
	CSG_Shape	*pClip	= Clip.Add_Shape();

	pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMin());
	pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMax());
	pClip->Add_Point(Extent.Get_XMax(), Extent.Get_YMax());
	pClip->Add_Point(Extent.Get_XMax(), Extent.Get_YMin());
	pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMin());

	//-----------------------------------------------------
	for(y=r.Get_YMin(); y<=r.Get_YMax(); y+=Interval)
	{
		CSG_Shape	*pLine	= pGraticule->Add_Shape();

		pLine->Set_Value(0, "LAT");
		pLine->Set_Value(1, Get_Degree(y, DEG_PREC_DEG));
		pLine->Set_Value(2, y);

		for(x=r.Get_XMin(); x<=r.Get_XMax(); x+=Interval)
		{
			CSG_Point	p(x, y);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);

			if( Resolution < Interval && x < r.Get_XMax() )
			{
				for(double i=x+Resolution; i<x+Interval; i+=Resolution)
				{
					CSG_Point	p(i, y);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);
				}
			}
		}

		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_LEFT);
		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_RIGHT);

		if( !SG_Polygon_Intersection(pLine, pClip) )
		{
			pGraticule->Del_Shape(pLine);
		}
	}

	//-----------------------------------------------------
	for(x=r.Get_XMin(); x<=r.Get_XMax(); x+=Interval)
	{
		CSG_Shape	*pLine	= pGraticule->Add_Shape();

		pLine->Set_Value(0, "LON");
		pLine->Set_Value(1, Get_Degree(x, DEG_PREC_DEG));
		pLine->Set_Value(2, x);

		for(y=r.Get_YMin(); y<=r.Get_YMax(); y+=Interval)
		{
			CSG_Point	p(x, y);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);

			if( Resolution < Interval && y < r.Get_YMax() )
			{
				for(double i=y+Resolution; i<y+Interval; i+=Resolution)
				{
					CSG_Point	p(x, i);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);
				}
			}
		}

		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_BOTTOM);
		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_TOP);

		if( !SG_Polygon_Intersection(pLine, pClip) )
		{
			pGraticule->Del_Shape(pLine);
		}
	}

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