Select to view content in your preferred language

Update symbol ranges from layer file

1034
3
Jump to solution
02-10-2022 03:31 PM
KisakyeM
Regular Contributor

I am applying symbology from a layer using the code snippet at https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#apply-symbology-to-a-layer-from.... When I use this method to update the symbology for a point layer, the symbols are updated but the symbol classes are maintained; the equivalent of 'maintain ranges' in the ApplySymbologyFromLayer tool. I would like for the symbol classes to be updated to only show the classes that are existent in the current data. Not all the classes from the symbology layer file. The equivalent of this in the ApplySymbologyFromLayer tool would be 'update ranges' and when I run this tool in Pro using 'update ranges', it does what I want.
So the question is how can I use the code below to update symbology ranges and not just maintain them?

var lyrDocFromLyrxFile = new LayerDocument(layerFile);
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
var rendererFromLayerFile = ((CIMFeatureLayer)cimLyrDoc.LayerDefinitions[0]).Renderer as CIMUniqueValueRenderer;
featureLayer?.SetRenderer(rendererFromLayerFile);

@CharlesMacleod @Wolf @UmaHarano 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

I see, then it would have to be done by hand then - as in, rebuild the renderer with the updated classes and current symbology. I can ask the mapping team if there is a way to extend Recalc renderer (or provide a new method) that can retain the current symbology.

View solution in original post

3 Replies
CharlesMacleod
Esri Regular Contributor

can you try doing a RecalculateRenderer(false)....(use "true" if you can have more than 100 unique values and want them all in the legend)

0 Kudos
KisakyeM
Regular Contributor

When I do RecalculateRenderer(false), it overwrites the point symbols retrieved from the layer file and replaces them with default point symbols which is not what I am looking to do.

0 Kudos
CharlesMacleod
Esri Regular Contributor

I see, then it would have to be done by hand then - as in, rebuild the renderer with the updated classes and current symbology. I can ask the mapping team if there is a way to extend Recalc renderer (or provide a new method) that can retain the current symbology.