3

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;
 pEnumColors.Reset();
 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);
 MessageBox.Show(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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 11, 2011 at 17:24
1
  • So you are trying to do this with ArcObjects? Oh, I guess that tag says so. Commented Mar 11, 2011 at 19:17

1 Answer 1

3

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.

answered Mar 11, 2011 at 20:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.