ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMPolygonSymbol Class
Members Example

In This Topic
    CIMPolygonSymbol Class
    In This Topic
    Represents a polygon symbol which is used to draw polygon features or polygon graphics.
    Object Model
    CIMPolygonSymbol ClassCIMPolygonSymbol ClassCIMPolygonSymbol Class
    Syntax
    Example
    Create_polygon_env
    //Create a polygon graphic using an envelope with simple line and fill styles.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope
      Coordinate2D env_ll = new Coordinate2D(1.0, 4.75);
      Coordinate2D env_ur = new Coordinate2D(3.0, 5.75);
      //At 2.x - Envelope env = EnvelopeBuilder.CreateEnvelope(env_ll, env_ur);
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(env_ll, env_ur);
    
      //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, env, polySym);
      //         polyElm.SetName("New Polygon");
      GraphicElement polyElm = ElementFactory.Instance.CreateGraphicElement(
        layout, env, polySym, "New Polygon");
    });
    Create_circle
    //Create a circle graphic element using a simple line and fill styles.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D center = new Coordinate2D(2, 4);
      //At 2.x - EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
      var eabCir = new EllipticArcBuilderEx(center, 0.5, ArcOrientation.ArcClockwise);
      EllipticArcSegment cir = eabCir.ToSegment();
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Dash);
      CIMPolygonSymbol circleSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);
      //At 2.x - GraphicElement cirElm = LayoutElementFactory.Instance.CreateCircleGraphicElement(layout, cir, circleSym);
      //         cirElm.SetName("New Circle");
    
      var polyLine = PolylineBuilderEx.CreatePolyline(cir);
      GraphicElement cirElm = ElementFactory.Instance.CreateGraphicElement(layout, polyLine, circleSym, "New Circle");
    });
    Create_ellipse
    //Create an ellipse graphic with simple line and fill styles.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D center = new Coordinate2D(2, 2.75);
      //At 2.x - EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
      var eabElp = new EllipticArcBuilderEx(center, 0, 1, 0.45, ArcOrientation.ArcClockwise);
      EllipticArcSegment ellipse = eabElp.ToSegment();
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2.0, SimpleLineStyle.Dot);
      CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, outline);
      //At 2.x - GraphicElement elpElm = LayoutElementFactory.Instance.CreateEllipseGraphicElement(layout, ellipse, ellipseSym);
      //         elpElm.SetName("New Ellipse");
    
      var polyLine = PolylineBuilderEx.CreatePolyline(ellipse);
      GraphicElement elpElm = ElementFactory.Instance.CreateGraphicElement(layout, polyLine, ellipseSym, "New Ellipse");
    });
    Create Ellipse Graphic Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D center = new Coordinate2D(2, 2.75);
    var eabElp = new EllipticArcBuilderEx(center, 0, 1, 0.45, 
                                           ArcOrientation.ArcClockwise);
    var ellipse = eabElp.ToSegment();
    
    //Set symbolology, create and add element to layout
    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
                                    ColorFactory.Instance.GreenRGB, 2.0,
                            SimpleLineStyle.Dot);
    CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(
                             ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, 
                                                      outline);
    
    var poly = PolygonBuilderEx.CreatePolygon(
      PolylineBuilderEx.CreatePolyline(ellipse, AttributeFlags.AllAttributes));
    
    var elpElm = ElementFactory.Instance.CreateGraphicElement(
      container, poly, ellipseSym, "New Ellipse");
    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 rectangle graphic with simple symbology
    //Create a simple 2D rectangle graphic and apply simple fill and
    //outline symbols.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75);
      Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75);
      //At 2.x - Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur);
      Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
        ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
        ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
    
      //At 2.x - GraphicElement recElm =
      //           LayoutElementFactory.Instance.CreateRectangleGraphicElement(
      //                                                  layout, rec_env, polySym);
      //         recElm.SetName("New Rectangle");
      //
      GraphicElement recElm = ElementFactory.Instance.CreateGraphicElement(
        container, rec_env, polySym, "New Rectangle");
      //Or use Predefined shape
      GraphicElement recElm2 = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                                container, PredefinedShape.Rectangle, rec_env, polySym, 
                                "New Rectangle2");
    });
    How to construct a polygon symbol of specific color and fill style
    CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid);
    
    How to construct a polygon symbol of specific color, fill style and outline
    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);
    CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);
    
    How to construct a polygon symbol without an outline
    CIMPolygonSymbol fillWithoutOutline = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, null);
    
    Snippet Cross hatch
    /// <summary>
    /// Create a polygon symbol using the ConstructHatchFill method . <br/>
    /// ![PolygonSymbolDiagonalCrossHatch](http://Esri.github.io/arcgis-pro-sdk/images/Symbology/ConstructHatchFill.png)
    /// </summary>
    /// <returns></returns>
    private static Task<CIMPolygonSymbol> CreateHatchFillPolygonAsync()
    {
      return QueuedTask.Run<CIMPolygonSymbol>(() =>
      {
        CIMStroke lineStroke = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(51, 51, 51, 60), 4, SimpleLineStyle.Solid);
        //gradient
        var hatchFill = SymbolFactory.Instance.ConstructHatchFill(lineStroke, 45, 6, 0);
    
        List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer>
        {
          hatchFill
        };
        return new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
      });
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.CIM.CIMObject
          ArcGIS.Core.CIM.CIMSymbol
             ArcGIS.Core.CIM.CIMMultiLayerSymbol
                ArcGIS.Core.CIM.CIMPolygonSymbol

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also