After creating a basicRasterLayer and setting the colorizer as shown in the code below.
How would the labels and label format be set?
The code used to colorize the raster copied from lines 147 to 171 in the ArcGIS Pro SDK Community Samples shown in this link.
This code does not pertain to this problem other than the next step in this coding project is to change the "Value" field label to "Custom". Then change the formatting of the "Custom" field to show 1 decimal place.
These 2 operations need to be applied to the same basicRasterLayer that is called in the SetToClassifyColorColorizer () method shown below.
public static async Task SetToClassifyColorizer(BasicRasterLayer basicRasterLayer)
{
// Defines values for parameters in colorizer definition.
string fieldName = "Value";
ClassificationMethod classificationMethod = ClassificationMethod.NaturalBreaks;
int numberofClasses = 7;
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;
// Sets the newly created colorizer on the layer.
basicRasterLayer.SetColorizer(newColorizer);
});
}
Solved! Go to Solution.
You can get minimum value of breaks from CIMRasterClassifyColorizer MinimumBreak property.
I would recommend you to download from Esri git CIMViewer source code, build add-in for ArcGIS Pro and you can investigate each ArcGIS Pro CIM element you selected.
I have found that CIMRasterClassifyColorizer has CIMRasterClassifyColorizer has property RoundingValue property which changes when you make changes from Symbology dockpane but I haven't tested it from code. Look at CIMViewer printscreen below
Hi,
You can set class label as you want. It could be text, number or etc. Add code below after creating newColorizer:
int index = 0;
var classBreaks = newColorizer.ClassBreaks;
foreach (var classBreak in classBreaks)
{
index++;
classBreak.Label = classBreak.Label + $"({index})";
}
In my code I just added index of class to existing label. You can read class break values and format label as you wish.
To change "Value" is impossible I think. It shows raster table field name used for class breaks.
Workaround I can suggest is to create additional raster field and copy Value field values. But it could be difficult because raster table field names has similar rules as database table field name.
This works perfectly to set the format of the characters... Thank You 🙂
Regarding the "Value" field. I think that I presented the problem incorrectly. The goal is not to change the name of the "Value" field. The goal is to set an alias for the name of the "Value" field... just like an alias can be set for a field name in a feature class attribute field.
The is easily done to a raster layer in ArcGIS Pro by making the "Value" field active then pressing F2... and entering whatever alias is wanted for a label.
There must be a way to do this with code.
The code you provide works very well... except for the lowerBound of the classBreaks[0].Label
I modified your code a little and the output is almost perfect.
Intuitively, it seems like there should be a property BasicRasterLayer.MinimumValue. However, that does not appear to be available. Do you have a suggestion for obtaining the statistics of a BasicRasterLayer?
var classBreaks = newColorizer.ClassBreaks;
classBreaks[0].Label = "? - " + Math.Round(classBreaks[0].UpperBound, 1).ToString();
for (int i = 1; i < classBreaks.Length; i++)
{
string lowerBound = Math.Round(classBreaks[i - 1].UpperBound, 1).ToString();
string upperBound = Math.Round(classBreaks[i].UpperBound, 1).ToString();
classBreaks[i].Label = lowerBound + " - " + upperBound;
}
You can get minimum value of breaks from CIMRasterClassifyColorizer MinimumBreak property.
I would recommend you to download from Esri git CIMViewer source code, build add-in for ArcGIS Pro and you can investigate each ArcGIS Pro CIM element you selected.
I have found that CIMRasterClassifyColorizer has CIMRasterClassifyColorizer has property RoundingValue property which changes when you make changes from Symbology dockpane but I haven't tested it from code. Look at CIMViewer printscreen below
Thank You very much. That worked. I will download the CIMViewer and play with it.