ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / GeometryBagBuilderEx Class / InsertGeometry Method
0 based index. Specify 0 to insert at the beginning. Specify GeometryCount or -1 to insert at the end.
The geometry to insert.
Example

In This Topic
    InsertGeometry Method
    In This Topic
    Inserts the given geometry before the specified index.
    Syntax
    public void InsertGeometry( 
       int index,
       Geometry geometry
    )
    Public Sub InsertGeometry( _
       ByVal index As Integer, _
       ByVal geometry As Geometry _
    ) 

    Parameters

    index
    0 based index. Specify 0 to insert at the beginning. Specify GeometryCount or -1 to insert at the end.
    geometry
    The geometry to insert.
    Exceptions
    ExceptionDescription
    geometry is null.
    geometry is GeometryBag. You cannot insert a GeometryBag into another GeometryBag.
    Index must be equal to -1 or less than or equal to the number of geometries in the builder.
    Remarks
    Specifying -1 for the index is equivalent to AddGeometry.

    An Envelope that is inserted into the builder is converted to a Polygon when the GeometryBag is created. As a result, when retrieving an Envelope from a GeometryBag, it will be a Polygon.

    Example
    Construct GeometryBag
    MapPoint point = MapPointBuilderEx.CreateMapPoint(1, 2, SpatialReferences.WebMercator);
    
    List<Coordinate2D> coords2D = new List<Coordinate2D>()
    {
      new Coordinate2D(0, 0),
      new Coordinate2D(0, 1),
      new Coordinate2D(1, 1),
      new Coordinate2D(1, 0)
    };
    
    Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(coords2D, SpatialReferences.WGS84);
    Polyline polyline = PolylineBuilderEx.CreatePolyline(coords2D, SpatialReferences.WebMercator);
    
    GeometryBagBuilderEx builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);
    
    GeometryBag emptyBag = builder.ToGeometry();
    // emptyBag.IsEmpty = true
    
    builder.AddGeometry(point);
    // builder.GeometryCount = 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
    
    builder.InsertGeometry(0, multipoint);
    geometryBag = builder.ToGeometry();
    // geometryBag.PartCount = 2
    
    geometries = geometryBag.Geometries;
    // geometries.Count = 2
    // geometries[0] is Multipoint
    // geometries[1] is MapPoint
    
    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 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also