This document is archived and information here might be outdated. Recommended version. |
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*
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);