ArcObjects Library Reference (Geometry)  

IGeometryCollection.AddGeometry Method

Adds a reference to the input geometry either at the end, or before, or after the specified index.

[Visual Basic .NET]
Public Sub AddGeometry ( _
    ByVal inGeometry As IGeometry, _
    [ByRef before As Object], _
    [ByRef after As Object] _
)
[C#]
public void AddGeometry (
    IGeometry inGeometry,
    ref object before,
    ref object after
);
[C#]

Optional Values

before   To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
after   To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
[C++]
HRESULT AddGeometry(
  IGeometry* inGeometry,
  VARIANT* before,
  VARIANT* after
);
[C++]

Parameters

inGeometry

  inGeometry is a parameter of type IGeometry

before [optional]   before is a parameter of type VARIANT

  To indicate this parameter is undefined pass a reference to a VARIANT with type VT_ERROR and scode value of DISP_E_PARAMNOTFOUND.

after [optional]   after is a parameter of type VARIANT

  To indicate this parameter is undefined pass a reference to a VARIANT with type VT_ERROR and scode value of DISP_E_PARAMNOTFOUND.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

When applying the AddGeometry method give either the before or after index and not both. Adding a Geometry to the collection as the first one is done by setting the before index as 0.

The spatial reference of the GeometryCollection is transferred (objects projected if necessary) to any objects added to it. However the spatial reference of the added geometry is not transferred to the GeometryCollection. Always make sure to set the spatial reference on the object GeometryCollection prior to add other geometries to it to avoid creating invalid geometry. For example, adding geometry objects to a GeometryBag that doesn't have a well-defined spatial reference will set an undefined spatial reference to all the objects added to the bag. Using this GeometryBag may cause unexpected behavior with the ITopologicalOperator::ConstructUnion method.

 
[C#]

IPoint pnt = new PointClass();

pnt.PutCoords(x, y);

IGeometryCollection geomColl = new MultipointClass() as IGeometryCollection;

object obj = Type.Missing;

geomColl.AddGeometry(pnt, ref obj, ref obj);

See Also

IGeometryCollection Interface