This document is archived and information here might be outdated.  Recommended version.


IGeometryCollection.AddGeometry Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IG > IGeometryCollection Interface > IGeometryCollection.AddGeometry Method
ArcGIS Developer Help

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++]
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* after [optional]
after is a parameter of type VARIANT*

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

.NET Samples

3D multipatch examples 3D multipatch examples 3D multipatch examples 3D multipatch examples 3D multipatch examples 3D multipatch examples 3D multipatch examples 3D multipatch examples Subset network evaluators ViperPin tool