ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / ISymbolFactory Interface / ConstructStroke Method / ConstructStroke(CIMColor,Double,SimpleLineStyle) Method
ArcGIS.Core.CIM.CIMColor
The width of stroke to construct.
SimpleLineStyle
Example

In This Topic
    ConstructStroke(CIMColor,Double,SimpleLineStyle) Method
    In This Topic
    Constructs a stroke of specific color, width and style.
    Syntax
    Overloads Function ConstructStroke( _
       ByVal color As CIMColor, _
       ByVal width As Double, _
       ByVal lineStyle As SimpleLineStyle _
    ) As CIMStroke

    Parameters

    color
    ArcGIS.Core.CIM.CIMColor
    width
    The width of stroke to construct.
    lineStyle
    SimpleLineStyle

    Return Value

    Example
    Create rectangle graphic with simple symbology
    {
      //Create a simple 2D rectangle graphic and apply simple fill and
      //outline symbols.
    
      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);
    
      Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
    
      //Set symbology, 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);
    
    
      GraphicElement recElm = ElementFactory.Instance.CreateGraphicElement(
        layout, rec_env, polySym, "New Rectangle");
      //Or use Predefined shape
      GraphicElement recElm2 = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                                layout, PredefinedShape.Rectangle, rec_env, polySym,
                                "New Rectangle2");
      });
    }
    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);
    }
    Modify a point symbol created from a character marker
    {
      //create marker from the Font, char index,size,color
      await QueuedTask.Run(() =>
      {
        var cimMarker = SymbolFactory.Instance.ConstructMarker(125, "Wingdings 3", "Regular", 6, ColorFactory.Instance.BlueRGB) as CIMCharacterMarker;
        var polygonMarker = cimMarker.Symbol;
        //modifying the polygon's outline and fill
        //This is the outline
        polygonMarker.SymbolLayers[0] = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2, SimpleLineStyle.Solid);
        //This is the fill
        polygonMarker.SymbolLayers[1] = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.BlueRGB);
        //create a symbol from the marker
        //Note this overload of ConstructPointSymbol does not need to be run within QueuedTask.Run.
        var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(cimMarker);
      });
    }
    Clip Map to the provided clip polygon
    {
      var mapToClip = MapView.Active.Map;
      await QueuedTask.Run(() =>
      {
        //A layer to use for the clip extent
        var lyrOfInterest = mapToClip.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name == "TestPoly").FirstOrDefault();
        //Get the polygon to use to clip the map
        var extent = lyrOfInterest.QueryExtent();
        var polygonForClipping = PolygonBuilderEx.CreatePolygon(extent);
        //Clip the map using the layer's extent
        mapToClip.SetClipGeometry(polygonForClipping,
              SymbolFactory.Instance.ConstructLineSymbol(
              SymbolFactory.Instance.ConstructStroke(
                ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Dash)));
      });
    }
    Modify symbology of a Graphic Element
    {
      await QueuedTask.Run(() =>
      {
        //get the first line element in the layer
        var ge = graphicsLayer.FindElement("Line 10") as GraphicElement;
        var graphic = ge.GetGraphic();
        if (graphic is CIMLineGraphic lineGraphic)
        {
          //change its symbol
          lineGraphic.Symbol =
           SymbolFactory.Instance.ConstructLineSymbol(
             SymbolFactory.Instance.ConstructStroke(
         ColorFactory.Instance.BlueRGB, 2, SimpleLineStyle.DashDot)).MakeSymbolReference();
          //apply the change
          ge.SetGraphic(lineGraphic);
        }
      });
    }
    Simple Renderer for a Polygon feature layer.
    /// <summary>
    /// Renders a Polygon feature layer using a single symbol.
    /// ![Simple Renderer for Polygon features](https://ArcGIS.github.io/arcgis-pro-sdk/images/Renderers/simple-polygon.png)
    /// </summary>
    {
      //Check feature layer name
      //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
      var featureLayer = activeMap.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics");
      if (featureLayer == null)
      {
        MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
      }
      //Creating a polygon with a red fill and blue outline.
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
            ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(
            ColorFactory.Instance.CreateRGBColor(255, 190, 190), SimpleFillStyle.Solid, outline);
      await QueuedTask.Run(() =>
      {
        //Get the layer's current renderer
        CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
    
        //Update the symbol of the current simple renderer
        renderer.Symbol = fillWithOutline.MakeSymbolReference();
    
        //Update the feature layer renderer
        featureLayer.SetRenderer(renderer);
      });
    }
    Custom fill and outline
    /// <summary>
    /// Creates a point symbol with custom fill and outline
    /// ![PointSymbolMarker](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/point-fill-outline.png)
    /// </summary>
    {
      //Note: Run withing QueuedTask
      var circlePtCustomFileOutlineSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlueRGB, 6, SimpleMarkerStyle.Circle);
      //Modifying this point symbol with the attributes we want.
      //getting the marker that is used to render the symbol
      var marker = circlePtCustomFileOutlineSymbol.SymbolLayers[0] as CIMVectorMarker;
      //Getting the polygon symbol layers components in the marker
      var polySymbol = marker.MarkerGraphics[0].Symbol as CIMPolygonSymbol;
      //modifying the polygon's outline and width per requirements
      polySymbol.SymbolLayers[0] = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid); //This is the outline
      polySymbol.SymbolLayers[1] = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.GreenRGB); //This is the fill
      //To apply the symbol to a point feature layer
      //var renderer = pointLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = circlePtCustomFileOutlineSymbol.MakeSymbolReference();
      //pointLayer.SetRenderer(renderer);
    }
    Diagonal cross hatch fill
    /// <summary>
    /// Create a polygon symbol with a diagonal cross hatch fill. <br/>
    /// ![PolygonSymbolDiagonalCrossHatch](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/polygon-diagonal-crosshatch.png)
    /// </summary>
    {
      var trans = 50.0;//semi transparent
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid);
    
      //Stroke for the fill
      var solid = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(255, 0, 0, trans), 1.0, SimpleLineStyle.Solid);
    
      //Mimic cross hatch
      CIMFill[] diagonalCross =
                {
                  new CIMHatchFill() {
                      Enable = true,
                      Rotation = 45.0,
                      Separation = 5.0,
                      LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { solid } }
                  },
                  new CIMHatchFill() {
                      Enable = true,
                      Rotation = -45.0,
                      Separation = 5.0,
                      LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { solid } }
                  }
        };
      List<CIMSymbolLayer> symbolLayers =
        [
          outline, .. diagonalCross
        ];
      //This is the polygon symbol with a diagonal cross hatch fill
      CIMPolygonSymbol diagonalCrossHatchFillSymbol = new()
      {
        SymbolLayers = [.. symbolLayers]
      };
      //To apply the symbol to a polygon feature layer
      //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = diagonalCrossHatchFillSymbol.MakeSymbolReference();
      //theLayer.SetRenderer(renderer);
    }
    Cross hatch
    /// <summary>
    /// Create a polygon symbol using the ConstructHatchFill method . <br/>
    /// ![PolygonSymbolDiagonalCrossHatch](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/ConstructHatchFill.png)
    /// </summary>
    {
      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()
      {
        hatchFill
      };
      //This is the polygon symbol with a diagonal cross hatch fill
      CIMPolygonSymbol crossHatchPolygonSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
      //To apply the symbol to a polygon feature layer
      //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = crossHatchPolygonSymbol.MakeSymbolReference();
      //theLayer.SetRenderer(renderer);
    }
    Dash dot fill
    /// <summary>
    /// Create a polygon symbol with a dash dot fill. <br/>
    /// ![PolygonSymbolDashDot](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/polygon-dash-dot.png)
    /// </summary>
    {
      //Note: Run withing QueuedTask
      var trans = 50.0;//semi transparent
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid);
    
      //Stroke for the fill
      var dashDot = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.RedRGB, 1.0, SimpleLineStyle.DashDotDot);
      //Mimic cross hatch
      CIMFill[] solidColorHatch =
            {
    
               new CIMHatchFill()
              {
                  Enable = true,
                  Rotation = 0.0,
                  Separation = 2.5,
                  LineSymbol = new CIMLineSymbol(){SymbolLayers = new CIMSymbolLayer[1] {dashDot } }
              },
               new CIMSolidFill()
              {
                  Enable = true,
                  Color = ColorFactory.Instance.CreateRGBColor(255, 255, 0)
              },
    };
      List<CIMSymbolLayer> symbolLayers = [outline, .. solidColorHatch];
      //This is the polygon symbol with a dash dot fill
      CIMPolygonSymbol dashDotFillPolygon = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
      //To apply the symbol to a polygon feature layer
      //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = dashDotFillPolygon.MakeSymbolReference();
      //theLayer.SetRenderer(renderer);
    }
    Gradient color fill using CIMGradientFill
    /// <summary>
    /// Create a polygon symbol with a gradient color fill. <br/>
    /// ![PolygonSymbolGradientColor](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/polygon-gradient-color.png)
    /// 1. Create a solid colored stroke with 50% transparency
    /// 1. Create a fill using gradient colors red through green
    /// 1. Apply both the stroke and fill as a symbol layer array to the new PolygonSymbol
    /// </summary>
    {
      //Note: Run withing QueuedTask
      var trans = 50.0;//semi transparent
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid);
      //Mimic cross hatch
      CIMFill solidColorHatch =
             new CIMGradientFill()
             {
               ColorRamp = ColorFactory.Instance.ConstructColorRamp(ColorRampAlgorithm.LinearContinuous,
                                    ColorFactory.Instance.RedRGB, ColorFactory.Instance.GreenRGB)
             };
      List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer>
        {
                  outline,
                  solidColorHatch
        };
    
      CIMPolygonSymbol gradientColorFillPolygon = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
      //To apply the symbol to a polygon feature layer
      //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = gradientColorFillPolygon.MakeSymbolReference();
      //theLayer.SetRenderer(renderer);
    }
    Gradient fill using Color ramp
    /// <summary>
    /// Create a polygon symbol using the ConstructGradientFill method. Constructs a gradient fill using the specified color ramp. <br/>
    /// ![PolygonSymbolColorRamp](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/PolygonSymbolColorRamp.png)
    /// </summary>
    {
      //Note: Run withing QueuedTask
      //outine
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(49, 49, 49), 2.0, SimpleLineStyle.Solid);
    
      //gradient fill using a color ramp
      var gradientFill = SymbolFactory.Instance.ConstructGradientFill(GetColorRamp(), GradientFillMethod.Linear);
    
      List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer>
        {
                  outline,
                  gradientFill
        };
      CIMPolygonSymbol gradientColorRampSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
      //To apply the symbol to a polygon feature layer
      //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = gradientColorRampSymbol.MakeSymbolReference();
      //theLayer.SetRenderer(renderer);
    
      //Helper method to get a color ramp from the "ArcGIS Colors" style.
      static CIMColorRamp GetColorRamp()
      {
        //Get a ColorRamp
        StyleProjectItem style =
                Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS Colors");
        var colorRampList = style.SearchColorRamps("Heat Map 4 - Semitransparent");
    
        CIMColorRamp colorRamp = colorRampList[0].ColorRamp;
        return colorRamp;
      }
    }
    Picture fill
    /// <summary>
    /// Constructs a picture fill with the specified parameters.
    /// ![ConstructPictureFill](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/ConstructPictureFill.png)
    /// </summary>
    {
      //Note: Run withing QueuedTask
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(110, 110, 110), 2.0, SimpleLineStyle.Solid);
      //picture
      var imgPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images\CaliforniaEmblem.png");
      var pictureFill = SymbolFactory.Instance.ConstructPictureFill(imgPath, 64);
    
      List<CIMSymbolLayer> symbolLayers = new()
      {
        outline,
        pictureFill
      };
      CIMPolygonSymbol pictureFillPolygonSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
      //To apply the symbol to a polygon feature layer
      //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = pictureFillPolygonSymbol.MakeSymbolReference();
      //theLayer.SetRenderer(renderer);
    }
    Animation water
    /// <summary>
    /// Constructs a water fill of specific color, waterbody size and wave strength. This fill can be used on polygon feature classes in a Scene view only.
    /// ![ConstructWaterFill](https://ArcGIS.github.io/arcgis-pro-sdk/images/Symbology/waterAnimation.gif)
    /// </summary>
    {
      //Note: Run withing QueuedTask
    
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(49, 49, 49, 50.0), 2.0, SimpleLineStyle.Solid);
      var waterFill = SymbolFactory.Instance.ConstructWaterFill(CIMColor.CreateRGBColor(3, 223, 252), WaterbodySize.Large, WaveStrength.Rippled);
      List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer>
        {
                  outline,
                  waterFill
        };
      CIMPolygonSymbol waterFillPolygonSymbol = new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
      //To apply the symbol to a polygon feature layer
      //var renderer = theLayer.GetRenderer() as CIMSimpleRenderer;
      //renderer.Symbol = waterFillPolygonSymbol.MakeSymbolReference();
      //theLayer.SetRenderer(renderer);
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also