I have created a raster layer programmatically by loading in a netCDF file into a RasterDataset and then creating a ClassifyColorizerDefinition. I use these to create the raster layer from a LayerFactory after targeting the file URI. This works and I am able to create a raster layer overlayed on my map; however, I am having problems setting the colors exactly as desired. I have a chosen color scheme for the Classify symbology, but I am unable to set the Upper Values of the Classes within my Symbology programmatically. I cannot seem to find where these are exposed in the SDK.
Could anyone point me in the right direction? I am using the ArcGIS Pro 3.0 SDK for C#
Solved! Go to Solution.
Hi,
You can change UpperBound values in created CIMRasterClassifyColorizer.
public static async Task SetToClassifyColorizer(BasicRasterLayer basicRasterLayer)
{
// Defines values for parameters in colorizer definition.
string fieldName = "Value";
ClassificationMethod classificationMethod = ClassificationMethod.Manual;
int numberofClasses = 4;
List<double> values = new List<double>() { 2.0, 4.0, 6.0, 140.85 };
string colorRampStyle = "ArcGIS Colors";
string colorRampName = "Aspect";
await QueuedTask.Run(async () =>
{
// Gets a color ramp from a style.
IList<ColorRampStyleItem> rampList = GetColorRampsFromStyleAsync(Project.Current, colorRampStyle, colorRampName);
CIMColorRamp colorRamp = rampList[0].ColorRamp;
// Creates a new Classify Colorizer Definition using defined parameters.
ClassifyColorizerDefinition classifyColorizerDef = new ClassifyColorizerDefinition(fieldName, numberofClasses, classificationMethod, colorRamp);
// Creates a new Classify colorizer using the colorizer definition created above.
CIMRasterClassifyColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(classifyColorizerDef) as CIMRasterClassifyColorizer;
var classBreaks = newColorizer.ClassBreaks.ToList();
int counter = 0;
foreach(var classbreak in classBreaks)
{
classbreak.UpperBound = values[counter];
counter++;
}
newColorizer.ClassBreaks = classBreaks.ToArray();
// Sets the newly created colorizer on the layer.
basicRasterLayer.SetColorizer(newColorizer);
});
}
Hi,
You can change UpperBound values in created CIMRasterClassifyColorizer.
public static async Task SetToClassifyColorizer(BasicRasterLayer basicRasterLayer)
{
// Defines values for parameters in colorizer definition.
string fieldName = "Value";
ClassificationMethod classificationMethod = ClassificationMethod.Manual;
int numberofClasses = 4;
List<double> values = new List<double>() { 2.0, 4.0, 6.0, 140.85 };
string colorRampStyle = "ArcGIS Colors";
string colorRampName = "Aspect";
await QueuedTask.Run(async () =>
{
// Gets a color ramp from a style.
IList<ColorRampStyleItem> rampList = GetColorRampsFromStyleAsync(Project.Current, colorRampStyle, colorRampName);
CIMColorRamp colorRamp = rampList[0].ColorRamp;
// Creates a new Classify Colorizer Definition using defined parameters.
ClassifyColorizerDefinition classifyColorizerDef = new ClassifyColorizerDefinition(fieldName, numberofClasses, classificationMethod, colorRamp);
// Creates a new Classify colorizer using the colorizer definition created above.
CIMRasterClassifyColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(classifyColorizerDef) as CIMRasterClassifyColorizer;
var classBreaks = newColorizer.ClassBreaks.ToList();
int counter = 0;
foreach(var classbreak in classBreaks)
{
classbreak.UpperBound = values[counter];
counter++;
}
newColorizer.ClassBreaks = classBreaks.ToArray();
// Sets the newly created colorizer on the layer.
basicRasterLayer.SetColorizer(newColorizer);
});
}