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


IGeometryBag vs. IGeometryCollection (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with geometry > IGeometryBag vs. IGeometryCollection (ArcObjects .NET 10.6 SDK)

IGeometryBag vs. IGeometryCollection


Summary
These two interfaces are related in name but perform important yet different roles.

In this topic


About IGeometryBag vs. IGeometryCollection

The IGeometryBag and IGeometryCollection interfaces serve two different purposes. The main function of IGeometryBag is the spatial reference of the geometry or geometries that are referenced as elements of the GeometryBag.
IGeometryCollection functions involve the creation of new geometries from collections of simpler geometries. IGeometryCollection can insert and rearrange elements within the composite object as well as create the composite objects from constituent parts.

IGeometryBag

IGeometryBag gives the user access to methods that affect the spatial reference of a GeometryBag and the geometry references it contains. Setting the spatial reference of IGeometryBag before adding references to geometries to the GeometryBag is important. Without this step, the geometry's spatial reference is automatically set to whatever the GeometryBag's spatial reference is even if it is not defined.
Geometries that are added to the GeometryBag inherit the GeometryBag spatial reference. Make sure the geometries you plan to reference are already in the same coordinate system. However, if the resolution and spatial domain values differ, you can use the SnapToSpatialReference method to ensure that all the elements have the same resolution value and coordinate grid.
Resolution and coordinate grid values are important if you want to perform analysis on the data particularly using ITopologicalOperator or IRelationalOperator. With the Project method, you can change the spatial reference of the GeometryBag and its elements. If the input and output spatial references use different geographic coordinate systems, it is important to remember that the Project method will not work if GeoTransformationOperationSet does not contain an appropriate GeoTransformation.
You cannot call the Project method on a GeometryBag that does not have its spatial reference property defined. Also, do not apply the Project and ProjectEx methods to GeometryBag if it contains segments, as this is not supported and results in an error. These methods and properties are powerful and allow properties to be changed in all elements of the GeometryBag.

IGeometryCollection

IGeometryCollection is implemented by several collection objects including GeometryBag. IGeometryCollection allows the addition, removal, insertion, and manipulation of elements from these collection objects. Also, setting specific parts of a composite geometry is available with this interface.
Only the following two properties are accessible in read-only format from IGeometryCollection:
Several of the methods on IGeometryCollection that involve adding arrays of geometries must be performed using IGeometryBridge or IGeometryBridge2 when programming in Java or any of the .NET languages.
After changing the properties of the elements referenced in a collection object, it is important to call IGeometryCollection.GeometriesChanged so that it can delete any cached properties it maintains, such as envelope, length, or area.






Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced