I have feature (polygon) was gotten by spatial query from the map.

How to change its color?

I used this code but it didn't work

IMxDocument mxDocument = application.Document as IMxDocument;
IActiveView activeView = mxDocument.ActiveView;
IRgbColor rgbColor = new RgbColorClass();
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
IElement element = new PolygonElementClass();
rgbColor.Red = 255;
rgbColor.Green = 40;
rgbColor.Blue = 50;
fillSymbol.Color = rgbColor;
element.Geometry = parcel.Shape;
IFillShapeElement pFillElement = (IFillShapeElement)element;
pFillElement.Symbol = fillSymbol;
  • your code does not use the objectid, and also does not add the pFillElement to any layer. – til_b Jul 29 '13 at 10:12
  • @til_b i get the feature by object id. in line 10 i already got the parcel.shap. and about pFillElement i'll search about how i can add it to the layer thanks. – IBRA Jul 29 '13 at 10:41

I resolved this issue by using IGraphicsContainer see this link


My workflow for "re-coloring" features is as follows:

First i setup the layer to be symbolized by categories, and set the correct options, classes, etc. with the normal ArcGIS workflow.

Then I use scripting to set the value of the field the data is colored with to my wanted value.

I use this for a national grid where i want to highlight certain grid cells. The feature class/shapefile is symbolized on the field "selected", displayed as grey when selected=0 and as yellow when selected=1. Then its simply (in python):

with arcpy.da.UpdateCursor(<shapefile to update>, ("ID","selected")) as cursor:
  for data_row in cursor:
    if data_row[0] <should be set to selected>:
      data_row[1] = 1
      data_row[1] = 0

You need to add your element to a graphics layer. See this sample from ESRI.

Dim pCGLayer As ICompositeGraphicsLayer
Set pCGLayer = New CompositeGraphicsLayer

'Name the new graphics layer
Dim pLayer As ILayer
Set pLayer = pCGLayer
pLayer.Name = "TestPoint"

'Add the layer to the map
pMap.AddLayer pCGLayer

'Get the graphics layer and screen display
Dim pGrLayer As IGraphicsLayer
Set pGrLayer = pCGLayer

Dim pScreenDisplay As IScreenDisplay
Set pScreenDisplay = pMxApp.Display

'Add the marker element ot the layer graphics container
Dim pGraphicCont As IGraphicsContainer
Set pGraphicCont = pGrLayer
pGraphicCont.AddElement pMarkerElement, 0
With pScreenDisplay
  .ActiveCache = 0
  .StartDrawing pScreenDisplay.hDC, 0
  .SetSymbol pSimpleMarkerSymbol
  pElement.Draw pScreenDisplay, Nothing
End With

'Refresh/redraw the display with the new point



ESRI.ArcGIS.Display.IColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass(); rgbColor.RGB = 255;

ESRI.ArcGIS.Display.IMarkerSymbol markerSymbol = (ESRI.ArcGIS.Display.IMarkerSymbol)simpleMarker3DSymbol; // Explicit cast markerSymbol.Color = rgbColor; markerSymbol.Size = 100000;


[Visual Basic 6.0]

Dim aColor As IRGBColor 
Set aColor = New RGBColor 

aColor.Red = 133 
aColor.Green = 135 
aColor.Blue = 43 
aColor.Transparency = 50 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.