ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / ReadOnlySegmentCollection Class
Members Example

In This Topic
    ReadOnlySegmentCollection Class
    In This Topic
    A read only collection of Segment classes.
    Object Model
    ReadOnlySegmentCollection ClassSegment Class
    Syntax
    Example
    Enumerate the parts of a Polyline
    ReadOnlyPartCollection polylineParts = polyline.Parts;
    
    // enumerate the segments to get the length
    double len = 0;
    IEnumerator<ReadOnlySegmentCollection> segments = polylineParts.GetEnumerator();
    while (segments.MoveNext())
    {
      ReadOnlySegmentCollection seg = segments.Current;
      foreach (Segment s in seg)
      {
        len += s.Length;
    
        // perhaps do something specific per segment type
        switch (s.SegmentType)
        {
          case SegmentType.Line:
            break;
          case SegmentType.Bezier:
            break;
          case SegmentType.EllipticArc:
            break;
        }
      }
    }
    
    // or use foreach pattern
    foreach (var part in polyline.Parts)
    {
      foreach (var segment in part)
      {
        len += segment.Length;
    
        // perhaps do something specific per segment type
        switch (segment.SegmentType)
        {
          case SegmentType.Line:
            break;
          case SegmentType.Bezier:
            break;
          case SegmentType.EllipticArc:
            break;
        }
      }
    }
    StartPoint of a Polyline
    // Method 1: Get the start point of the polyline by converting the polyline 
    //    into a collection of points and getting the first point
    
    // sketchGeometry is a Polyline
    // get the sketch as a point collection
    var pointCol = ((Multipart)sketchGeometry).Points;
    // Get the start point of the line
    var firstPoint = pointCol[0];
    
    // Method 2: Convert polyline into a collection of line segments 
    //   and get the "StartPoint" of the first line segment.
    var polylineGeom = sketchGeometry as ArcGIS.Core.Geometry.Polyline;
    var polyLineParts = polylineGeom.Parts;
    
    ReadOnlySegmentCollection polylineSegments = polyLineParts.First();
    
    //get the first segment as a LineSegment
    var firsLineSegment = polylineSegments.First() as LineSegment;
    
    //Now get the start Point
    var startPoint = firsLineSegment.StartPoint;
    
    Enumerate the parts of a Polygon
    int numSegments = 0;
    IEnumerator<ReadOnlySegmentCollection> segments = polygon.Parts.GetEnumerator();
    while (segments.MoveNext())
    {
      ReadOnlySegmentCollection seg = segments.Current;
      numSegments += seg.Count;
      foreach (Segment s in seg)
      {
        // do something with the segment
      }
    }
    
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.Geometry.ReadOnlySegmentCollection

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also