ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolygonBuilderEx Class / CreatePolygon Method / CreatePolygon(IEnumerable<Coordinate3D>,SpatialReference) Method
Coordinates to create the polygon. Line segments are created from the coordinates.
(Optional) The SpatialReference. The default value is null.
Example

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

    Parameters

    coordinate3Ds
    Coordinates to create the polygon. Line segments are created from the coordinates.
    spatialReference
    (Optional) The SpatialReference. The default value is null.

    Return Value

    Exceptions
    ExceptionDescription
    coordinate3Ds is null.
    Remarks
    The HasZ property is set to true.
    Example
    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 symbology, 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 symbology, 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);
    
    Create Rectangle Paragraph Text Element 1
    //Create rectangle text with background and border symbology.  
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D polygon geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(3.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.1));
      plyCoords.Add(new Coordinate2D(3.5, 6.1));
      //At 2.x - Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbology, create and add element to layout
      //Also notice how formatting tags are using within the text string.
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                        ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
      string text = "Some Text String that is really long and is " +
                    "<BOL>forced to wrap to other lines</BOL> so that " +
                    "we can see the effects." as String;
      //At 2.x - GraphicElement polyTxtElm =
      //           LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(
      //                                      layout, poly, text, sym);
      //         polyTxtElm.SetName("New Polygon Text");
    
      GraphicElement polyTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        container, TextType.RectangleParagraph, poly, sym, text, "Polygon Paragraph");
    
      //(Optionally) Modify paragraph border 
      CIMGraphic polyTxtGra = polyTxtElm.GetGraphic();
      CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic;
      cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimPolyTxtGra.Frame.BorderSymbol.Symbol =
                   SymbolFactory.Instance.ConstructLineSymbol(
                              ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
      polyTxtElm.SetGraphic(polyTxtGra);
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also