Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can anyone tell me how to use isimplerender interface to symbolize a polygon layer with graduated colors according to a value of a field such as "population"?

I've used the interface "IUniqueValueRenderer" to symbolize the polygon layer "citys" where each polygon takes the return value from a field "integer"(number of accidents) here is the code that I've used

IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
        string fieldnam = "nombre_d'accident";

        PerformSort(CreateTableSort(pGeoFeatureLayer as ITable,fieldnam));

        IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();

        pRandomColorRamp.MinSaturation = 10;
        pRandomColorRamp.MaxSaturation = 100;
        pRandomColorRamp.MinValue = 90;
        pRandomColorRamp.MaxValue = 100;
        pRandomColorRamp.StartHue = 200;//10:rouge  100:vert   200:bleu   
        pRandomColorRamp.EndHue = 200;
        //pRandomColorRamp.UseSeed = true;
        //pRandomColorRamp.Seed = 100;
        IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();

        ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
        pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross;
        pSimpleFillSymbol.Outline.Width = 2;
        pUniqueValueRenderer.FieldCount = 1;
        pUniqueValueRenderer.set_Field(0, fieldnam);
        pUniqueValueRenderer.DefaultSymbol = pSimpleFillSymbol as ISymbol;
        pUniqueValueRenderer.UseDefaultSymbol = false;

        IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable;
        IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor;
        IFeature pFeature = pFeatureCursor.NextFeature();
        bool ValFound;
        int fieldIndex;

        IFields pFields = pFeatureCursor.Fields;
        fieldIndex = pFields.FindField(fieldnam);
        string xv;
        ISimpleFillSymbol pSimpleFillColor;

        while (pFeature != null)

            ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass();
            pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
            pClassSymbol.Outline.Width = 0.4;

            string classValue;

            classValue = Convert.ToString(pFeature.get_Value(fieldIndex)) ;

            //Test to see if this value was added to the renderer. If not, add it.
            ValFound = false;
            for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
                if (pUniqueValueRenderer.get_Value(i) == classValue)
                    ValFound = true;
                    break; //Exit the loop if the value was found.
            //If the value was not found, it's new and will be added.
            if (ValFound == false)
                pUniqueValueRenderer.AddValue(classValue, fieldnam, pClassSymbol as ISymbol);
                pUniqueValueRenderer.set_Label(classValue, classValue);
                pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol);
            pFeature = pFeatureCursor.NextFeature();
        //Since the number of unique values is known, the color ramp can be sized and the colors assigned.
        //algo perso

        ISymbol[] symbol = new ISymbol[pUniqueValueRenderer.ValueCount];
        pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount;
        bool bOK;
        pRandomColorRamp.CreateRamp(out bOK);

        IEnumColors pEnumColors = pRandomColorRamp.Colors;
        int[] tab=new int[pUniqueValueRenderer.ValueCount];

        for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++)

            xv =  pUniqueValueRenderer.get_Value(j);
            tab[j] = int.Parse(xv);

            if (xv != "")
                 pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleFillSymbol;

                 pSimpleFillColor.Color = pEnumColors.Next();
                pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol);


the problem: I want graduated colors to be classified according to the values ​​taken from the field (number of accidents) and to be ranked in ascending order thing that I can't do.

share|improve this question
So you are trying to do this with ArcObjects? Oh, I guess that tag says so. – jvangeld Mar 11 '11 at 19:17

I don't think you can use SimpleRendererClass because it is designed to use the same symbol for all features. You might want to take a look at ClassBreaksRendererClass.

SDK page for ClassBreaksRenderer

It also has "see also" links to other types of renderers that may be appropriate.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.