This document is archived and information here might be outdated. Recommended version. |
ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IE > IEnumGeometry Interface (ArcObjects .NET 10.4 SDK) |
Provides access to members that enumerate the members of a collection of geometries.
IEnumGeometry methods can be used to loop over the geometries contain in a GeometryBag or an EnumFeatureGeometry.
Description | ||
---|---|---|
Count | The number of geometries in the enumeration. | |
Next | Returns the next geometry in the enumeration. | |
Reset | Starts the enumeration at the beginning. |
CoClasses and Classes | Description |
---|---|
EnumFeatureGeometry (esriGeoDatabase) | Esri enumerator for geometries of a feature class or selection set. |
GeometryBag | An ordered collection of objects that support the IGeometry interface. |
[C#]
//This example demonstrates how to use the IEnumGeometry methods
public void IEnumGeometry_Example()
{
IGeometryBag geometryBag=CreateGeometryBag() as IGeometryBag;
IEnumGeometry enumGeometry=geometryBag as IEnumGeometry;
//Reset the enumrator
enumGeometry.Reset();
//Print the number of geometries
System.Windows.Forms.MessageBox.Show("Number of geometries : " + enumGeometry.Count);
//Loop over the enumerator and print the geometrytype of each geometry
IGeometry geometry=enumGeometry.Next();
int counter=1;
while(geometry != null)
{
System.Windows.Forms.MessageBox.Show("Geometry: " + counter + " Geometry type: " + geometry.GeometryType);
geometry=enumGeometry.Next();
counter++;
}
}
//Create a geometrybag for the need of the example
private IGeometryCollection CreateGeometryBag()
{
//Should set the spatial reference on the geometry bag here - Code ommited
//Create some points
IPoint[] points=new IPoint[4];
for(int i=0; i < 4; i++)
{
points[i]=new PointClass();
}
points[0].PutCoords(0, 0);
points[1].PutCoords(0, 10);
points[2].PutCoords(10, 10);
points[3].PutCoords(0, 0);
//Create a polyline
IPointCollection polyLinePoints=new PolylineClass();
//helper class to solve C-Style Array usage in COM classes
IGeometryBridge geometryBride=new GeometryEnvironmentClass();
geometryBride.AddPoints(polyLinePoints as IPointCollection4, ref points);
//Create a polygon
IPointCollection polygonPoints=new PolygonClass();
geometryBride.AddPoints(polygonPoints as IPointCollection4, ref points);
IGeometryCollection geometryBag=new GeometryBagClass();
object Missing=Type.Missing;
geometryBag.AddGeometry(polyLinePoints as IGeometry, ref Missing, ref Missing);
geometryBag.AddGeometry(polygonPoints as IGeometry, ref Missing, ref Missing);
return geometryBag;
}
[Visual Basic .NET]
'This example demonstrates how to use the IEnumGeometry methods
Sub IEnumGeometry_Example()
Dim pGeoBag As ESRI.ArcGIS.Geometry.IGeometryBag, pEnumGeometry As ESRI.ArcGIS.Geometry.IEnumGeometry
Dim pGeo As ESRI.ArcGIS.Geometry.IGeometry, i As Long
pGeoBag=CreateGeometryBag
pEnumGeometry=pGeoBag
'Reset the enumrator
pEnumGeometry.Reset()
'Print the number of geometries
Debug.Print("Number of geometries : " & pEnumGeometry.Count)
'Loop over the enumerator and print the geometrytype of each geometry
pGeo=pEnumGeometry.Next
While Not pGeo Is Nothing
Debug.Print("Geometry: " & i & " Geometry type: " & pGeo.GeometryType)
i=i + 1
pGeo=pEnumGeometry.Next
End While
End Sub
'Create a geometrybag for the need of the example
Private Function CreateGeometryBag() As ESRI.ArcGIS.Geometry.IGeometryBag
Dim pGeoColl As ESRI.ArcGIS.Geometry.IGeometryCollection, pPointColl0 As ESRI.ArcGIS.Geometry.IPointCollection
Dim pts(3) As ESRI.ArcGIS.Geometry.IPoint, i As Long
Dim pPointColl1 As ESRI.ArcGIS.Geometry.IPointCollection
pGeoColl=New ESRI.ArcGIS.Geometry.GeometryBag
'Should set the spatial reference on the geometry bag here - Code ommited
'Create some points
For i=0 To 3
pts(i)=New ESRI.ArcGIS.Geometry.Point
Next
pts(0).PutCoords(0, 0)
pts(1).PutCoords(0, 10)
pts(2).PutCoords(10, 10)
pts(3).PutCoords(0, 0)
'Create a polyline
pPointColl0=New ESRI.ArcGIS.Geometry.Polyline
pPointColl0.AddPoints(3, pts(0))
'Create a polygon
pPointColl1=New ESRI.ArcGIS.Geometry.Polygon
pPointColl1.AddPoints(4, pts(0))
pGeoColl.AddGeometry(pPointColl0)
pGeoColl.AddGeometry(pPointColl1)
CreateGeometryBag=pGeoColl
End Function
.NET Related Topics
Geodatabase