Set break values for 'Manual' GraduatedColorsRendererDefinition

1413
3
02-22-2017 08:22 AM
AdrianBirch
New Contributor

I want to create a GraduatedColorsRendererDefinition using the 'Manual' classification method (in order to set breaks at unequal intervals (for example at 0.4, 0.7, 0.9, 1). Where can I set the required break values? I can't see the appropriate member on GraduatedColorsRendererDefinition. Other classification methods (defined interval, for example) work fine.

// Apply renderer and add output to map
Uri uri = new Uri(OutputPath);
string colorBrewerSchemesName = "ArcGIS Colors";
StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
string colorRampName = "Red to Green";
IList<ColorRampStyleItem> colorRampList = await style.SearchColorRampsAsync(colorRampName);
ColorRampStyleItem colorRamp = colorRampList[0];
CIMStroke outline = SymbolFactory.ConstructStroke(ColorFactory.GreyRGB, 0, SimpleLineStyle.Solid);
await QueuedTask.Run(() =>
{
    GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
    {
        ClassificationField = "VALUE",

        // Defined Interval works fine
        //ClassificationMethod = ClassificationMethod.DefinedInterval,
        //IntervalSize = 0.2,

        // How to set breaks for Manual classification method?
        ClassificationMethod = ClassificationMethod.Manual,
        // Set break values?

        ColorRamp = colorRamp.ColorRamp,
        SymbolTemplate = SymbolFactory.ConstructPolygonSymbol(
        ColorFactory.GreenRGB, SimpleFillStyle.Solid, outline).MakeSymbolReference(),
    };
    FeatureLayer outLyr = LayerFactory.CreateFeatureLayer(uri, MapView.Active.Map, rendererDefinition: gcDef);
});
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (1)
0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Hi Adrian,

The GraduatedColorsRendererDefinition cannot be used for Manual breaks. Instead you can edit the CIM directly to accomplish this.  Here is a code snippet below to do this:

            var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();

            List<CIMClassBreak> listClassBreaks = new List<CIMClassBreak>
            {
                new CIMClassBreak
                {
                    Symbol = SymbolFactory.ConstructPolygonSymbol(ColorFactory.RedRGB).MakeSymbolReference(),
                    UpperBound = 56
                },
                new CIMClassBreak
                {
                    Symbol = SymbolFactory.ConstructPolygonSymbol(ColorFactory.GreenRGB).MakeSymbolReference(),
                    UpperBound = 68
                },
                new CIMClassBreak
                {
                    Symbol = SymbolFactory.ConstructPolygonSymbol(ColorFactory.BlueRGB).MakeSymbolReference(),
                    UpperBound = 77
                }
            };
            CIMClassBreaksRenderer cimClassBreakRenderer = new CIMClassBreaksRenderer
            {
                ClassBreakType = ClassBreakType.GraduatedColor,
                ClassificationMethod = ClassificationMethod.Manual,
                Field = "Y2008_VOTE",
                Breaks = listClassBreaks.ToArray()
            };
            await QueuedTask.Run(() =>
            {
                lyr?.SetRenderer(cimClassBreakRenderer);
            });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
 

Thanks

Uma Harano

ArcGIS Pro SDK Team

AdrianBirch
New Contributor

Thanks Uma,

I've been looking at this again, but I'm still unable to get to where I want. I want to use a colour ramp (instead of defining a symbol explicitly for each break), but the ColorRamp and DefaultSymbol properties on CIMClassBreaksRenderer seems to get ignored when I set them. I also want to set the 'out of range' symbol on, but this doesn't seem to be possible with CIMClassBreaksRenderer either.

I'd like to achieve the settings in the attached screengrab through the API - is this currently possible?

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Adrian

With Pro 1.4 it is not possible to get colors from the ColorRamp to use in the class break renderer - you will have to define the symbol explicitly for each break.  We will look into methods to work with the color ramp in future releases.

Regarding setting the default symbol and out of range color and label, I got this code below to do that. I had to set the UseDefaultSymbol = true flag to get it to work.  Code snippet below:

 var defaultSymbolReference =
                SymbolFactory.ConstructPolygonSymbol(ColorFactory.GreyRGB, SimpleFillStyle.Solid).MakeSymbolReference();

CIMClassBreaksRenderer cimClassBreakRenderer = new CIMClassBreaksRenderer
            {
                ClassBreakType = ClassBreakType.GraduatedColor,
                ClassificationMethod = ClassificationMethod.Manual,
                Field = "Y2008_VOTE",
                Breaks = listClassBreaks.ToArray(),
                UseDefaultSymbol = true,
                DefaultSymbol = defaultSymbolReference,
                DefaultLabel = "<out of range>"
            };

Thanks

Uma Harano

Pro SDK Team

0 Kudos