ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Geometry Namespace / MultipartBuilderEx Class / ReplaceSegment Method
Zero-based index. Specify 0 to replace a segment from the first part. Specify PartCount - 1 or -1 to replace a segment from the last part.
Zero-based index. Specify 0 to replace the first segment. Specify GetSegmentCount - 1 or -1 to replace the last segment.
The new segment.
Example

In This Topic
    ReplaceSegment Method
    In This Topic
    Replace the segment at the specified index from the part specified by partIndex.

    Note: Values of partIndex = -1, segmentIndex = -1 replaces the last segment from the last part of the multipart.

    Syntax
    public void ReplaceSegment( 
       int partIndex,
       int segmentIndex,
       Segment segment
    )
    Public Sub ReplaceSegment( _
       ByVal partIndex As Integer, _
       ByVal segmentIndex As Integer, _
       ByVal segment As Segment _
    ) 

    Parameters

    partIndex
    Zero-based index. Specify 0 to replace a segment from the first part. Specify PartCount - 1 or -1 to replace a segment from the last part.
    segmentIndex
    Zero-based index. Specify 0 to replace the first segment. Specify GetSegmentCount - 1 or -1 to replace the last segment.
    segment
    The new segment.
    Exceptions
    ExceptionDescription
    The input segment is null.
    The input part index is > PartCount - 1 or the input segment index is > GetSegmentCount - 1.
    Example
    Create 3D Polyline and set Z-values while preserving curve segments
    PolylineBuilderEx polylineBuilder = new PolylineBuilderEx(polyline);
    polylineBuilder.HasZ = true;
    
    // The HasZ property is set to true for all the points in
    // polyline3D when you call ToGeometry().
    Polyline polyline3D = polylineBuilder.ToGeometry();
    
    // For this example, create Z-values. 
    // You may want to pass them in as a parameter.
    int numPoints = polyline3D.PointCount;
    double[] zValues = new double[numPoints];
    for (int i = 0; i < numPoints; i++)
    {
      zValues[i] = i % 2 == 0 ? 2 : 1;
    }
    
    // We need to know at which point index each part starts
    int partPointIndex = 0;  
    int numParts = polyline3D.PartCount;
    
    for (int i = 0; i < numParts; i++)
    {
      var part = polyline3D.Parts[i];
      int numSegments = part.Count;
    
      for (int j = 0; j < numSegments; j++)
      {
        Segment segment = part[j];
    
        MapPointBuilderEx pointBuilder = new MapPointBuilderEx(segment.StartPoint);
        pointBuilder.Z = zValues[partPointIndex++];
        MapPoint startPoint = pointBuilder.ToGeometry();
    
        // Make sure that the end point of this segment is the same as the start point of the next segment
        pointBuilder = new MapPointBuilderEx(segment.EndPoint);
        pointBuilder.Z = zValues[partPointIndex];
        MapPoint endPoint = pointBuilder.ToGeometry();
    
        SegmentType segmentType = segment.SegmentType;
        SegmentBuilderEx segmentBuilder = null;
        switch (segmentType)
        {
          case SegmentType.Line:
            segmentBuilder = new LineBuilderEx((LineSegment)segment);
            break;
          case SegmentType.Bezier:
            segmentBuilder = new CubicBezierBuilderEx((CubicBezierSegment)segment);
            break;
          case SegmentType.EllipticArc:
            segmentBuilder = new EllipticArcBuilderEx((EllipticArcSegment)segment);
            break;
        }
    
        // Only change the start and end point which now have Z-values set. 
        // This will preserve the curve if the segment is an EllipticArcSegment or CubicBezierSegment.
        segmentBuilder.StartPoint = startPoint;
        segmentBuilder.EndPoint = endPoint;
        segment = segmentBuilder.ToSegment();
    
        polylineBuilder.ReplaceSegment(i, j, segment);
      }
    
      // Move point index for the next part
      partPointIndex++;
    }
    
    polyline3D = polylineBuilder.ToGeometry();
    return polyline3D;
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also