Ejemplo n.º 1
0
//---------------------------------------------------------
bool CPolygon_Centroids::On_Execute(void)
{
	bool			bPart;
	int				iShape, iPart;
	CSG_Shape			*pCentroid;
	CSG_Shape_Polygon	*pPolygon;
	CSG_Shapes			*pPolygons, *pCentroids;

	pPolygons	= Parameters("POLYGONS")	->asShapes();
	pCentroids	= Parameters("CENTROIDS")	->asShapes();
	bPart		= Parameters("METHOD")		->asBool();

	if(	pPolygons->Get_Type() == SHAPE_TYPE_Polygon && pPolygons->Get_Count() > 0 )
	{
		pCentroids->Create(SHAPE_TYPE_Point, pPolygons->Get_Name(), pPolygons);

		//-------------------------------------------------
		for(iShape=0; iShape<pPolygons->Get_Count(); iShape++)
		{
			pPolygon	= (CSG_Shape_Polygon *)pPolygons->Get_Shape(iShape);

			if( bPart )
			{
				for(iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
				{
					pCentroid	= pCentroids->Add_Shape(pPolygon, SHAPE_COPY_ATTR);
					pCentroid->Add_Point(pPolygon->Get_Centroid(iPart));
				}
			}
			else
			{
				pCentroid	= pCentroids->Add_Shape(pPolygon, SHAPE_COPY_ATTR);
				pCentroid->Add_Point(pPolygon->Get_Centroid());
			}
		}

		return( true );
	}

	return( false );
}
Ejemplo n.º 2
0
//---------------------------------------------------------
bool CSelectByTheme::Select(CSG_Shapes *pShapes, CSG_Shapes *pShapes2, int iCondition, bool bFromSelection)
{
	CSG_Shapes			Intersect(SHAPE_TYPE_Polygon);
	CSG_Shape_Polygon	*pIntersect	= (CSG_Shape_Polygon *)Intersect.Add_Shape();

	m_Selection.clear();

	for(int i=0; i<pShapes->Get_Count() && Set_Progress(i, pShapes->Get_Count()); i++)
	{
		CSG_Shape_Polygon	*pShape	= (CSG_Shape_Polygon *)pShapes->Get_Shape(i);

		bool	bSelect	= false;

		for(int j=0; !bSelect && j<pShapes2->Get_Count(); j++)
		{
			if( !bFromSelection || pShapes2->Get_Record(j)->is_Selected() )
			{
				CSG_Shape_Polygon	*pShape2 = (CSG_Shape_Polygon *)pShapes2->Get_Shape(j);

				switch( iCondition )
				{
				case 0: //intersect
					if( GPC_Intersection(pShape, pShape2, pIntersect) )
					{
						bSelect = true;
					}
					break;

				case 1: //are completely within
					if( GPC_Intersection(pShape, pShape2, pIntersect)
					&&  pIntersect->Get_Area() == pShape->Get_Area() )
					{
						bSelect = true;
					}
					break;

				case 2: //Completely contain
					if( GPC_Intersection(pShape, pShape2, pIntersect)
					&&	pIntersect->Get_Area() == pShape2->Get_Area() )
					{
						bSelect = true;
					}
					break;

				case 3: //have their center in
					if( pShape2->is_Containing(pShape->Get_Centroid()) )
					{
						bSelect = true;
					}
					break;

				case 4: //contain center of
					if( pShape->is_Containing(pShape2->Get_Centroid()) )
					{
						bSelect = true;
					}
					break;
				}

				if( bSelect )
				{
					m_Selection.push_back(i);
				}
			}
		}
	}

	return( m_Selection.size() > 0 );
}