Ejemplo n.º 1
0
        /// <summary>
        /// 创建一个Random色带
        /// </summary>
        /// <returns></returns>
        public IColorRamp RandomColorRamp(int ImageLstIndex, int ClassCount)
        {
            //为渲染符号创建一个色带
            IRandomColorRamp pRandomColorRamp = new RandomColorRamp();

            if (ImageLstIndex >= 0 && ImageLstIndex <= 2)
            {
                pRandomColorRamp.StartHue      = m_intColorRampArray[ImageLstIndex, 0];
                pRandomColorRamp.EndHue        = m_intColorRampArray[ImageLstIndex, 1];
                pRandomColorRamp.MinValue      = m_intColorRampArray[ImageLstIndex, 2];
                pRandomColorRamp.MaxValue      = m_intColorRampArray[ImageLstIndex, 3];
                pRandomColorRamp.MinSaturation = m_intColorRampArray[ImageLstIndex, 4];
                pRandomColorRamp.MaxSaturation = m_intColorRampArray[ImageLstIndex, 5];
            }
            else
            {
                pRandomColorRamp.StartHue      = m_intColorRampArray[0, 0];
                pRandomColorRamp.EndHue        = m_intColorRampArray[0, 1];
                pRandomColorRamp.MinValue      = m_intColorRampArray[0, 2];
                pRandomColorRamp.MaxValue      = m_intColorRampArray[0, 3];
                pRandomColorRamp.MinSaturation = m_intColorRampArray[0, 4];
                pRandomColorRamp.MaxSaturation = m_intColorRampArray[0, 5];
            }

            pRandomColorRamp.UseSeed = true;
            pRandomColorRamp.Seed    = 43;

            bool blnout = true;

            pRandomColorRamp.CreateRamp(out blnout);
            return(pRandomColorRamp as IColorRamp);
        }
Ejemplo n.º 2
0
        public void UniqueValueMultiCondition(IGeoFeatureLayer geoLayer, string aFieldName, string Value)
        {
            IUniqueValueRenderer MyIUniqueValueRenderer;

            MyIUniqueValueRenderer            = new UniqueValueRenderer();
            MyIUniqueValueRenderer.FieldCount = 1;
            MyIUniqueValueRenderer.set_Field(0, aFieldName);
            int intFieldIndex;

            intFieldIndex = geoLayer.FeatureClass.FindField(aFieldName);
            IFeatureCursor MyIFeatureCursor;
            IQueryFilter   MyQueryFilter;

            MyQueryFilter = new QueryFilter();
            int ValuesCount = ListofUniqueValues.Count;

            for (int i = 0; i < ValuesCount; i++)
            {
                MyQueryFilter.WhereClause = ListofUniqueValues[i];
                MyIFeatureCursor          = geoLayer.FeatureClass.Search(MyQueryFilter, true);
                IRandomColorRamp MyIRandomColorRamp;
                MyIRandomColorRamp      = new RandomColorRamp();
                MyIRandomColorRamp.Size = 16;
                bool CheckColor;
                MyIRandomColorRamp.CreateRamp(out CheckColor);
                if (!CheckColor)
                {
                    return;
                }
                IEnumColors MyIEnumColors;
                MyIEnumColors = MyIRandomColorRamp.Colors;
                ISimpleMarkerSymbol MyISimpleMarkerSymbol;
                IColor   MyIColor;
                IFeature MyIFeature = MyIFeatureCursor.NextFeature();
                while (MyIFeature != null)
                {
                    MyISimpleMarkerSymbol = new SimpleMarkerSymbolClass();
                    MyIColor = MyIEnumColors.Next();
                    if ((MyIColor == null))
                    {
                        MyIEnumColors.Reset();
                        MyIColor = MyIEnumColors.Next();
                    }
                    MyISimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCross;
                    MyISimpleMarkerSymbol.Color = MyIColor;
                    MyISimpleMarkerSymbol.Size  = 22;
                    MyIUniqueValueRenderer.AddValue(MyIFeature.get_Value(intFieldIndex).ToString(), "", ((ISymbol)(MyISimpleMarkerSymbol)));
                    MyIFeature = MyIFeatureCursor.NextFeature();
                }
                geoLayer.Renderer = MyIUniqueValueRenderer as IFeatureRenderer;
                axMapControl1.ActiveView.Refresh();
            }
        }
Ejemplo n.º 3
0
        private IColorRamp UniqueValueRandomColorRamp(int NumOfValues, int seedCount)
        {
            //为渲染符号创建一个色带
            IRandomColorRamp pRandomColorRamp = new RandomColorRamp();

            pRandomColorRamp.UseSeed = true;
            pRandomColorRamp.Seed    = seedCount;
            pRandomColorRamp.Size    = NumOfValues;

            bool blnout = true;

            pRandomColorRamp.CreateRamp(out blnout);
            return(pRandomColorRamp as IColorRamp);
        }
Ejemplo n.º 4
0
        public static bool ChangeRenderToUVRenderer(IRasterLayer irasterLayer_0, string string_0)
        {
            bool        flag;
            bool        flag3;
            IRaster     raster = irasterLayer_0.Raster;
            IRasterBand band   = (raster as IRasterBandCollection).Item(0);

            band.HasTable(out flag);
            if (!flag)
            {
                return(false);
            }
            ITable           attributeTable = band.AttributeTable;
            int              pCount         = attributeTable.RowCount(null);
            IRandomColorRamp ramp           = new RandomColorRamp
            {
                Size = pCount,
                Seed = 100
            };

            ramp.CreateRamp(out flag3);
            IRasterUniqueValueRenderer renderer  = new RasterUniqueValueRenderer();
            IRasterRenderer            renderer2 = renderer as IRasterRenderer;

            renderer2.Raster = raster;
            renderer2.Update();
            renderer.HeadingCount = 1;
            renderer.set_Heading(0, "All Data Values");
            renderer.set_ClassCount(0, pCount);
            renderer.Field = string_0;
            int index = attributeTable.FindField(string_0);

            for (int i = 0; i < pCount; i++)
            {
                object obj2 = attributeTable.GetRow(i).get_Value(index);
                renderer.AddValue(0, i, obj2);
                renderer.set_Label(0, i, obj2.ToString());
                ISimpleFillSymbol symbol = new SimpleFillSymbol
                {
                    Color = ramp.get_Color(i)
                };
                renderer.set_Symbol(0, i, symbol as ISymbol);
            }
            renderer2.Update();
            irasterLayer_0.Renderer = renderer as IRasterRenderer;
            return(true);
        }
Ejemplo n.º 5
0
        private IEnumColors CreateAlgorithmicColorRamp()
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRamp();

            pRandomColorRamp.StartHue      = 0;
            pRandomColorRamp.EndHue        = 120;
            pRandomColorRamp.MinValue      = 0;
            pRandomColorRamp.MaxValue      = 90;
            pRandomColorRamp.MinSaturation = 0;
            pRandomColorRamp.MaxSaturation = 45;
            pRandomColorRamp.Size          = 20;
            pRandomColorRamp.UseSeed       = true;
            pRandomColorRamp.Seed          = 40;
            bool bture = true;

            pRandomColorRamp.CreateRamp(out bture);
            IEnumColors pEnuColors = pRandomColorRamp.Colors;

            return(pEnuColors);
        }
Ejemplo n.º 6
0
        private void UniqueValueRenderer(IFeatureLayer pFeatLyr, string[] sFieldName)
        {
            IUniqueValueRenderer pUniqueValueRender;

            IColor pNextUniqueColor;

            IEnumColors pEnumRamp;

            ITable pTable;

            IRow pNextRow;

            ICursor pCursor;

            IQueryFilter pQueryFilter;

            IRandomColorRamp pRandColorRamp = new RandomColorRamp();

            pRandColorRamp.StartHue = 0;

            pRandColorRamp.MinValue = 0;

            pRandColorRamp.MinSaturation = 15;

            pRandColorRamp.EndHue = 360;

            pRandColorRamp.MaxValue = 100;

            pRandColorRamp.MaxSaturation = 30;

            IQueryFilter pQueryFilter1 = new QueryFilter();

            pRandColorRamp.Size = pFeatLyr.FeatureClass.FeatureCount(pQueryFilter1);

            bool bSuccess = false;

            pRandColorRamp.CreateRamp(out bSuccess);
            if (sFieldName.Length == 1)
            {
                IFeatureLayer pFLayer = pFeatLyr as IFeatureLayer;

                IGeoFeatureLayer geoLayer = pFeatLyr as IGeoFeatureLayer;

                IFeatureClass fcls = pFLayer.FeatureClass;

                IQueryFilter pqf = new QueryFilter();

                IFeatureCursor fCursor = fcls.Search(pqf, false);

                IRandomColorRamp rx = new RandomColorRamp();

                rx.MinSaturation = 15;

                rx.MaxSaturation = 30;

                rx.MinValue = 85;

                rx.MaxValue = 100;

                rx.StartHue = 0;

                rx.EndHue = 360;

                rx.Size = 100;

                bool ok;
                ;

                rx.CreateRamp(out ok);

                IEnumColors RColors = rx.Colors;

                RColors.Reset();

                IUniqueValueRenderer pRender = new UniqueValueRenderer();

                pRender.FieldCount = 1;

                pRender.set_Field(0, sFieldName[0]);

                IFeature pFeat = fCursor.NextFeature();

                int index = pFeat.Fields.FindField(sFieldName[0]);

                while (pFeat != null)
                {
                    ISimpleFillSymbol symd = new SimpleFillSymbol();

                    symd.Style = esriSimpleFillStyle.esriSFSSolid;

                    symd.Outline.Width = 1;

                    symd.Color = RColors.Next();

                    string valuestr = pFeat.get_Value(index).ToString();

                    pRender.AddValue(valuestr, valuestr, symd as ISymbol);

                    pFeat = fCursor.NextFeature();
                }

                geoLayer.Renderer = pRender as IFeatureRenderer;
                _mxDocument.ActiveView.Refresh();
            }
            if (sFieldName.Length == 2)
            {
                string sFieldName1 = sFieldName[0];

                string sFieldName2 = sFieldName[1];

                IGeoFeatureLayer pGeoFeatureL = (IGeoFeatureLayer)pFeatLyr;

                pUniqueValueRender = new UniqueValueRenderer();

                pTable = (ITable)pGeoFeatureL;

                int pFieldNumber = pTable.FindField(sFieldName1);

                int pFieldNumber2 = pTable.FindField(sFieldName2);

                pUniqueValueRender.FieldCount = 2;

                pUniqueValueRender.set_Field(0, sFieldName1);

                pUniqueValueRender.set_Field(1, sFieldName2);

                pEnumRamp = pRandColorRamp.Colors;

                pNextUniqueColor = null;

                pQueryFilter = new QueryFilter();

                pQueryFilter.AddField(sFieldName1);

                pQueryFilter.AddField(sFieldName2);

                pCursor = pTable.Search(pQueryFilter, true);

                pNextRow = pCursor.NextRow();

                string codeValue;

                while (pNextRow != null)
                {
                    codeValue = pNextRow.get_Value(pFieldNumber).ToString() + pUniqueValueRender.FieldDelimiter +
                                pNextRow.get_Value(pFieldNumber2).ToString();

                    pNextUniqueColor = pEnumRamp.Next();

                    if (pNextUniqueColor == null)
                    {
                        pEnumRamp.Reset();

                        pNextUniqueColor = pEnumRamp.Next();
                    }

                    IFillSymbol pFillSymbol;

                    ILineSymbol pLineSymbol;

                    IMarkerSymbol pMarkerSymbol;

                    switch (pGeoFeatureL.FeatureClass.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPolygon:
                    {
                        pFillSymbol = new SimpleFillSymbol();

                        pFillSymbol.Color = pNextUniqueColor;

                        pUniqueValueRender.AddValue(codeValue, sFieldName1 + " " + sFieldName2,
                                                    (ISymbol)pFillSymbol);

                        break;
                    }

                    case esriGeometryType.esriGeometryPolyline:
                    {
                        pLineSymbol = new SimpleLineSymbol();

                        pLineSymbol.Color = pNextUniqueColor;

                        pUniqueValueRender.AddValue(codeValue, sFieldName1 + " " + sFieldName2,
                                                    (ISymbol)pLineSymbol);

                        break;
                    }

                    case esriGeometryType.esriGeometryPoint:
                    {
                        pMarkerSymbol = new SimpleMarkerSymbol();

                        pMarkerSymbol.Color = pNextUniqueColor;

                        pUniqueValueRender.AddValue(codeValue, sFieldName1 + " " + sFieldName2,
                                                    (ISymbol)pMarkerSymbol);

                        break;
                    }
                    }

                    pNextRow = pCursor.NextRow();
                }

                pGeoFeatureL.Renderer = (IFeatureRenderer)pUniqueValueRender;

                _mxDocument.ActiveView.Refresh();
            }

            else if (sFieldName.Length == 3)
            {
                string sFieldName1 = sFieldName[0];

                string sFieldName2 = sFieldName[1];

                string sFieldName3 = sFieldName[2];

                IGeoFeatureLayer pGeoFeatureL = (IGeoFeatureLayer)pFeatLyr;

                pUniqueValueRender = new UniqueValueRenderer();

                pTable = (ITable)pGeoFeatureL;

                int pFieldNumber = pTable.FindField(sFieldName1);

                int pFieldNumber2 = pTable.FindField(sFieldName2);

                int pFieldNumber3 = pTable.FindField(sFieldName3);

                pUniqueValueRender.FieldCount = 3;

                pUniqueValueRender.set_Field(0, sFieldName1);

                pUniqueValueRender.set_Field(1, sFieldName2);

                pUniqueValueRender.set_Field(2, sFieldName3);

                pEnumRamp = pRandColorRamp.Colors;

                pNextUniqueColor = null;

                pQueryFilter = new QueryFilter();

                pQueryFilter.AddField(sFieldName1);

                pQueryFilter.AddField(sFieldName2);

                pQueryFilter.AddField(sFieldName3);

                pCursor = pTable.Search(pQueryFilter, true);

                pNextRow = pCursor.NextRow();

                string codeValue;

                while (pNextRow != null)
                {
                    codeValue = pNextRow.get_Value(pFieldNumber).ToString() + pUniqueValueRender.FieldDelimiter +
                                pNextRow.get_Value(pFieldNumber2).ToString() + pUniqueValueRender.FieldDelimiter +
                                pNextRow.get_Value(pFieldNumber3).ToString();

                    pNextUniqueColor = pEnumRamp.Next();

                    if (pNextUniqueColor == null)
                    {
                        pEnumRamp.Reset();

                        pNextUniqueColor = pEnumRamp.Next();
                    }

                    IFillSymbol pFillSymbol;

                    ILineSymbol pLineSymbol;

                    IMarkerSymbol pMarkerSymbol;

                    switch (pGeoFeatureL.FeatureClass.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPolygon:
                    {
                        pFillSymbol = new SimpleFillSymbol();

                        pFillSymbol.Color = pNextUniqueColor;

                        pUniqueValueRender.AddValue(codeValue, sFieldName1 + " " + sFieldName2 + "" + sFieldName3,
                                                    (ISymbol)pFillSymbol);

                        break;
                    }

                    case esriGeometryType.esriGeometryPolyline:
                    {
                        pLineSymbol = new SimpleLineSymbol();

                        pLineSymbol.Color = pNextUniqueColor;

                        pUniqueValueRender.AddValue(codeValue, sFieldName1 + " " + sFieldName2 + "" + sFieldName3,
                                                    (ISymbol)pLineSymbol);

                        break;
                    }

                    case esriGeometryType.esriGeometryPoint:
                    {
                        pMarkerSymbol = new SimpleMarkerSymbol();

                        pMarkerSymbol.Color = pNextUniqueColor;

                        pUniqueValueRender.AddValue(codeValue, sFieldName1 + " " + sFieldName2 + "" + sFieldName3,
                                                    (ISymbol)pMarkerSymbol);

                        break;
                    }
                    }

                    pNextRow = pCursor.NextRow();
                }

                pGeoFeatureL.Renderer = (IFeatureRenderer)pUniqueValueRender;

                _mxDocument.ActiveView.Refresh();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mask"></param>
        /// <returns></returns>
        /// <remarks>https://gis.stackexchange.com/questions/58728/set-unique-values-to-different-groups-programmatically
        /// http://edndoc.esri.com/arcobjects/9.0/ComponentHelp/esriCarto/IUniqueValueRenderer_Example.htm
        /// </remarks>
        public static IUniqueValueRenderer GetRegularMaskRenderer(GCDCore.Project.Masks.RegularMask mask)
        {
            ISimpleFillSymbol symbol = new SimpleFillSymbol();

            symbol.Style         = esriSimpleFillStyle.esriSFSSolid;
            symbol.Outline.Width = 0.4;

            // Make the color ramp we will use for the symbols in the renderer
            IRandomColorRamp rx = new RandomColorRamp();

            rx.MinSaturation = 20;
            rx.MaxSaturation = 40;
            rx.MinValue      = 85;
            rx.MaxValue      = 100;
            rx.StartHue      = 76;
            rx.EndHue        = 188;
            rx.UseSeed       = true;
            rx.Seed          = 43;

            // These properties should be set prior to adding values
            IUniqueValueRenderer pRender = new UniqueValueRenderer();

            pRender.FieldCount       = 1;
            pRender.Field[0]         = mask._Field;
            pRender.DefaultSymbol    = (ISymbol)symbol;
            pRender.UseDefaultSymbol = false; // prevents "All other values" legend entry

            foreach (GCDCore.Project.Masks.MaskItem item in mask._Items.Where(x => x.Include))
            {
                ISimpleFillSymbol symx = new SimpleFillSymbol();
                symx.Style         = esriSimpleFillStyle.esriSFSSolid;
                symx.Outline.Width = 0.4;

                pRender.AddValue(item.FieldValue, string.Empty, (ISymbol)symx);
                pRender.Label[item.FieldValue]  = item.Label;
                pRender.Symbol[item.FieldValue] = (ISymbol)symx;
            }

            // now that we know how many unique values there are we can size the color ramp and assign the colors
            rx.Size = pRender.ValueCount;
            bool bOK;

            rx.CreateRamp(out bOK);
            IEnumColors RColors = rx.Colors;

            RColors.Reset();

            for (int i = 0; i < pRender.ValueCount; i++)
            {
                string            xv  = pRender.Value[i];
                ISimpleFillSymbol jsv = (ISimpleFillSymbol)pRender.Symbol[xv];
                jsv.Color          = RColors.Next();
                pRender.Symbol[xv] = (ISymbol)jsv;
            }

            // If you didn't use a color ramp that was predefined in a style, you need to use "Custom" here, otherwise
            // use the name of the color ramp you chose.
            pRender.ColorScheme = "Custom";
            pRender.set_FieldType(0, true);

            return(pRender);
        }
Ejemplo n.º 8
0
        public void ApplyUniqueValue(IGeoFeatureLayer geoLayer, string aFieldName)
        {
            //UniqueRender is engaged with feature data
            IUniqueValueRenderer uniqueRender = new UniqueValueRenderer();

            uniqueRender.FieldCount = 1;
            uniqueRender.set_Field(0, aFieldName);
            //Pointer
            int intFieldIndex = geoLayer.FeatureClass.FindField(aFieldName);
            //Create a ColorRamp with 16 colors
            IRandomColorRamp randomColors = new RandomColorRamp();

            randomColors.Size = 256;
            bool bOK;

            randomColors.CreateRamp(out bOK);
            if (!bOK)
            {
                return;
            }
            IEnumColors enumColor = randomColors.Colors;
            //May be used only to Polygon
            ISymbol pSym = null;
            //ISimpleFillSymbol sym;
            IColor color;
            //Query
            IFeatureCursor fCursor;
            IQueryFilter   qFilter = new QueryFilter();

            qFilter.SubFields = aFieldName;
            fCursor           = geoLayer.FeatureClass.Search(qFilter, true);
            IFeature feature = fCursor.NextFeature();

            while (feature != null)
            {
                color = enumColor.Next();
                if (color == null)
                {
                    enumColor.Reset();
                    color = enumColor.Next();
                }
                //code by jin, old is only used to Polygon Feature
                if (geoLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                    ISimpleFillSymbol sym = new SimpleFillSymbol();
                    sym.Style = esriSimpleFillStyle.esriSFSSolid;
                    sym.Color = color;
                    pSym      = sym as ISymbol;
                }
                else if (geoLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    ISimpleLineSymbol sym = new SimpleLineSymbol();
                    sym.Style = esriSimpleLineStyle.esriSLSSolid;
                    sym.Color = color;
                    pSym      = sym as ISymbol;
                }
                else
                {
                    ISimpleMarkerSymbol sym = new SimpleMarkerSymbol();
                    sym.Style = esriSimpleMarkerStyle.esriSMSCircle;
                    sym.Color = color;
                    pSym      = sym as ISymbol;
                }

                Console.WriteLine(feature.get_Value(intFieldIndex).ToString());
                //uniqueRender.AddValue(feature.get_Value(intFieldIndex).ToString(), "", ((ISymbol)(sym)));
                //the dynamic COM binder does not support the get_Range syntax exposed in C# before indexed properties were supported.
                //modified following by jin
                string codeValue = feature.get_Value(intFieldIndex).ToString();
                //将
                uniqueRender.AddValue(codeValue, "", pSym);
                feature = fCursor.NextFeature();
            }
            geoLayer.Renderer = uniqueRender as IFeatureRenderer;
            axMapControl1.ActiveView.Refresh();
            axTOCControl1.Update();
        }
Ejemplo n.º 9
0
        public void Render_Layers()
        {
            IMxDocument pMxDoc;

            pMxDoc = (IMxDocument)ArcMap.Application.Document;
            IMap pMap;

            pMap = pMxDoc.FocusMap;
            string strChoice = null;

            //** Giving the user a choice of 3 predefined maps
            strChoice = Interaction.InputBox("1 - U.S. States, " + Environment.NewLine + "2 - Major Cities, " + Environment.NewLine + "3 - State Polygon Area Rank", "Please choose a map.");
            if (string.IsNullOrEmpty(strChoice))
            {
                return;
            }
            IWorkspaceFactory pWFactory;

            pWFactory = new ShapefileWorkspaceFactory();
            IWorkspace pWorkspace;

            pWorkspace = pWFactory.OpenFromFile("C:\\GEOG489\\Lesson1-2", 0);
            IFeatureWorkspace pFeatureWorkspace;

            pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
            IFeatureLayer pFLayer;

            pFLayer = new FeatureLayer();
            IGeoFeatureLayer pGeoFLayer;

            pGeoFLayer = (IGeoFeatureLayer)pFLayer;
            IFeatureClass pFClass;

            ITable                   pTable;
            IClassify                pClasses;
            ITableHistogram          pTableHist;
            IHistogram               pHist;
            IClassBreaksRenderer     pCBR;
            IClassBreaksUIProperties pUIProperties;
            ILegendInfo              pLegendInfo;

            object Frequencies = null;
            object Values      = null;


            if (strChoice == "1")
            {
                //** User gets a Unique Value rendering of U.S. States by sub-region
                pFClass = pFeatureWorkspace.OpenFeatureClass("us_boundaries.shp");

                pFLayer.FeatureClass = pFClass;
                pFLayer.Name         = "U.S. States";
                pMap.AddLayer(pFLayer);

                IUniqueValueRenderer pUVRender;
                pUVRender = new UniqueValueRenderer();

                //** Setting default symbol for features that don't have a value in
                //** the classification field
                ISimpleFillSymbol pSymDefault;
                pSymDefault               = new SimpleFillSymbol();
                pSymDefault.Style         = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSSolid;
                pSymDefault.Outline.Width = 0.4;

                //** These properties should be set prior to adding values
                pUVRender.FieldCount = 1;
                //** Can classify based on up to 3 fields
                pUVRender.Field[0] = "NAME";
                //** Name of the 1st (only) field
                pUVRender.DefaultSymbol    = (ISymbol)pSymDefault;
                pUVRender.UseDefaultSymbol = true;
                IQueryFilter pQFilter;
                pQFilter = new QueryFilter();
                //** empty QueryFilter same as selecting all recs
                IFeatureCursor pFCursor;
                pFCursor = pFClass.Search(pQFilter, false);
                //** getting all features

                //** Make the color ramp we will use for the symbols in the renderer.
                //** Colors should be random for Unique Value, as opposed to light-to-dark.
                //** Make settings for hue, saturation, value, and seed to have random
                //** colors generated within certain limits.
                IRandomColorRamp pRamp;
                pRamp = new RandomColorRamp();
                pRamp.MinSaturation = 25;
                pRamp.MaxSaturation = 45;
                pRamp.MinValue      = 85;
                pRamp.MaxValue      = 100;
                pRamp.StartHue      = 205;
                pRamp.EndHue        = 320;
                pRamp.UseSeed       = true;
                pRamp.Seed          = 25;

                IFeature pFeature;
                int      n = 0;
                int      i = 0;

                n = pFClass.FeatureCount(pQFilter);
                //** Getting total count of state features

                //** Loop through the features
                while (i != n)
                {
                    ISimpleFillSymbol pSymX;
                    pSymX = new SimpleFillSymbol();

                    //** Move to the next feature and assign the value in the Sub_region field to a var
                    pFeature = pFCursor.NextFeature();
                    string strVal = null;
                    strVal = pFeature.Value[2].ToString();
                    //** NAME Field is at this index in fields collection

                    //** Test to see if we've already added this value
                    //** to the renderer, if not, then add it.
                    bool blnAdded = false;
                    blnAdded = false;

                    int x = 0;
                    //** First time through, ValueCount = 0
                    for (x = 0; x <= (pUVRender.ValueCount - 1); x++)
                    {
                        if (pUVRender.Value[x] == strVal)
                        {
                            blnAdded = true;
                            break;
                        }
                    }

                    //** Value not yet encountered, must add it
                    if (blnAdded == false)
                    {
                        pUVRender.AddValue(strVal, "Predominant Term", (ISymbol)pSymDefault);
                        pUVRender.Label[strVal]  = strVal;
                        pUVRender.Symbol[strVal] = (ISymbol)pSymX;
                        //** All values get same symbol at first,
                        //** colors assigned later
                    }
                    i = i + 1;
                }

                //** Can size the color ramp and assign the colors, now that the
                //** number of unique values is known.

                pRamp.Size = pUVRender.ValueCount;
                bool blnRamp;
                pRamp.CreateRamp(out blnRamp);

                //** Create an enum of colors from the color ramp and initialize it
                IEnumColors pColors;
                pColors = pRamp.Colors;
                pColors.Reset();

                int y = 0;

                //** Loop through each unique value, setting its symbol's color
                for (y = 0; y <= (pUVRender.ValueCount - 1); y++)
                {
                    string strRendVal = null;
                    strRendVal = pUVRender.Value[y];
                    if (!string.IsNullOrEmpty(strRendVal))
                    {
                        ISimpleFillSymbol pSym;
                        pSym       = (ISimpleFillSymbol)pUVRender.Symbol[strRendVal];
                        pSym.Color = pColors.Next();
                        pUVRender.Symbol[strRendVal] = (ISymbol)pSym;
                    }
                }

                //** If you didn't use a color ramp that was predefined
                //** in a style, use "Custom" here, otherwise
                //** use the name of the color ramp you chose.
                pUVRender.ColorScheme  = "Custom";
                pUVRender.FieldType[0] = true;
                //** Set to True since Sub_region is a string

                pGeoFLayer.Renderer = (IFeatureRenderer)pUVRender;

                //** Make sure the symbology tab shows the correct info.
                IRendererPropertyPage pRendPropPage;
                pRendPropPage = (IRendererPropertyPage) new UniqueValuePropertyPage();
                pGeoFLayer.RendererPropertyPageClassID = pRendPropPage.ClassID;
            }
            else if (strChoice == "2")
            {
                //** User gets a graduated symbol map of U.S. Cities
                pFClass = pFeatureWorkspace.OpenFeatureClass("us_cities.shp");

                pFLayer.FeatureClass = pFClass;
                pFLayer.Name         = "Major U.S. Cities";
                pGeoFLayer           = (IGeoFeatureLayer)pFLayer;
                pMap.AddLayer(pFLayer);
                //** Switching to the ITable interface; FeatureClass is a type of Table
                pTable = (ITable)pFClass;

                //** Creating a new quantile classification
                pClasses = (IClassify) new Quantile();

                //** Must create a TableHistogram to generate classes
                //** Need both ITableHistogram and IHistogram interfaces
                pTableHist = (ITableHistogram) new TableHistogram();

                pHist = (IHistogram)pTableHist;


                //** Set the table and field for the histogram, then use GetHistogram to
                //** get arrays of values and corresponding frequencies
                pTableHist.Field = "POPCLASS";
                pTableHist.Table = pTable;
                pHist.GetHistogram(out Values, out Frequencies);

                //** Assign the arrays of values and frequencies to the quantile classification
                //** then break the data into 5 classes
                pClasses.SetHistogramData(Values, Frequencies);
                pClasses.Classify(4);

                double[] classBreaks = new double[4];
                classBreaks = (double[])pClasses.ClassBreaks;

                //** Ready to render the data
                pCBR = new ClassBreaksRenderer();

                pCBR.BreakCount = 4;

                pCBR.Field        = "POPCLASS";
                pCBR.MinimumBreak = classBreaks[0];
                //** ClassBreak(0) is min value of 1st class

                int j = 0;

                //** Loop thru each class, setting the renderers breaks
                //** The renderer's breaks are 0-based, quantile's breaks are 1-based
                for (j = 0; j <= (pCBR.BreakCount - 1); j++)
                {
                    pCBR.Break[j] = classBreaks[j + 1];
                    pCBR.Label[j] = classBreaks[j] + " - " + classBreaks[j + 1];
                }
                //** Ready for symbols
                ISimpleMarkerSymbol pCitySym;

                //** Setting the smallest symbol size
                double dblFromSize = 0;
                dblFromSize = 4;

                //** Setting the largest symbol size
                double dblToSize = 0;
                dblToSize = 16;

                //** Calculating the change in size between classes based on the min size,
                //** max size, and # of classes
                double dblStep = 0;
                dblStep = (dblToSize - dblFromSize) / (pCBR.BreakCount - 1);

                //** Setting the foreground color of the symbols
                IRgbColor pColor;
                pColor = new RgbColor();

                pColor.Red   = 179;
                pColor.Green = 235;
                pColor.Blue  = 255;

                //** Setting the outline color of the symbols
                //** No color settings means black outline (r=0, g=0, b=0)
                IRgbColor pOlColor;
                pOlColor = new RgbColor();

                int k = 0;

                //** Setting symbol for each class
                for (k = 0; k <= pCBR.BreakCount - 1; k++)
                {
                    pCitySym              = new SimpleMarkerSymbol();
                    pCitySym.Color        = pColor;
                    pCitySym.Outline      = true;
                    pCitySym.OutlineColor = pOlColor;
                    pCitySym.OutlineSize  = 1;
                    pCitySym.Size         = dblFromSize + (dblStep * Convert.ToDouble(k));
                    pCBR.Symbol[k]        = (ISymbol)pCitySym;
                }
                //** Assigning the ClassBreaksRenderer to the layer
                pGeoFLayer.Renderer       = (IFeatureRenderer)pCBR;
                pUIProperties             = (IClassBreaksUIProperties)pCBR;
                pUIProperties.LowBreak[0] = pCBR.MinimumBreak;

                int m = 0;
                for (m = 1; m <= pCBR.BreakCount - 1; m++)
                {
                    pUIProperties.LowBreak[m] = classBreaks[m];
                }
                //** Creating a heading for the legend in the Table of Contents
                pLegendInfo = (ILegendInfo)pCBR;
                //qi
                pLegendInfo.LegendGroup[0].Heading = "Population Class";
                pLegendInfo.SymbolsAreGraduated    = false;
            }
            else if (strChoice == "3")
            {
                //** User gets a graduated color map of state population normalized by area
                pFClass = pFeatureWorkspace.OpenFeatureClass("us_boundaries.shp");

                pFLayer.FeatureClass = pFClass;
                pFLayer.Name         = "State Polygon Area Rank";
                pGeoFLayer           = (IGeoFeatureLayer)pFLayer;
                pMap.AddLayer(pFLayer);
                //** Very similar to previous example

                pTable   = (ITable)pFClass;
                pClasses = (IClassify) new Quantile();

                pTableHist = (ITableHistogram) new TableHistogram();
                pHist      = (IHistogram)pTableHist;

                pTableHist.Field = "Shape_Area";
                pTableHist.Table = pTable;
                //pTableHist.NormField = "Rank" '** Setting the normalization field before getting histogram
                pHist.GetHistogram(out Values, out Frequencies);

                pClasses.SetHistogramData(Values, Frequencies);
                pClasses.Classify(5);

                double[] classBreaks = new double[4];
                classBreaks = (double[])pClasses.ClassBreaks;

                pCBR = new ClassBreaksRenderer();

                //** Making normalization settings for the renderer
                //Dim pNorm As IDataNormalization
                //pNorm = pCBR
                //pNorm.NormalizationField = "Rank"
                //pNorm.NormalizationType = esriDataNormalization.esriNormalizeByField

                pCBR.BreakCount   = 5;
                pCBR.Field        = "Shape_Area";
                pCBR.MinimumBreak = classBreaks[0];

                int t = 0;

                pUIProperties             = (IClassBreaksUIProperties)pCBR;
                pUIProperties.LowBreak[0] = pCBR.MinimumBreak;

                for (t = 0; t <= Information.UBound(classBreaks) - 1; t++)
                {
                    pCBR.Break[t] = classBreaks[t + 1];

                    //** Want to round the class break values in the class labels
                    //** Use the NumericFormat class to set up a 1-decimal format
                    INumericFormat pNumericFormat;
                    pNumericFormat = (INumericFormat) new NumericFormat();
                    pNumericFormat.RoundingOption = ESRI.ArcGIS.esriSystem.esriRoundingOptionEnum.esriRoundNumberOfDecimals;
                    pNumericFormat.RoundingValue  = 1;

                    INumberFormat pNumberFormat;
                    pNumberFormat = (INumberFormat)pNumericFormat;

                    string strRndVal1 = null;
                    string strRndVal2 = null;

                    //** Using ValueToString method to convert the numbers into the desired format
                    strRndVal1 = pNumberFormat.ValueToString(classBreaks[t]);
                    strRndVal2 = pNumberFormat.ValueToString(classBreaks[t + 1]);

                    pCBR.Label[t] = strRndVal1 + " - " + strRndVal2;
                }

                pGeoFLayer.Renderer = (IFeatureRenderer)pCBR;

                for (t = 1; t <= 4; t++)
                {
                    pUIProperties.LowBreak[t] = classBreaks[t];
                }
                //** Ready to set colors
                //** Want to use AlgorithmicColorRamp to ramp from one color to another
                IEnumColors           pColorEnum;
                IAlgorithmicColorRamp pAColorRamp;
                IRgbColor             pFromColor;
                IRgbColor             pToColor;

                //** Setting up the algorithmic color ramp
                pFromColor     = new RgbColor();
                pFromColor.RGB = Information.RGB(242, 233, 250);
                // lavender
                pToColor     = new RgbColor();
                pToColor.RGB = Information.RGB(56, 45, 121);
                // deep purple
                pAColorRamp = new AlgorithmicColorRamp();

                pAColorRamp.Algorithm = ESRI.ArcGIS.Display.esriColorRampAlgorithm.esriHSVAlgorithm;
                pAColorRamp.Size      = 5;
                //** # of classes
                pAColorRamp.FromColor = pFromColor;
                pAColorRamp.ToColor   = pToColor;
                bool blnRamp;
                pAColorRamp.CreateRamp(out blnRamp);
                pColorEnum = pAColorRamp.Colors;
                pColorEnum.Reset();

                int s = 0;

                //** Loop thru the classes, creating a new symbol, assigning the next color
                //** created by the ramp, and assigning the symbol to the renderer.
                for (s = 0; s <= 4; s++)
                {
                    ISimpleFillSymbol pSFSym;
                    pSFSym         = new SimpleFillSymbol();
                    pSFSym.Color   = pColorEnum.Next();
                    pCBR.Symbol[s] = (ISymbol)pSFSym;
                }

                //** Creating a heading for the legend in the Table of Contents
                pLegendInfo = (ILegendInfo)pCBR;
                //qi
                pLegendInfo.LegendGroup[0].Heading = "Area (Degrees)";
                pLegendInfo.SymbolsAreGraduated    = false;
            }
            //** Refreshing the Table of Contents
            pMxDoc.ActiveView.ContentsChanged();
            pMxDoc.UpdateContents();

            //** Re-drawing the map
            pMxDoc.ActiveView.Refresh();
        }