ArcObjects Library Reference  (Geometry)    


 ' The example shows a GeometryCollection for MultiPoint.
 Option Explicit
 Private m_pGeoColl As IGeometryCollection
 Private m_pMpt As IMultipoint
 Private m_pPtColl As IPointCollection
 Private Sub Form_Load()
   Set m_pMpt = New Multipoint
   Set m_pPtColl = m_pMpt
   AddPoint m_pPtColl, 0, 0
   AddPoint m_pPtColl, 1, 1
   AddPoint m_pPtColl, 2, 2
   AddPoint m_pPtColl, 3, 3
   Set m_pGeoColl = m_pMpt
 End Sub
 Private Sub AddPoint(pPtCol As IPointCollection, x As Double, y As Double)
   Dim point As IPoint
   Set point = New point
   point.x = x: point.y = y
   pPtCol.AddPoint point
 End Sub
 Private Function GeoCollCount() As Long
   GeoCollCount = m_pGeoColl.GeometryCount
 End Function
 Private Function getGeometry(index As Long) As IGeometry
   If index e" 0 And index < m_pGeoColl.GeometryCount Then
     Set getGeometry = m_pGeoColl.Geometry(index)
     Set getGeometry = Nothing
   End If
 End Function

//The example shows a GeometryCollection for MultiPoint.
public void ShowGeometries()
  IGeometryCollection geometryCollection = new MultipointClass();
  //add 10 points in a loop
  object missing = Type.Missing;
  for(int i = 0; i < 10; i++)
    IPoint point = new PointClass();
    point.PutCoords(i*10, i* 2);
    geometryCollection.AddGeometry(point as IGeometry, ref missing, ref missing);

  int geometryCount = geometryCollection.GeometryCount;
  System.Windows.Forms.MessageBox.Show("GeometryCount = " + geometryCount);
  for(int i = 0; i < geometryCount; i++)
    IGeometry currentGeometry = geometryCollection.get_Geometry(i);
    IPoint point = currentGeometry as IPoint;
    //we know that there are IPoints only in the Geometrycollection. 
    //But this is the safe and recommended way
    if(point != null)
      System.Windows.Forms.MessageBox.Show("X = " + point.X+ ", Y = " + point.Y);

[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.