ProSnippets Symbology - kataya/arcgis-pro-sdk GitHub Wiki

All ProSnippets listed here are also used by the following sample code: Symbology sample code

Language:              C#  
Subject:               Map-Authoring  
Contributor:           ArcGIS Pro SDK Team <[email protected]>  
Organization:          esri, http://www.esri.com  
Date:                  12/11/2020  
ArcGIS Pro:            2.7  
Visual Studio:         2017, 2019  
.NET Target Framework: 4.8  

LineSymbology

Markers placed at a 45 degree angle

Create a line symbol with the markers placed at a 45 degree angle.
LineSymbolAngleMarker

internal static Task<CIMLineSymbol> CreateMyMarkerLineSymbolAsync()
{
    return QueuedTask.Run<CIMLineSymbol>(() =>
    {
        //Create a marker from the "|" character.  This is the marker that will be used to render the line layer.
        var lineMarker = SymbolFactory.Instance.ConstructMarker(124, "Agency FB", "Regular", 12);

        //Default line symbol which will be modified 
        var blackSolidLineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid);

        //Modifying the marker to align with line
        //First define "markerplacement"
        CIMMarkerPlacementAlongLineSameSize markerPlacement = new CIMMarkerPlacementAlongLineSameSize()
        {
            AngleToLine = true,
            ControlPointPlacement = PlacementEndings.WithMarkers,
            PlacementTemplate = new double[] { 5 }
        };
        //assign the markerplacement to the marker
        lineMarker.MarkerPlacement = markerPlacement;
        //angle the marker if needed
        lineMarker.Rotation = 45;

        //assign the marker as a layer to the line symbol
        blackSolidLineSymbol.SymbolLayers[0] = lineMarker;

        return blackSolidLineSymbol;
    });
}

Dash line with two markers - Method I

Create a line symbol with a dash and two markers.

This line symbol comprises three symbol layers listed below:

  1. A solid stroke that has dashes.
  2. A circle marker.
  3. A square marker. LineSymbolTwoMarkers
internal static Task<CIMLineSymbol> CreateLineDashTwoMarkersAync()
{
    return QueuedTask.Run<CIMLineSymbol>(() =>
    {

        var dash2MarkersLine = new CIMLineSymbol();

        var mySymbolLyrs = new CIMSymbolLayer[]
        {
            new CIMSolidStroke()
            {
                Color = ColorFactory.Instance.BlackRGB,
                Enable = true,
                ColorLocked = true,
                CapStyle = LineCapStyle.Round,
                JoinStyle = LineJoinStyle.Round,
                LineStyle3D = Simple3DLineStyle.Strip,
                MiterLimit = 10,
                Width = 1,
                CloseCaps3D = false,
                Effects = new CIMGeometricEffect[]
                {
                    new CIMGeometricEffectDashes()
                    {
                        CustomEndingOffset = 0,
                        DashTemplate = new double[] {20, 10, 20, 10},
                        LineDashEnding = LineDashEnding.HalfPattern,
                        OffsetAlongLine = 0,
                        ControlPointEnding = LineDashEnding.NoConstraint
                    },
                    new CIMGeometricEffectOffset()
                    {
                        Method = GeometricEffectOffsetMethod.Bevelled,
                        Offset = 0,
                        Option = GeometricEffectOffsetOption.Fast
                    }
                },
            },
            CreateCircleMarkerPerSpecs(),
            CreateSquareMarkerPerSpecs()
        };
        dash2MarkersLine.SymbolLayers = mySymbolLyrs;
        return dash2MarkersLine;
    });
}
private static CIMMarker CreateCircleMarkerPerSpecs()
{
    var circleMarker = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.BlackRGB, 5, SimpleMarkerStyle.Circle) as CIMVectorMarker;
    //Modifying the marker to align with line
    //First define "markerplacement"
    CIMMarkerPlacementAlongLineSameSize markerPlacement = new CIMMarkerPlacementAlongLineSameSize()
    {
        AngleToLine = true,
        Offset = 0,
        ControlPointPlacement = PlacementEndings.WithMarkers,
        Endings = PlacementEndings.Custom,
        OffsetAlongLine = 15,
        PlacementTemplate = new double[] { 60 }
    };
    //assign the markerplacement to the marker
    circleMarker.MarkerPlacement = markerPlacement;
    return circleMarker;
}
private static CIMMarker CreateSquareMarkerPerSpecs()
{
    var squareMarker = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.BlueRGB, 5, SimpleMarkerStyle.Square) as CIMVectorMarker;
    CIMMarkerPlacementAlongLineSameSize markerPlacement2 = new CIMMarkerPlacementAlongLineSameSize()
    {
        AngleToLine = true,
        Endings = PlacementEndings.Custom,
        OffsetAlongLine = 45,
        PlacementTemplate = new double[] { 60 },
    };
    squareMarker.MarkerPlacement = markerPlacement2;
    return squareMarker;
}

Dash line with two markers - Method II

Create a line symbol with a dash and two markers.
In this pattern of creating this symbol, a CIMVectorMarker object is created as a new CIMSymbolLayer. The circle and square markers created by ContructMarker method is then assigned to the MarkerGraphics property of the CIMVectorMarker. When using this method, the CIMVectorMarker's Frame property needs to be set to the CIMMarker object's Frame. Similarly, the CIMVectorMarker's Size property needs to be set to the CIMMarker object's size.

This line symbol comprises three symbol layers listed below:

  1. A solid stroke that has dashes.
  2. A circle marker.
  3. A square marker. LineSymbolTwoMarkers
internal static Task<CIMLineSymbol> CreateLineDashTwoMarkers2Async()
{
    return QueuedTask.Run<CIMLineSymbol>(() =>
    {
        //default line symbol that will get modified.
        var dash2MarkersLine = new CIMLineSymbol();
        //circle marker to be used in our line symbol as a layer
        var circleMarker = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.BlackRGB, 5, SimpleMarkerStyle.Circle) as CIMVectorMarker;
        //circle marker to be used in our line symbol as a layer
        var squareMarker = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.BlueRGB, 5, SimpleMarkerStyle.Square) as CIMVectorMarker;
        //Create the array of layers that make the new line symbol
        CIMSymbolLayer[] mySymbolLyrs =
        {
            new CIMSolidStroke() //dash line
            {
                Color = ColorFactory.Instance.BlackRGB,
                Enable = true,
                ColorLocked = true,
                CapStyle = LineCapStyle.Round,
                JoinStyle = LineJoinStyle.Round,
                LineStyle3D = Simple3DLineStyle.Strip,
                MiterLimit = 10,
                Width = 1,
                CloseCaps3D = false,
                Effects = new CIMGeometricEffect[]
                {
                    new CIMGeometricEffectDashes()
                    {
                        CustomEndingOffset = 0,
                        DashTemplate = new double[] {20, 10, 20, 10},
                        LineDashEnding = LineDashEnding.HalfPattern,
                        OffsetAlongLine = 0,
                        ControlPointEnding = LineDashEnding.NoConstraint
                    },
                    new CIMGeometricEffectOffset()
                    {
                        Method = GeometricEffectOffsetMethod.Bevelled,
                        Offset = 0,
                        Option = GeometricEffectOffsetOption.Fast
                    }
                }
            },
            new CIMVectorMarker() //circle marker
            {
                MarkerGraphics = circleMarker.MarkerGraphics,
                Frame = circleMarker.Frame, //need to match the CIMVector marker's frame to the circleMarker's frame.
                Size = circleMarker.Size,    //need to match the CIMVector marker's size to the circleMarker's size.                    
               MarkerPlacement = new CIMMarkerPlacementAlongLineSameSize()
               {
                   AngleToLine = true,
                   Offset = 0,
                   ControlPointPlacement = PlacementEndings.WithMarkers,
                   Endings = PlacementEndings.Custom,
                   OffsetAlongLine = 15,
                   PlacementTemplate = new double[] {60},
               }
               
            },
            new CIMVectorMarker() //square marker
            {
               MarkerGraphics = squareMarker.MarkerGraphics,
               Frame = squareMarker.Frame, //need to match the CIMVector marker's frame to the squareMarker frame.
               Size = squareMarker.Size, //need to match the CIMVector marker's size to the squareMarker size.
               MarkerPlacement = new CIMMarkerPlacementAlongLineSameSize()
               {
                   AngleToLine = true,
                   Endings = PlacementEndings.Custom,
                   OffsetAlongLine = 45,
                   PlacementTemplate = new double[] {60},
               }                       
            }
        };
        dash2MarkersLine.SymbolLayers = mySymbolLyrs;
        return dash2MarkersLine;
    });

}

MeshSymbology

Mesh material fill symbol

Create a mesh symbol that can be applied to a multi-patch feature layer.

A mesh symbol is a CIMMeshSymbol object. Define an array of CIMSymbolLayers which contains a CIMMaterialSymbol layer with the specified properties such as Color, etc. Assign this array of CIMSymbolLayers to the CIMMeshSymbol. MeshSymbolOrange

public static Task<CIMMeshSymbol> CreateMeshSymbolAsync()
{
    return QueuedTask.Run<CIMMeshSymbol>(() =>
   {
       CIMSymbolLayer[] materialSymbolLayer =
      {
            new CIMMaterialSymbolLayer()
            {
                Color = ColorFactory.Instance.CreateRGBColor(230,152,0),
                MaterialMode = MaterialMode.Multiply
            }
       };
       var myMeshSymbol = new CIMMeshSymbol()
       {
           SymbolLayers = materialSymbolLayer
       };
       return myMeshSymbol;
   });
}

Mesh procedural texture symbol

Creates Mesh procedural symbol with various textures. MeshProceduralTexture Note: The rule package used in this method can be obtained from the Sample Data included in the arcgis-pro-sdk-community-samples repository.

private static readonly string _rulePkgPath = @"C:\Data\RulePackages\MultipatchTextures.rpk";
public static Task<CIMMeshSymbol> CreateProceduralMeshSymbolAsync()
{
    return QueuedTask.Run<CIMMeshSymbol>(() =>
    {                  
        CIMSymbolLayer[] proceduralSymbolLyr =
        {
            new CIMProceduralSymbolLayer()
            {
                PrimitiveName = "Textures",
                RulePackage = _rulePkgPath,
                RulePackageName = "Textures",
            }
        };
        var myMeshSymbol = new CIMMeshSymbol()
        {
            SymbolLayers = proceduralSymbolLyr
        };

        return myMeshSymbol;
    });
}

PointSymbology

Custom fill and outline

Creates a point symbol with custom fill and outline PointSymbolMarker

internal static Task<CIMPointSymbol> CreatePointSymbolAsync()
{
    return QueuedTask.Run<CIMPointSymbol>(() =>
    {
         var circlePtSymbol = 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 = circlePtSymbol.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.BlueRGB); //This is the fill
        return circlePtSymbol;              
    });           
    
}

Point Symbol from a font

Create a point symbol from a character in a font file PointSymbolFont

internal static Task<CIMPointSymbol> CreateMarkerSymbolAsync()
{           
    //Construct point symbol from marker
    return QueuedTask.Run<CIMPointSymbol>(() => {
        //creating the marker from the Font selected
        var cimMarker = SymbolFactory.Instance.ConstructMarker(47, "Wingdings 3", "Regular", 12);
        return SymbolFactory.Instance.ConstructPointSymbol(cimMarker);
    });

}

PolygonSymbology

Cross hatch fill

Create a polygon symbol with a cross hatch fill.
PolygonSymbolCrossHatch

public static Task<CIMPolygonSymbol> CreateCrossHatchPolygonAsync()
{
    return QueuedTask.Run<CIMPolygonSymbol>(() =>
    {
        var trans = 50.0;//semi transparent
        CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid);

        //Stroke for the hatch fill
        var dash = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(255, 170, 0, trans), 1.0, SimpleLineStyle.Dash);

        //Mimic cross hatch
        CIMFill[] crossHatch =
            {
            new CIMHatchFill() {
                Enable = true,
                Rotation = 0.0,
                Separation = 5.0,
                LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { dash } }
            },
            new CIMHatchFill() {
                Enable = true,
                Rotation = 90.0,
                Separation = 5.0,
                LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { dash } }
            }
        };
        List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer>();
        symbolLayers.Add(outline);
        foreach (var fill in crossHatch)
            symbolLayers.Add(fill);
        return new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
    });
   
}

Diagonal cross hatch fill

Create a polygon symbol with a diagonal cross hatch fill.
PolygonSymbolDiagonalCrossHatch

public static Task<CIMPolygonSymbol> CreateDiagonalCrossPolygonAsync()
{
    return QueuedTask.Run<CIMPolygonSymbol>(() =>
    {
        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 = new List<CIMSymbolLayer>();
        symbolLayers.Add(outline);
        foreach (var fill in diagonalCross)
            symbolLayers.Add(fill);
        return new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
    });
}

Dash dot fill

Create a polygon symbol with a dash dot fill.
PolygonSymbolDashDot

public static Task<CIMPolygonSymbol> CreateDashDotFillAsync()
{
    return QueuedTask.Run<CIMPolygonSymbol>(() =>
    {
        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 = new List<CIMSymbolLayer>();
        symbolLayers.Add(outline);
        foreach (var fill in solidColorHatch)
            symbolLayers.Add(fill);
        return new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
    });          
}

Gradient color fill

Create a polygon symbol with a gradient color fill.
PolygonSymbolGradientColor

  1. Create a solid colored stroke with 50% transparency
  2. Create a fill using gradient colors red through green
  3. Apply both the stroke and fill as a symbol layer array to the new PolygonSymbol
public static Task<CIMPolygonSymbol> CreateGradientFillAsync()
{
    return QueuedTask.Run<CIMPolygonSymbol>(() =>
    {
        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>();
        symbolLayers.Add(outline);
        symbolLayers.Add(solidColorHatch);

        return new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
    });          
}

Procedural Symbol

Create a procedural symbol that can be applied to a polygon building footprint layer ProceduralSymbol Note: The rule package used in this method can be obtained from the Sample Data included in the arcgis-pro-sdk-community-samples repository.

private static readonly string _rulePkgPath = @"C:\Data\RulePackages\Venice_2014.rpk";
public static Task<CIMPolygonSymbol> CreateProceduralPolygonSymbolAsync()
{
    return QueuedTask.Run<CIMPolygonSymbol>(() =>
    {
        //Polygon symbol to hold the procedural layer
        var myPolygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(); 

        //Array of layers to hold a procedural symbol layer
        CIMSymbolLayer[] proceduralSymbolLyr =
        {
            new CIMProceduralSymbolLayer()
            {
                PrimitiveName = "Venice Rule package 2014",
                RulePackage = _rulePkgPath,
                RulePackageName = "Venice_2014",
            }                    
        };
        myPolygonSymbol.SymbolLayers = proceduralSymbolLyr;
        return myPolygonSymbol;
    });
}
⚠️ **GitHub.com Fallback** ⚠️