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
Create a line symbol with the markers placed at a 45 degree angle.
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;
});
}
Create a line symbol with a dash and two markers.
This line symbol comprises three symbol layers listed below:
- A solid stroke that has dashes.
- A circle marker.
- A square marker.
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;
}
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:
- A solid stroke that has dashes.
- A circle marker.
- A square marker.
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;
});
}
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.
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;
});
}
Creates Mesh procedural symbol with various textures. 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;
});
}
Creates a point symbol with custom fill and outline
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;
});
}
Create a point symbol from a character in a font file
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);
});
}
Create a polygon symbol with a cross hatch fill.
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() };
});
}
Create a polygon symbol with a diagonal cross hatch fill.
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() };
});
}
Create a polygon symbol with a dash dot fill.
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() };
});
}
Create a polygon symbol with a gradient color fill.
- Create a solid colored stroke with 50% transparency
- Create a fill using gradient colors red through green
- 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() };
});
}
Create a procedural symbol that can be applied to a polygon building footprint layer 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;
});
}