Change renderer colors

411
4
01-18-2012 04:47 AM
AleydisG__Pere
Occasional Contributor
I must change the symbology of a bunch of layers in an mxd programatically. I have point, line and polygon layers using unique value renderers and class break renderers. The only change needed is the color of the symbol of each unique value/class based on an algorithm, so I've been doing some research to see whether it is likely to make changes to a created renderer without having to extract all its propierties to create it again. So far I don't have much hope about it
Anyway any idea will be really welcome.
Thanks in advance.
0 Kudos
4 Replies
sapnas
by
Occasional Contributor III
You can use IGeoFeatureLayer to change renderer colors. I used following logic to dynamically change the symbology

IGeoFeatureLayer pGeoFLayer = pLayer as IGeoFeatureLayer;
IUniqueValueRenderer uniqueRenderer = pGeoFLayer.Renderer as IUniqueValueRenderer;
uniqueRenderer.set_Symbol("Change", pSimpleFillSymbol as ISymbol);

Hope this helps.
0 Kudos
NeilClemmons
Regular Contributor III
Get a reference to the renderer from IGeoFeatureLayer::Renderer.  QI to the correct renderer type (IUniqueValueRenderer, IClassBreaksRenderer).  Then all you have to do is create the color objects you want and set the symbol properties on the renderer.  The way you access the symbols depends on what type of renderer it is.  That information is all in the developer help.
0 Kudos
PeterCrossing
New Contributor
Get a reference to the renderer from IGeoFeatureLayer::Renderer.  QI to the correct renderer type (IUniqueValueRenderer, IClassBreaksRenderer).  ...


How can you return which renderer a layer is using (in order to QI to the correct renderer type)? Thanks!
0 Kudos
NeilClemmons
Regular Contributor III
You have to test for it using the various renderer interfaces.  In VB, you use TypeOf.  In C# I believe you use Is.

If TypeOf renderer Is IUniqueValueRenderer Then
  Dim uvRenderer As IUniqueValueRenderer = DirectCast(renderer, IUniqueValueRenderer
ElseIf TypeOf renderer Is IClassBreaksRenderer Then
  ' handle this type
End If
0 Kudos