ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Geometry Namespace / Multipart Class / Parts Property
Example

In This Topic
    Parts Property (Multipart)
    In This Topic
    Gets the parts in this instance.
    Syntax
    Public Overridable ReadOnly Property Parts As ReadOnlyPartCollection
    public virtual ReadOnlyPartCollection Parts {get;}
    Example
    Get the parts of a Polyline
    {
      int numParts = polyline.PartCount;
      // get the parts as a readonly collection
      ReadOnlyPartCollection parts = polyline.Parts;
    }
    Enumerate the parts of a Polyline
    {
      ReadOnlyPartCollection polylineParts = polyline.Parts;
    
      // enumerate the segments to get the length
      double len = 0;
      IEnumerator<ReadOnlySegmentCollection> segmentsPolyline = polylineParts.GetEnumerator();
      while (segmentsPolyline.MoveNext())
      {
        ReadOnlySegmentCollection seg = segmentsPolyline.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
      Geometry sketchGeometry = polyline; // for example
      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 startPointOfSegment = firsLineSegment.StartPoint;
    }
    Get the parts of a Polygon
    {
      // get the parts as a readonly collection
      ReadOnlyPartCollection parts = polygon.Parts;
    }
    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
        }
      }
    }
    Get the individual parts of a multipart feature
    IEnumerable<Geometry> MultipartToSinglePart(Geometry inputGeometry)
    {
      // list holding the part(s) of the input geometry
      List<Geometry> singleParts = new List<Geometry>();
    
      // check if the input is a null pointer or if the geometry is empty
      if (inputGeometry == null || inputGeometry.IsEmpty)
        return singleParts;
    
      // based on the type of geometry, take the parts/points and add them individually into a list
      switch (inputGeometry.GeometryType)
      {
        case GeometryType.Envelope:
          singleParts.Add(inputGeometry.Clone() as Envelope);
          break;
        case GeometryType.Multipatch:
          singleParts.Add(inputGeometry.Clone() as Multipatch);
          break;
        case GeometryType.Multipoint:
          var multiPoint = inputGeometry as Multipoint;
    
          foreach (var point in multiPoint.Points)
          {
            // add each point of collection as a standalone point into the list
            singleParts.Add(point);
          }
          break;
        case GeometryType.Point:
          singleParts.Add(inputGeometry.Clone() as MapPoint);
          break;
        case GeometryType.Polygon:
          var polygonNew = inputGeometry as Polygon;
    
          foreach (var polygonPart in polygonNew.Parts)
          {
            // use the PolygonBuilderEx turning the segments into a standalone 
            // polygon instance
            singleParts.Add(PolygonBuilderEx.CreatePolygon(polygonPart));
          }
          break;
        case GeometryType.Polyline:
          var polylineNew = inputGeometry as Polyline;
    
          foreach (var polylinePart in polyline.Parts)
          {
            // use the PolylineBuilderEx turning the segments into a standalone
            // polyline instance
            singleParts.Add(PolylineBuilderEx.CreatePolyline(polylinePart));
          }
          break;
        case GeometryType.Unknown:
          break;
        default:
          break;
      }
      return singleParts;
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also