ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / GeometryBagBuilderEx Class / InsertGeometries 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
    InsertGeometries Method
    In This Topic
    Inserts the given list of geometries before the specified index.
    Syntax
    public void InsertGeometries( 
       int index,
       IEnumerable<Geometry> geometries
    )
    Public Sub InsertGeometries( _
       ByVal index As Integer, _
       ByVal geometries As IEnumerable(Of Geometry) _
    ) 

    Parameters

    index
    0 based index. Specify 0 to insert at the beginning. Specify GeometryCount or -1 to insert at the end.
    geometries
    The geometry to insert.
    Exceptions
    ExceptionDescription
    geometries is null.
    A geometry in geometries is null. You cannot insert a null geometry into GeometryBag.
    A geometry in geometries 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 AddGeometries.

    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 - adding or inserting an enumeration of geometries
    MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20);
    List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
    Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(coords, SpatialReferences.WebMercator);
    Polyline polyline = PolylineBuilderEx.CreatePolyline(coords);
    
    string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
    Polygon polygon = PolygonBuilderEx.FromJson(json);
    
    var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };
    
    //At 2.x - using (var builder = new GeometryBagBuilder(SpatialReferences.WGS84))
    var builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);
    builder.AddGeometries(geometries);
    
    GeometryBag geomBag = builder.ToGeometry();
    // geomBag.PartCount == 4    (point, multipoint, polyline, polygon)
    
    geometries = new List<Geometry>() { point, polyline };
    builder.InsertGeometries(1, geometries);
    // builder.GeometryCount == 6
    geomBag = builder.ToGeometry();
    // geomBag.PartCount == 6    (point, point, polyline, multipoint, polyline, polygon)
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also