How to use IGeometryBag

By using this GeometryBag you can selected multiple object within another geometry object. this method give you fast result.

By using this GeometryBag you can selected multiple object within another geometry object. this method give you fast result.

public IGeometryBag Create_GeometryBag_from_FeatureClass(IFeatureClass pFeatureClass)
{
    IGeometryBag
pGeometryBag = new GeometryBagClass();

    IGeoDataset
pGeoDataset = (IGeoDataset)pFeatureClass;

    ISpatialReference
pSpatialReference = pGeoDataset.SpatialReference;

    pGeometryBag.SpatialReference = pSpatialReference;

    IGeometryCollection
pGeometryCollection = (IGeometryCollection)pGeometryBag;

    object
MissingType = Type.Missing;

    IFeatureCursor
pFeatureCursor = pFeatureClass.Search(null, false);

    IFeature
pFeature = pFeatureCursor.NextFeature();

    while
(pFeature != null)

    {

       pGeometryCollection.AddGeometry(pFeature.Shape, ref MissingType, ref MissingType);

       pFeature = pFeatureCursor.NextFeature();

    }

    Marshal
.ReleaseComObject(pFeatureCursor);

    return
pGeometryBag;

}