This document is archived and information here might be outdated. Recommended version. |
ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IG > IGeometryCollection Interface > IGeometryCollection.AddGeometry Method (ArcObjects .NET 10.4 SDK) |
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 );
Optional Values
[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.
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.
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);