ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolygonBuilderEx Class / CreatePolygon Method / CreatePolygon(IEnumerable<Segment>,SpatialReference) Method
Segments to create the polyline. The spatial references of the segments are checked for compatibility.
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from segments which requires traversing through the enumeration of segments. For improved performance or if you want to set these properties yourself, use CreatePolygon(IEnumerable<Segment>,AttributeFlags,SpatialReference).
Example

In This Topic
    CreatePolygon(IEnumerable<Segment>,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the Polygon class.
    Syntax
    Public Overloads Shared Function CreatePolygon( _
       ByVal segments As IEnumerable(Of Segment), _
       Optional ByVal spatialReference As SpatialReference _
    ) As Polygon

    Parameters

    segments
    Segments to create the polyline. The spatial references of the segments are checked for compatibility.
    spatialReference
    (Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from segments which requires traversing through the enumeration of segments. For improved performance or if you want to set these properties yourself, use CreatePolygon(IEnumerable<Segment>,AttributeFlags,SpatialReference).

    Return Value

    Exceptions
    ExceptionDescription
    Incompatible spatial references.
    segments is null.
    Remarks
    The HasZ, HasM and HasID properties are inherited from segments which requires traversing through the enumeration of segments. For improved performance or if you want to set these properties yourself, use CreatePolygon(IEnumerable<Segment>,AttributeFlags,SpatialReference).
    Example
    Get the segments of a Polygon
    {
      List<Segment> segmentList = new List<Segment>(30);
      ICollection<Segment> collection = segmentList;
      polygon.GetAllSegments(ref collection);
      // segmentList.Count = 4
      // segmentList.Capacity = 30
    
      // use the segments to build another polygon
      Polygon polygonFromSegments = PolygonBuilderEx.CreatePolygon(collection);
    }
    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