ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolygonBuilderEx Class / CreatePolygon Method / CreatePolygon(Polyline,SpatialReference) Method
The polyline to create the polygon.
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from polyline.
Example

In This Topic
    CreatePolygon(Polyline,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the Polygon class.
    Syntax
    public static Polygon CreatePolygon( 
       Polyline polyline,
       SpatialReference spatialReference
    )
    Public Overloads Shared Function CreatePolygon( _
       ByVal polyline As Polyline, _
       Optional ByVal spatialReference As SpatialReference _
    ) As Polygon

    Parameters

    polyline
    The polyline to create the polygon.
    spatialReference
    (Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from polyline.

    Return Value

    Exceptions
    ExceptionDescription
    polyline is null.
    Remarks
    HasZ, HasM and HasID attributes are inherited from the input polyline.
    Example
    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;
    }
    Get a combination of monotonicity values that describes all trends in the M-values over the length of the multipart - GetMMonotonicity
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,5],[-1000,-2000,0]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      Monotonicity monotonicity = GeometryEngine.Instance.GetMMonotonicity(polyline);
      // monotonicity = Monotonicity.ValueDecreases
    
      // Create a polygon from the polyline
      polygon = PolygonBuilderEx.CreatePolygon(polyline);
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(polygon);
      // monotonicity = ValueIncreases | ValueDecreases
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,10],[-1000,-2000,10]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(polygon);
      // monotonicity = Monotonicity.ValueLevel
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,null],[-2000,-2000,5],[-1000,-2000,10]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(polyline);
      // monotonicity = ValueIncreases | ValueEmpty
    
      // Create an empty polyline
      Polyline emptyPolyline = PolylineBuilderEx.FromJson("{\"hasM\":true,\"paths\":[]}");
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(emptyPolyline);
      // monotonicity = Monotonicity.None
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also