IEnumGeometry Interface

Provides access to members that enumerate the members of a collection of geometries.

Description

IEnumGeometry methods can be used to loop over the geometries contain in a GeometryBag or an EnumFeatureGeometry.

Members

Name Description
Read-only property Count The number of geometries in the enumeration.
Method Next Returns the next geometry in the enumeration.
Method Reset Starts the enumeration at the beginning.

IEnumGeometry.Count Property

The number of geometries in the enumeration.

Public ReadOnly Property Count As Integer
public int Count {get;}

Description

Returns the number of distinct geometry parts in the enumeration. This count is the same as the count returned by GeometryCount in a GeometryCollection.

IEnumGeometry.Next Method

Returns the next geometry in the enumeration.

Public Function Next ( _
) As IGeometry
public IGeometry Next (
);

Description

Returns the Next Geometry part from the current enumeration location.

IEnumGeometry.Reset Method

Starts the enumeration at the beginning.

Public Sub Reset ( _
)
public void Reset (
);

Description

Resets the current enumeration location to the null pointer at the beginning of the enumeration such that the Next Geometry is the first Geometry part in the enumeration.

Classes that implement IEnumGeometry

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.

//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;

}
'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

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.