ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolygonBuilderEx Class / CreatePolygon Method / CreatePolygon(IEnumerable<Polygon>,SpatialReference) Method
Parts to create the polyline. The spatial references of the polygons are checked for compatibility.
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from polygons. which requires traversing through the enumeration of points. For improved performance, use CreatePolygon(IEnumerable<Polygon>,AttributeFlags,SpatialReference).
Example

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

    Parameters

    polygons
    Parts to create the polyline. The spatial references of the polygons 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 polygons. which requires traversing through the enumeration of points. For improved performance, use CreatePolygon(IEnumerable<Polygon>,AttributeFlags,SpatialReference).

    Return Value

    Exceptions
    ExceptionDescription
    Incompatible spatial references.
    polygons is null.
    Remarks
    The HasZ, HasM and HasID properties are inherited from polygons. If you don't want these properties to be inherited, you can set them yourself by using CreatePolygon(IEnumerable<Polygon>,AttributeFlags,SpatialReference).
    Example
    Create an N-sided regular polygon
    // <summary>
    // Create an N-sided regular polygon.  A regular sided polygon is a polygon that is equiangular (all angles are equal in measure) 
    // and equilateral (all sides are equal in length).  See https://en.wikipedia.org/wiki/Regular_polygon
    // </summary>
    // <param name="numSides">The number of sides in the polygon.</param>
    // <param name="center">The center of the polygon.</param>
    // <param name="radius">The distance from the center of the polygon to a vertex.</param>
    // <param name="rotation">The rotation angle in radians of the start point of the polygon. The start point will be
    // rotated counterclockwise from the positive x-axis.</param>
    // <returns>N-sided regular polygon.</returns>
    // <exception cref="ArgumentException">Number of sides is less than 3.</exception>
    public Polygon CreateRegularPolygon(int numSides, Coordinate2D center, double radius, double rotation)
    {
      if (numSides < 3)
        throw new ArgumentException();
    
      Coordinate2D[] coords = new Coordinate2D[numSides + 1];
    
      double centerX = center.X;
      double centerY = center.Y;
      double x = radius * Math.Cos(rotation) + centerX;
      double y = radius * Math.Sin(rotation) + centerY;
      Coordinate2D start = new Coordinate2D(x, y);
      coords[0] = start;
    
      double da = 2 * Math.PI / numSides;
      for (int i = 1; i < numSides; i++)
      {
        x = radius * Math.Cos(i * da + rotation) + centerX;
        y = radius * Math.Sin(i * da + rotation) + centerY;
    
        coords[i] = new Coordinate2D(x, y);
      }
    
      coords[numSides] = start;
    
      return PolygonBuilderEx.CreatePolygon(coords);
    }
    
    Create_polygon_poly
    //Create a polygon graphic with simple line and fill styles.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(1, 7));
      plyCoords.Add(new Coordinate2D(2, 7));
      plyCoords.Add(new Coordinate2D(2, 6.7));
      plyCoords.Add(new Coordinate2D(3, 6.7));
      plyCoords.Add(new Coordinate2D(3, 6.1));
      plyCoords.Add(new Coordinate2D(1, 6.1));
      //At 2.x - Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
      //At 2.x - GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
      //         polyElm.SetName("New Polygon"); 
      GraphicElement polyElm = ElementFactory.Instance.CreateGraphicElement(layout, poly, polySym, "New Polygon");
    });
    Create_lasso
    //Create a graphic lasso element with simple line and fill styles.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(1, 1));
      plyCoords.Add(new Coordinate2D(1.25, 2));
      plyCoords.Add(new Coordinate2D(1.5, 1.1));
      plyCoords.Add(new Coordinate2D(1.75, 2));
      plyCoords.Add(new Coordinate2D(2, 1.1));
      plyCoords.Add(new Coordinate2D(2.25, 2));
      plyCoords.Add(new Coordinate2D(2.5, 1.1));
      plyCoords.Add(new Coordinate2D(2.75, 2));
      plyCoords.Add(new Coordinate2D(3, 1));
      //At 2.x - Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
      //At 2.x - GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
      //         polyElm.SetName("New Lasso"); 
      GraphicElement polyElm = ElementFactory.Instance.CreateGraphicElement(layout, poly, polySym, "New Lasso");
    });
    Create Lasso Polygon, Freehand Element
    //Must be on QueuedTask.Run(() => { ...
    
    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
    plyCoords.Add(new Coordinate2D(1, 1));
    plyCoords.Add(new Coordinate2D(1.25, 2));
    plyCoords.Add(new Coordinate2D(1.5, 1.1));
    plyCoords.Add(new Coordinate2D(1.75, 2));
    plyCoords.Add(new Coordinate2D(2, 1.1));
    plyCoords.Add(new Coordinate2D(2.25, 2));
    plyCoords.Add(new Coordinate2D(2.5, 1.1));
    plyCoords.Add(new Coordinate2D(2.75, 2));
    plyCoords.Add(new Coordinate2D(3, 1));
    Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
    //Set symbolology, create and add element to layout
    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
                ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
    CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
             ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
    
    ElementFactory.Instance.CreateGraphicElement(
      container, poly, polySym, "New Lasso");
    Create Polygon Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
    plyCoords.Add(new Coordinate2D(1, 7));
    plyCoords.Add(new Coordinate2D(2, 7));
    plyCoords.Add(new Coordinate2D(2, 6.7));
    plyCoords.Add(new Coordinate2D(3, 6.7));
    plyCoords.Add(new Coordinate2D(3, 6.1));
    plyCoords.Add(new Coordinate2D(1, 6.1));
    Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
    //Set symbolology, create and add element to layout
    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
      ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
    CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
      ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
    
    ElementFactory.Instance.CreateGraphicElement(
      container, poly, polySym, "New Polygon", false);
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also