ArcGIS Pro 2.7 API Reference Guide
GeometryBagBuilder Constructor(SpatialReference)
Example 

ArcGIS.Core.Geometry Namespace > GeometryBagBuilder Class > GeometryBagBuilder Constructor : GeometryBagBuilder Constructor(SpatialReference)
(Optional) Spatial reference of the GeometryBag. The default value is null.
Initializes a new instance of the GeometryBagBuilder class. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public GeometryBagBuilder( 
   SpatialReference spatialReference
)
Public Function New( _
   Optional ByVal spatialReference As SpatialReference _
)

Parameters

spatialReference
(Optional) Spatial reference of the GeometryBag. The default value is null.
Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Example
// Builder constructors need to run on the MCT.
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
  using (GeometryBagBuilder builder = new GeometryBagBuilder(SpatialReferences.WGS84))
  {
    GeometryBag emptyBag = builder.ToGeometry();
    // emptyBag.IsEmpty = true

    MapPoint point = MapPointBuilder.CreateMapPoint(1, 2, SpatialReferences.WebMercator);
    builder.AddGeometry(point);
    // builder.CountGeometries = 1

    GeometryBag geometryBag = builder.ToGeometry();
    // geometryBag.PartCount = 1
    // geometryBag.PointCount = 1
    // geometryBag.IsEmpty = false

    IReadOnlyList<Geometry> geometries = geometryBag.Geometries;
    // geometries.Count = 1
    // geometries[0] is MapPoint with a sr of WGS84

    bool isEqual = geometryBag.IsEqual(emptyBag);   // isEqual = false

    List<Coordinate2D> coords2D = new List<Coordinate2D>()
    {
    new Coordinate2D(0, 0),
    new Coordinate2D(0, 1),
    new Coordinate2D(1, 1),
    new Coordinate2D(1, 0)
    };

    Multipoint multipoint = MultipointBuilder.CreateMultipoint(coords2D, SpatialReferences.WGS84);
    builder.InsertGeometry(0, multipoint);
    geometryBag = builder.ToGeometry();
    // geometryBag.PartCount = 2

    geometries = geometryBag.Geometries;
    // geometries.Count = 2
    // geometries[0] is Multipoint
    // geometries[1] is MapPoint

    Polyline polyline = PolylineBuilder.CreatePolyline(coords2D, SpatialReferences.WebMercator);
    builder.AddGeometry(polyline);
    builder.RemoveGeometry(1);
    geometryBag = builder.ToGeometry();
    // geometryBag.PartCount = 2

    geometries = geometryBag.Geometries;
    // geometries.Count = 2
    // geometries[0] is Multipoint
    // geometries[1] is Polyline          
  }
});
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

GeometryBagBuilder Class
GeometryBagBuilder Members
Overload List