private static IRandomColorRamp GetColorRamp(int size)
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();

            pRandomColorRamp.StartHue      = 10;
            pRandomColorRamp.EndHue        = 300;
            pRandomColorRamp.MaxSaturation = 100;
            pRandomColorRamp.MinSaturation = 0;
            pRandomColorRamp.MaxValue      = 100;
            pRandomColorRamp.MinValue      = 0;
            pRandomColorRamp.Size          = size;
            bool ok = true;

            pRandomColorRamp.CreateRamp(out ok);
            return(pRandomColorRamp);
        }
        private IColorRamp GetColorRamp(int colorSize)
        {
            IRandomColorRamp pColorRamp = new RandomColorRampClass();

            pColorRamp.StartHue      = 0;   //0
            pColorRamp.EndHue        = 360; //360
            pColorRamp.MinSaturation = 15;  //15
            pColorRamp.MaxSaturation = 30;  //30
            pColorRamp.MinValue      = 99;  //99
            pColorRamp.MaxValue      = 100; //100
            pColorRamp.Size          = colorSize;
            bool ok = true;

            pColorRamp.CreateRamp(out ok);
            return(pColorRamp as IColorRamp);
        }
Example #3
0
        /// <summary>
        /// 构建色带
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        private static IRandomColorRamp GetColorRamp(int size)
        {
            var randomColorRamp = new RandomColorRampClass
            {
                StartHue      = 10,
                EndHue        = 300,
                MaxSaturation = 100,
                MinSaturation = 0,
                MaxValue      = 100,
                MinValue      = 0,
                Size          = size
            };

            randomColorRamp.CreateRamp(out _);
            return(randomColorRamp);
        }
Example #4
0
        private IColorRamp CreateRandomColorRamp()
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();

            // 制作一系列介于橘黄色和蓝绿色之间的随机颜色
            pRandomColorRamp.StartHue      = 40;
            pRandomColorRamp.EndHue        = 120;
            pRandomColorRamp.MinValue      = 65;
            pRandomColorRamp.MaxValue      = 90;
            pRandomColorRamp.MinSaturation = 25;
            pRandomColorRamp.MaxSaturation = 45;
            pRandomColorRamp.Size          = 20;
            pRandomColorRamp.Seed          = 23;
            bool bture = true;

            pRandomColorRamp.CreateRamp(out bture);
            return(pRandomColorRamp);
        }
Example #5
0
        public static void uniqueRender(IFeatureLayer featLayer, string fieldName)
        {
            IGeoFeatureLayer     pGeoFeatureLayer     = featLayer as IGeoFeatureLayer;
            IFeatureClass        pFeatureClass        = featLayer.FeatureClass;         //获取图层上的featureClass
            IFeatureCursor       pFeatureCursor       = pFeatureClass.Search(null, false);
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器

            //设置渲染字段对象
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, fieldName);

            ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass();   //创建填充符号

            pUniqueValueRenderer.DefaultSymbol    = (ISymbol)pSimFillSymbol;
            pUniqueValueRenderer.UseDefaultSymbol = false;
            int n = pFeatureClass.FeatureCount(null);

            for (int i = 0; i < n; i++)
            {
                IFeature pFeature      = pFeatureCursor.NextFeature();
                string   pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString();
                pUniqueValueRenderer.AddValue(pFeatureValue, "", null);
            }
            IRandomColorRamp colorRamp = new RandomColorRampClass();

            colorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool b = true;

            colorRamp.CreateRamp(out b);
            //为每个符号设置颜色

            for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
            {
                string xv = pUniqueValueRenderer.get_Value(i);

                if (xv != "")
                {
                    pUniqueValueRenderer.set_Symbol(xv, getISymbolByGeomType(featLayer,
                                                                             colorRamp.get_Color(i * (colorRamp.Size - 1) / (pUniqueValueRenderer.ValueCount - 1))));
                }
            }
            pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
        }
Example #6
0
        /// <summary>
        /// 创建随机的颜色条带
        /// </summary>
        /// <param name="Number"></param>
        /// <returns></returns>
        private IColorRamp CreateRandomColorRamp(int Number)
        {
            //请注意色度、饱和度、最大值、最小值、随机种子数等参数的设定
            //参数不同, 所产生的色带也不同
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();

            pRandomColorRamp.StartHue      = 0; //开始色度
            pRandomColorRamp.EndHue        = 360;
            pRandomColorRamp.MinValue      = 99;
            pRandomColorRamp.MaxValue      = 100;
            pRandomColorRamp.MinSaturation = 15;     //最小饱和度
            pRandomColorRamp.MaxSaturation = 30;     //最大饱和度
            pRandomColorRamp.Size          = Number; //设置颜色带数量
            pRandomColorRamp.Seed          = 23;     //随机数种子
            bool bture = true;

            pRandomColorRamp.CreateRamp(out bture);
            return(pRandomColorRamp);
        }
        private IEnumColors GetEnumColorsByRandomColorRamp(int colorSize)
        {
            IRandomColorRamp pColorRamp = new RandomColorRampClass();

            pColorRamp.StartHue      = 0;   //0
            pColorRamp.EndHue        = 360; //360
            pColorRamp.MinSaturation = 15;  //15
            pColorRamp.MaxSaturation = 30;  //30
            pColorRamp.MinValue      = 99;  //99
            pColorRamp.MaxValue      = 100; //100
            pColorRamp.Size          = colorSize;
            bool ok = true;

            pColorRamp.CreateRamp(out ok);
            IEnumColors pEnumRamp = pColorRamp.Colors;

            pEnumRamp.Reset();
            return(pEnumRamp);
        }
Example #8
0
        private IEnumColors CreateRdmColorRamp(int startHue, int endHue, int minValue, int maxValue, int minSaturation,
                                               int maxSaturation, int size, int seed)
        {
            IRandomColorRamp pRdmcolor = new RandomColorRampClass();

            pRdmcolor.StartHue      = startHue;
            pRdmcolor.EndHue        = endHue;
            pRdmcolor.MinValue      = minValue;
            pRdmcolor.MaxValue      = maxValue;
            pRdmcolor.MinSaturation = minSaturation;
            pRdmcolor.MaxSaturation = maxSaturation;
            pRdmcolor.Size          = size;
            pRdmcolor.Seed          = seed;
            bool b;

            pRdmcolor.CreateRamp(out b);

            return(pRdmcolor.Colors);
        }
Example #9
0
        public static void uniqueRender(IRasterLayer rasterLayer)
        {
            if (rasterLayer == null)
            {
                return;
            }
            IRaster raster = rasterLayer.Raster;
            IRasterUniqueValueRenderer render       = new RasterUniqueValueRendererClass();
            IRasterRenderer            rasterRender = render as IRasterRenderer;

            rasterRender.Raster = raster;
            rasterRender.Update();
            IUniqueValues           uniqueValues     = new UniqueValuesClass();
            IRasterCalcUniqueValues calcUniqueValues = new RasterCalcUniqueValuesClass();

            calcUniqueValues.AddFromRaster(raster, 0, uniqueValues);
            IRasterRendererUniqueValues renderUniqueValues = render as IRasterRendererUniqueValues;

            renderUniqueValues.UniqueValues = uniqueValues;
            render.Field        = "Value";
            render.HeadingCount = 1;
            render.set_Heading(0, "淹没水深");
            render.set_ClassCount(0, uniqueValues.Count);

            IRandomColorRamp ramp = new RandomColorRampClass();

            ramp.Size = uniqueValues.Count;
            bool b = true;

            ramp.CreateRamp(out b);

            for (int i = 0; i < uniqueValues.Count; i++)
            {
                render.AddValue(0, i, uniqueValues.get_UniqueValue(i));
                render.set_Label(0, i, uniqueValues.get_UniqueValue(i).ToString());
                ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
                fillSymbol.Color = ramp.get_Color(i);
                render.set_Symbol(0, i, fillSymbol as ISymbol);
            }
            rasterRender.Update();
            rasterLayer.Renderer = rasterRender;
        }
Example #10
0
        private IColor method_3(int int_0)
        {
            bool             flag;
            IRandomColorRamp ramp = new RandomColorRampClass
            {
                StartHue      = 40,
                EndHue        = 120,
                MinValue      = 65,
                MaxValue      = 90,
                MinSaturation = 25,
                MaxSaturation = 45,
                Size          = 5,
                Seed          = int_0
            };

            ramp.CreateRamp(out flag);
            IEnumColors colors = ramp.Colors;

            colors.Reset();
            return(colors.Next());
        }
Example #11
0
        private void mnuUniqueValue_Click(object sender, EventArgs e)
        {
            ILayer pLayer = MainMap.get_Layer(0);
            ITable pTable = pLayer as ITable;

            IUniqueValueRenderer pUniqueValueRender = new UniqueValueRendererClass();

            pUniqueValueRender.FieldCount = 1;
            pUniqueValueRender.set_Field(0, "ADCODE99");

            int fldIndex = pTable.Fields.FindField("ADCODE99");

            // 产生一个随机的色带
            IRandomColorRamp pColorRamp = new RandomColorRampClass();

            pColorRamp.StartHue      = 0;
            pColorRamp.MinValue      = 99;
            pColorRamp.MinSaturation = 15;
            pColorRamp.EndHue        = 360;
            pColorRamp.MaxValue      = 100;
            pColorRamp.MinSaturation = 30;

            // 任意产生50种颜色
            pColorRamp.Size = 50;

            bool bOK;

            pColorRamp.CreateRamp(out bOK);

            IEnumColors pEnumRamp        = pColorRamp.Colors;
            IColor      pNextUniqueColor = null;

            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.AddField("ADCODE99");

            ICursor pCursor = pTable.Search(pQueryFilter, true);
            IRow    pRow    = pCursor.NextRow();

            while (pRow != null)
            {
                IRowBuffer    pRowBuffer = pRow as IRowBuffer;
                System.Object cValue     = pRowBuffer.get_Value(fldIndex);

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


                ISimpleFillSymbol pSym = new SimpleFillSymbolClass();
                pSym.Color = pNextUniqueColor;

                pUniqueValueRender.AddValue(cValue.ToString(), "", pSym as ISymbol);
                pRow = pCursor.NextRow();
            }

            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;

            pGeoFeatureLayer.Renderer = pUniqueValueRender as IFeatureRenderer;
            MainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
 private IEnumColors GetEnumColorsByRandomColorRamp(int colorSize)
 {
     IRandomColorRamp pColorRamp = new RandomColorRampClass();
     pColorRamp.StartHue = 0;  //0
     pColorRamp.EndHue = 360;     //360
     pColorRamp.MinSaturation = 15;  //15
     pColorRamp.MaxSaturation = 30;   //30
     pColorRamp.MinValue = 99;    //99
     pColorRamp.MaxValue = 100;     //100
     pColorRamp.Size = colorSize;
     bool ok = true;
     pColorRamp.CreateRamp(out ok);
     IEnumColors pEnumRamp = pColorRamp.Colors;
     pEnumRamp.Reset();
     return pEnumRamp;
 }
Example #13
0
 //进行唯一值渲染
 private void UniqueValueRenderer(IFeatureLayer featureLayer, string FieldName)
 {
     int FieldIndex = featureLayer.FeatureClass.Fields.FindField(FieldName);
     IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass();
     uniqueValueRenderer.FieldCount = 1;
     uniqueValueRenderer.set_Field(0, FieldName);
     IRandomColorRamp randomColorRamp = new RandomColorRampClass();
     randomColorRamp.StartHue = 0;
     randomColorRamp.MinValue = 0;
     randomColorRamp.MinSaturation = 15;
     randomColorRamp.EndHue = 360;
     randomColorRamp.MaxValue = 100;
     randomColorRamp.MaxSaturation = 30;
     IQueryFilter queryFilter = new QueryFilterClass();
     randomColorRamp.Size = featureLayer.FeatureClass.FeatureCount(queryFilter);
     bool flag = false;
     randomColorRamp.CreateRamp(out flag);
     IEnumColors enumColors = randomColorRamp.Colors;
     IColor color = null;
     object codeValue = null;
     queryFilter = new QueryFilterClass();
     queryFilter.AddField(FieldName);
     IFeatureCursor featureCursor= featureLayer.FeatureClass.Search(queryFilter, true);
     IFeature feature = featureCursor.NextFeature();
     while (feature != null)
     {
         codeValue = feature.get_Value(FieldIndex);
         color = enumColors.Next();
         if (color == null)
         {
             enumColors.Reset();
             color = enumColors.Next();
         }
         ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
         simpleLineSymbol.Color = color;
         uniqueValueRenderer.AddValue(codeValue.ToString(), "", simpleLineSymbol as ISymbol);
         feature = featureCursor.NextFeature();
     }
     IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
     geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer;
     System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
     axMapControl1.Refresh();
     axMapControl1.Update();
 }
Example #14
0
        private void polygonUniqueDye(ILayer pLayer)
        {
            IGeoFeatureLayer     m_pGeoFeatureL;
            IUniqueValueRenderer pUniqueValueR;
            IFillSymbol          pFillSymbol;
            IColor           pNextUniqueColor;
            IEnumColors      pEnumRamp;
            ITable           pTable;
            int              iFieldNumber;
            IRow             pNextRow;
            IRowBuffer       pNextRowBuffer;
            ICursor          pCursor;
            IQueryFilter     pQueryFilter;
            string           codeValue;
            IRandomColorRamp pColorRamp;


            string strNameField = cbField1.Text;

            IMap pMap = axMapControl1.Map;

            pMap.ReferenceScale = 0;
            m_pGeoFeatureL      = pLayer as IGeoFeatureLayer;
            pUniqueValueR       = new UniqueValueRendererClass();
            pTable = (ITable)m_pGeoFeatureL;

            iFieldNumber = pTable.FindField(strNameField);
            if (iFieldNumber == -1)
            {
                MessageBox.Show("未能找到字段" + strNameField);
                return;
            }
            //只用一个字段进行单值着色
            pUniqueValueR.FieldCount = 1;
            //用于区分着色的字段
            pUniqueValueR.set_Field(0, strNameField);
            //产生一个随机的颜色条,用的是HSV颜色模式
            pColorRamp               = new RandomColorRampClass();
            pColorRamp.StartHue      = 0;
            pColorRamp.MinValue      = 99;
            pColorRamp.MinSaturation = 15;
            pColorRamp.EndHue        = 360;
            pColorRamp.MaxValue      = 100;
            pColorRamp.MaxSaturation = 30;
            //任意产生100歌颜色,如果知道要素的数据可以产生精确的颜色数目
            pColorRamp.Size = 100;
            bool ok = true;

            pColorRamp.CreateRamp(out ok);
            pEnumRamp        = pColorRamp.Colors;
            pNextUniqueColor = null;
            //产生查询过滤器的对象
            pQueryFilter = new QueryFilterClass();
            pQueryFilter.AddField(strNameField);
            //根据某个字段在表中找出指向所有行的游标对象
            pCursor  = pTable.Search(pQueryFilter, true);
            pNextRow = pCursor.NextRow();
            //遍历所有的要素
            while (pNextRow != null)
            {
                pNextRowBuffer = pNextRow;
                //找出row为某个定值的值
                codeValue = pNextRowBuffer.get_Value(iFieldNumber).ToString();
                //获取随机颜色带中的任意一个颜色
                pNextUniqueColor = pEnumRamp.Next();
                if (pNextUniqueColor == null)
                {
                    pEnumRamp.Reset();

                    pNextUniqueColor = pEnumRamp.Next();
                }
                pFillSymbol       = new SimpleFillSymbolClass();
                pFillSymbol.Color = pNextUniqueColor;
                //将每次得到的要素字段值和修饰它的符号值放入着色对象中
                pUniqueValueR.AddValue(codeValue, strNameField, (ISymbol)pFillSymbol);
                pNextRow = pCursor.NextRow();
            }
            m_pGeoFeatureL.Renderer = (IFeatureRenderer)pUniqueValueR;
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Example #15
0
        // 唯一值符号化
        public static void UniqueValueRenderer(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            ITable pTable = featureLayer as ITable;
            IUniqueValueRenderer pRenderer = new UniqueValueRendererClass();

            pRenderer.FieldCount = 1;          // 设置唯一值符号化的关键字段为一个
            pRenderer.set_Field(0, fieldName); // 设置唯一值符号化的第一个关键字段
            IRandomColorRamp pColorRamp = new RandomColorRampClass()
            {
                StartHue      = 0,
                MinValue      = 0,
                MinSaturation = 0,
                EndHue        = 100,
                MaxValue      = 100,
                MaxSaturation = 100
            };

            // 根据渲染字段的值的个数,设置一组随机颜色
            pColorRamp.Size = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass());
            bool bSuccess = false;

            pColorRamp.CreateRamp(out bSuccess);
            IEnumColors pEnumColors      = pColorRamp.Colors;
            IColor      pNextUniqueColor = null;
            // 查询字段的值
            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.AddField(fieldName);
            int        fieldNumber    = pTable.FindField(fieldName); // 获取渲染字段索引
            ICursor    pCursor        = pTable.Search(pQueryFilter, true);
            IRow       pNextRow       = pCursor.NextRow();
            object     codeValue      = null;
            IRowBuffer pNextRowBuffer = null;

            while (pNextRow != null)
            {
                pNextRowBuffer = pNextRow as IRowBuffer;
                // 获取渲染字段的每一个值
                codeValue        = pNextRowBuffer.get_Value(fieldNumber);
                pNextUniqueColor = pEnumColors.Next();
                if (pNextUniqueColor == null)
                {
                    pEnumColors.Reset();
                    pNextUniqueColor = pEnumColors.Next();
                }
                ISymbol pSymbol = null;
                switch (featureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    pSymbol = new SimpleFillSymbolClass()
                    {
                        Color = pNextUniqueColor
                    };
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    pSymbol = new SimpleLineSymbolClass()
                    {
                        Color = pNextUniqueColor
                    };
                    break;

                case esriGeometryType.esriGeometryPoint:
                    pSymbol = new SimpleMarkerSymbolClass()
                    {
                        Color = pNextUniqueColor
                    };
                    break;
                }
                pRenderer.AddValue(codeValue.ToString(), "", pSymbol);
                pNextRow = pCursor.NextRow();
            }
            (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
            mapControl.Refresh();
            tocControl.Update();
        }
Example #16
0
        /// <summary>
        /// 唯一值渲染
        /// </summary>
        /// <param name="activeView"></param>
        /// <param name="pFtLayer"></param>
        /// <param name="pCount"></param>
        /// <param name="pFieldName"></param>
        public static void  UniqueValueRender(IActiveView activeView, IFeatureLayer pFtLayer, int pCount, string pFieldName)

        {
            IGeoFeatureLayer     pGeoFeaturelayer = pFtLayer as IGeoFeatureLayer;
            IUniqueValueRenderer pUnique          = new UniqueValueRendererClass();

            pUnique.FieldCount = 1;

            //遍历,根据code获取当前确诊人数
            //先获取图层的要素个数

            IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false);
            IFeature       pFt       = pFtCursor.NextFeature();

            pUnique.set_Field(0, pFieldName);
            //while (pFt != null) {
            //    int index = pFt.Fields.FindField(pFieldName);
            //    String code = pFt.get_Value(index).ToString();
            //    DataRow[] drs=dt.Select("code='" + code+"'");
            //    String num = drs[0]["CurConfirmeed"].ToString();
            //    pUnique.set_Value(0,num);
            //}



            ISimpleFillSymbol pSimFill = new SimpleFillSymbolClass();

            //给颜色

            //IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search (null, false);
            //IFeature pFt = pFtCursor.NextFeature ();

            IFillSymbol pFillSymbol1;

            ////添加第一个符号

            //pFillSymbol1 = new SimpleFillSymbolClass();

            //pFillSymbol1.Color = GetRGBColor(103, 252, 179) as IColor;

            ////添加第二个符号

            //IFillSymbol pFillSymbol2 = new SimpleFillSymbolClass();

            //pFillSymbol2.Color = GetRGBColor(125, 155, 251) as IColor;

            //创建并设置随机色谱从上面的的图可以看出我们要给每一个值定义一种颜色,我 们可以创建色谱,但是色谱的这些参数

            IRandomColorRamp pColorRamp = new RandomColorRampClass();

            pColorRamp.StartHue = 0;

            pColorRamp.MinValue = 0;

            pColorRamp.MinSaturation = 0;

            pColorRamp.EndHue = 360;

            pColorRamp.MaxValue = 100;

            pColorRamp.MaxSaturation = 100;
            pColorRamp.Size          = pCount;

            //pColorRamp.Size = pUniqueValueRenderer.ValueCount; bool ok = true;
            bool ok = true;

            pColorRamp.CreateRamp(out ok);
            IEnumColors pEnumRamp = pColorRamp.Colors;

            //IColor pColor = pEnumRamp.Next();

            int pIndex = pFt.Fields.FindField(pFieldName);

            //因为我只有24条记录,所以改变这些,这些都不会超过255或者为负数.求余

            int i = 0;

            while (pFt != null)

            {
                IColor pColor = pEnumRamp.Next();
                if (pColor == null)

                {
                    pEnumRamp.Reset();

                    pColor = pEnumRamp.Next();
                }

                //以下注释代码为自定义的两种颜色 ,如果不使用随机的颜色,可以采用这样的

                //if (i % 2 == 0)

                //{

                // pUnique.AddValue(Convert.ToString(pFt.get\_Value(pIndex)) , pFieldName, pFillSymbol1 as ISymbol);

                //}

                //else

                //{

                // pUnique.AddValue(Convert.ToString(pFt.get\_Value(pIndex)) , pFieldName, pFillSymbol2 as ISymbol);

                //}

                //i++;

                pFillSymbol1 = new SimpleFillSymbolClass();
                int R = Convert.ToInt32(pFt.get_Value(pIndex).ToString());
                if (R > 0 && R < 10)
                {
                    pFillSymbol1.Color = GetRgbColor(255, 255, 255);
                }
                else if (R >= 10 && R <= 100)
                {
                    pFillSymbol1.Color = GetRgbColor(255, 200, 200);
                }
                else if (R >= 100 && R <= 1000)
                {
                    pFillSymbol1.Color = GetRgbColor(255, 155, 155);
                }
                else if (R >= 1000 && R <= 10000)
                {
                    pFillSymbol1.Color = GetRgbColor(255, 100, 100);
                }
                else if (R >= 10000 && R <= 50000)
                {
                    pFillSymbol1.Color = GetRgbColor(255, 55, 55);
                }
                else
                {
                    pFillSymbol1.Color = GetRgbColor(255, 0, 0);
                }

                pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol1 as ISymbol);

                pFt = pFtCursor.NextFeature();

                // pColor = pEnumRamp.Next();
            }

            pGeoFeaturelayer.Renderer = pUnique as IFeatureRenderer;

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
        public IFeatureRenderer UniqueValueRenderer(IFeatureWorkspace workspace, IFeatureClass fc)
        {
            try
            {
                string tablename = ((IDataset)fc).BrowseName;
                ITable ipTable   = workspace.OpenTable(tablename);

                IFeatureCursor  featureCursor  = fc.Search(null, false);
                IDataStatistics dataStatistics = new DataStatisticsClass();
                dataStatistics.Cursor = featureCursor as ICursor;
                dataStatistics.Field  = "gridcode";

                System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues;
                enumerator.Reset();

                while (enumerator.MoveNext())
                {
                    object myObject = enumerator.Current;
                }

                int uniqueValues = dataStatistics.UniqueValueCount;

                //Create colors for each unique value.
                IRandomColorRamp colorRamp = new RandomColorRampClass();
                colorRamp.Size = uniqueValues;
                colorRamp.Seed = 100;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);
                if (createColorRamp == false)
                {
                    return(null);
                }

                IUniqueValueRenderer uvRenderer   = new UniqueValueRendererClass();
                IFeatureRenderer     featRenderer = (IFeatureRenderer)uvRenderer;

                uvRenderer.FieldCount = 1;

                ISimpleFillSymbol fillSymbol  = new SimpleFillSymbolClass();
                ISimpleFillSymbol fillSymbol2 = new SimpleFillSymbolClass();

                ISimpleLineSymbol outlineSymbol = new SimpleLineSymbolClass();
                outlineSymbol.Color = new RgbColorClass()
                {
                    NullColor = true
                } as IColor;
                outlineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;

                if (ShowNonVisibleData == true)
                {
                    fillSymbol.Color = new RgbColorClass()
                    {
                        Red = 255
                    } as IColor;
                    fillSymbol.Outline = outlineSymbol;
                    uvRenderer.AddValue("0", "", fillSymbol as ISymbol);
                    uvRenderer.set_Label("0", "Non-Visible");
                }
                fillSymbol2.Color = new RgbColorClass()
                {
                    Green = 255
                } as IColor;
                fillSymbol2.Outline = outlineSymbol;
                uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol);
                uvRenderer.set_Label("1", "Visible by 1 Observer");

                int field = ipTable.FindField("gridcode");
                uvRenderer.set_Field(0, "gridcode");

                for (int i = 2; i < uniqueValues; i++)
                {
                    ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass();
                    newFillSymbol.Color   = colorRamp.get_Color(i);
                    newFillSymbol.Outline = outlineSymbol;
                    uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol);
                    string label = "Visible by " + i.ToString() + " Observers";
                    uvRenderer.set_Label(i.ToString(), label);
                }

                return(featRenderer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
 private IColorRamp GetColorRamp(int colorSize)
 {
     IRandomColorRamp pColorRamp = new RandomColorRampClass();
     pColorRamp.StartHue = 0;  //0
     pColorRamp.EndHue = 360;     //360
     pColorRamp.MinSaturation = 15;  //15
     pColorRamp.MaxSaturation = 30;   //30
     pColorRamp.MinValue = 99;    //99
     pColorRamp.MaxValue = 100;     //100
     pColorRamp.Size = colorSize;
     bool ok = true;
     pColorRamp.CreateRamp(out ok);
     return pColorRamp as IColorRamp;
 }
        public static void DefineUniqueValueRenderer(IGeoFeatureLayer geoFealyr,string fieldName)
        {
            // Create color ramp for the symbol in rendere
            IRandomColorRamp randomColorRamp = new RandomColorRampClass();
            randomColorRamp.MinSaturation = 20;
            randomColorRamp.MaxSaturation = 40;
            randomColorRamp.MinValue = 85;
            randomColorRamp.MaxValue = 100;
            randomColorRamp.StartHue = 76;
            randomColorRamp.EndHue = 188;
            randomColorRamp.UseSeed = true;
            randomColorRamp.Seed = 43;
            // Create a symbol
            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
            simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
            simpleFillSymbol.Outline.Width = 0.4;
            // Create the renderer
            IUniqueValueRenderer uniqueValueRender = new UniqueValueRendererClass();
            uniqueValueRender.FieldCount = 1;
            uniqueValueRender.set_Field(0, fieldName);
            uniqueValueRender.DefaultSymbol = simpleFillSymbol as ISymbol;
            uniqueValueRender.UseDefaultSymbol = true;

            IDisplayTable displayTable = geoFealyr as IDisplayTable;
            IFeatureCursor feacursor = displayTable.SearchDisplayTable(null, false) as IFeatureCursor;
            IFeature fea = feacursor.NextFeature();

            bool valfound;
            int fieldIndex;

            IFields fields = feacursor.Fields;
            fieldIndex = fields.FindField(fieldName);
            while(fea!=null)
            {
                ISimpleFillSymbol classSymbol = new SimpleFillSymbolClass();
                classSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                classSymbol.Outline.Width = 0.4;

                string classValue;
                classValue = fea.get_Value(fieldIndex) as string;

                valfound = false;
                for(int i=0;i<=uniqueValueRender.ValueCount-1;i++)
                {
                    if(uniqueValueRender.get_Value(i)==classValue)
                    {
                        valfound = true;
                        break;
                    }
                }
                if(valfound==false)
                {
                    uniqueValueRender.AddValue(classValue, fieldName, classSymbol as ISymbol);
                    uniqueValueRender.set_Label(classValue, classValue);
                    uniqueValueRender.set_Symbol(classValue, classSymbol as ISymbol);
                }

                fea = feacursor.NextFeature();
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(feacursor);

            randomColorRamp.Size = uniqueValueRender.ValueCount;
            bool bOK;
            randomColorRamp.CreateRamp(out bOK);

            IEnumColors enumColors = randomColorRamp.Colors;
            enumColors.Reset();
            for(int j=0;j<=uniqueValueRender.ValueCount-1;j++)
            {
                string xv;
                xv = uniqueValueRender.get_Value(j);
                if(xv!="")
                {
                    ISimpleFillSymbol simplefs = uniqueValueRender.get_Symbol(xv) as ISimpleFillSymbol;
                    simplefs.Color = enumColors.Next();
                    uniqueValueRender.set_Symbol(xv, simplefs as ISymbol);
                }
            }

            uniqueValueRender.ColorScheme = "Custome";
            ITable tbl = displayTable as ITable;
            bool isString = tbl.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString;
            uniqueValueRender.set_FieldType(0, isString);

            geoFealyr.Renderer = uniqueValueRender as IFeatureRenderer;

            IUID uid = new UIDClass();
            uid.Value = "{25AE5C2F-0B57-41C6-A492-31352BAD3A37}";
            geoFealyr.RendererPropertyPageClassID = uid as UIDClass;
        }
Example #20
0
        private void UniqueValueRender_Click(object sender, EventArgs e)
        {
            //
            ITable pTable= (ITable)this.mainMapControl.get_Layer(0);
            int fieldIndex = pTable.FindField("NAME");//取得"NAME"字段的index,关键

            IQueryFilter pQueryFilter = new QueryFilterClass();
            pQueryFilter.WhereClause = "";
            pQueryFilter.AddField("NAME");
            //IFeatureCursor pFeatureCursor = pTable.Search(pQueryFilter, false);

            int rowCount = pTable.RowCount(pQueryFilter);//取得"NAME"字段有值得行的数目,关键!!!!!

            //以下代码创建并设置随机颜色带对象,并生成颜色
            IRandomColorRamp pColorRamp = new RandomColorRampClass();
            pColorRamp.StartHue = 0;
            pColorRamp.MinValue = 99;
            pColorRamp.MinSaturation = 15;
            pColorRamp.EndHue = 360;
            pColorRamp.MaxValue = 100;
            pColorRamp.MaxSaturation = 30;
            pColorRamp.Size = rowCount;
            bool ok = true;
            pColorRamp.CreateRamp(out ok);//产生颜色

            if (ok)
            {
                IEnumColors pEnumColors = pColorRamp.Colors;

                ISimpleFillSymbol pSimpleFillSymbol;
                IRowBuffer pRowBuffer;
                IColor pColor;
                string value;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();//创建着色对象
                pUniqueValueRenderer.FieldCount = 1;//设置只对一个字段进行着色
                pUniqueValueRenderer.set_Field(0, "NAME");

                for (int i = 0; i < rowCount; i++)
                {
                    pRowBuffer = (IRowBuffer)pTable.GetRow(i);//关键,用于取得字段值
                    value = pRowBuffer.get_Value(fieldIndex).ToString();
                    pColor = pEnumColors.Next();
                    pSimpleFillSymbol = new SimpleFillSymbolClass();
                    pSimpleFillSymbol.Color = pColor;
                    pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                    pUniqueValueRenderer.AddValue(value, "", (ISymbol)pSimpleFillSymbol);//为每个唯一值设置Symbol,关键!!!!!!
                }
                //ITransparencyRenderer pTransparencyRenderer = pUniqueValueRenderer as ITransparencyRenderer;
                //pTransparencyRenderer.TransparencyField = "";

                ((IGeoFeatureLayer)pTable).Renderer = pUniqueValueRenderer as IFeatureRenderer;
                this.mainMapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                //this.axTOCControl.SetBuddyControl(this.mainMapControl.Object);
                this.axTOCControl.Update();
            }
        }
Example #21
0
        private void btnAddAllValues_Click(object sender, EventArgs e)
        {
            //��ʼ���ͼ��ı����ֶε���Ϣ
            IFillSymbol pSymbol;
            IColor pColor;
            IColor pNextUniqueColor;
            IEnumColors pEnumRamp;
            IQueryFilter pQueryFilter;
            ICursor pCursor;
            IRow pNextRow;
            IRowBuffer pNextRowBuffer;
            object objTempValue="";
            object objCodeValue;
            ITable pTable = pFeatLayer as ITable;
            IRandomColorRamp pColorRamp = new RandomColorRampClass();
            m_colValues=new ArrayClass();
            if (comboBoxUnique.Text != "")
            {
                int iFieldNo = pTable.FindField(comboBoxUnique.Text);
                if (iFieldNo != -1)
                {
                    for (int i = 0; i <= 2; i++)
                    {
                        if (comboBoxEx1.SelectedIndex == i)
                        {
                            pColorRamp.StartHue = m_intColorRampArray[i, 0];
                            pColorRamp.EndHue = m_intColorRampArray[i, 1];
                            pColorRamp.MinValue = m_intColorRampArray[i, 2];
                            pColorRamp.MaxValue = m_intColorRampArray[i, 3];
                            pColorRamp.MinSaturation = m_intColorRampArray[i, 4];
                            pColorRamp.MaxSaturation = m_intColorRampArray[i, 5];
                        }
                    }
                    pColorRamp.Size = 100;
                    bool ok=true;
                    pColorRamp.CreateRamp(out ok);
                    pEnumRamp = pColorRamp.Colors;

                    pQueryFilter = new QueryFilterClass();
                    pQueryFilter.AddField(comboBoxUnique.Text);
                    pCursor = pTable.Search(pQueryFilter, true);
                    pNextRow = pCursor.NextRow();

                    m_intSymbolsNum = 0;
                    //�����״ͼ��
                    if (m_strShapeType == "Fill Symbols")
                    {
                        IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
                        m_pSymbolsArray = new ESRI.ArcGIS.esriSystem.ArrayClass();
                        while (pNextRow != null)
                        {
                            pNextRowBuffer = pNextRow as IRowBuffer;
                            objCodeValue=pNextRowBuffer.get_Value(iFieldNo);
                            if ((objTempValue != objCodeValue) || (m_intSymbolsNum == 0))
                            {
                                pNextUniqueColor = pEnumRamp.Next();
                                if (pNextUniqueColor == null)
                                {
                                    pEnumRamp.Reset();
                                    pNextUniqueColor = pEnumRamp.Next();
                                }
                                pFillSymbol.Color = pNextUniqueColor;
                                m_pSymbolsArray.Add(pFillSymbol);
                                m_colValues.Add(objCodeValue);
                                m_intSymbolsNum += 1;
                                objTempValue = objCodeValue;
                                pFillSymbol = null;
                            }
                            pNextRow = pCursor.NextRow();
                        }
                    }
                    //��ͼ��
                    if (m_strShapeType == "Line Symbols")
                    {
                        ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
                        m_pSymbolsArray.RemoveAll();
                        while (pNextRow != null)
                        {
                            pNextRowBuffer = pNextRow as IRowBuffer;
                            objCodeValue = pNextRowBuffer.get_Value(iFieldNo);
                            if ((objTempValue != objCodeValue) || (m_intSymbolsNum == 0))
                            {
                                pNextUniqueColor = pEnumRamp.Next();
                                if (pNextUniqueColor == null)
                                {
                                    pEnumRamp.Reset();
                                    pNextUniqueColor = pEnumRamp.Next();
                                }
                                pLineSymbol.Color = pNextUniqueColor;
                                m_pSymbolsArray.Add(pLineSymbol);
                                m_colValues.Add(objCodeValue);
                                m_intSymbolsNum += 1;
                                objTempValue = objCodeValue;
                                pLineSymbol = null;
                            }
                            pNextRow = pCursor.NextRow();
                        }
                    }
                    //��ͼ��
                    if (m_strShapeType == "Marker Symbols")
                    {
                        IMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass();
                        m_pSymbolsArray.RemoveAll();
                        while (pNextRow != null)
                        {
                            pNextRowBuffer = pNextRow as IRowBuffer;
                            objCodeValue = pNextRowBuffer.get_Value(iFieldNo);
                            if ((objTempValue != objCodeValue) || (m_intSymbolsNum == 0))
                            {
                                pNextUniqueColor = pEnumRamp.Next();
                                if (pNextUniqueColor == null)
                                {
                                    pEnumRamp.Reset();
                                    pNextUniqueColor = pEnumRamp.Next();
                                }
                                pMarkerSymbol.Color = pNextUniqueColor;
                                m_pSymbolsArray.Add(pMarkerSymbol);
                                m_colValues.Add(objCodeValue);
                                m_intSymbolsNum += 1;
                                pMarkerSymbol = null;
                            }
                            pNextRow = pCursor.NextRow();
                        }
                    }
                    pColorRamp = null;
                    pQueryFilter = null;
                    pColorRamp = null;
                    //��ʾ����

                }
            }
        }
Example #22
0
        public static void DefineUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName)
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();

            //Create the color ramp for the symbols in the renderer.
            pRandomColorRamp.MinSaturation = 20;
            pRandomColorRamp.MaxSaturation = 40;
            pRandomColorRamp.MinValue      = 85;
            pRandomColorRamp.MaxValue      = 100;
            pRandomColorRamp.StartHue      = 76;
            pRandomColorRamp.EndHue        = 188;
            pRandomColorRamp.UseSeed       = true;
            pRandomColorRamp.Seed          = 43;

            //Create the renderer.
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();

            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();

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

            //These properties should be set prior to adding values.
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, fieldName);
            pUniqueValueRenderer.DefaultSymbol    = pSimpleFillSymbol as ISymbol;
            pUniqueValueRenderer.UseDefaultSymbol = true;

            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(fieldName);
            while (pFeature != null)
            {
                ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass();
                pClassSymbol.Style         = esriSimpleFillStyle.esriSFSSolid;
                pClassSymbol.Outline.Width = 0.4;

                string classValue;
                classValue = pFeature.get_Value(fieldIndex) as string;

                //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, fieldName, 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.
            pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool bOK;

            pRandomColorRamp.CreateRamp(out bOK);

            IEnumColors pEnumColors = pRandomColorRamp.Colors;

            pEnumColors.Reset();
            for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++)
            {
                string xv;
                xv = pUniqueValueRenderer.get_Value(j);
                if (xv != "")
                {
                    ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv)
                                                         as ISimpleFillSymbol;
                    pSimpleFillColor.Color = pEnumColors.Next();
                    pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol);
                }
            }

            //'** If you didn't use a predefined color ramp in a style, use "Custom" here.
            //'** Otherwise, use the name of the color ramp you selected.

            pUniqueValueRenderer.ColorScheme = pRandomColorRamp.Name;//"Custom";

            ITable pTable   = pDisplayTable as ITable;
            bool   isString = pTable.Fields.get_Field(fieldIndex).Type ==
                              esriFieldType.esriFieldTypeString;

            pUniqueValueRenderer.set_FieldType(0, isString);
            pGeoFeatureLayer.Renderer = pUniqueValueRenderer as IFeatureRenderer;

            //This makes the layer properties symbology tab show the correct interface.
            IUID pUID = new UIDClass();

            pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}";
            pGeoFeatureLayer.RendererPropertyPageClassID = pUID as UIDClass;
        }
        public UniqueValueRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer,int pCount, string pFieldName)
        {
            IGeoFeatureLayer pGeoFeaturelayer = pFtLayer as IGeoFeatureLayer;

            IUniqueValueRenderer pUnique = new UniqueValueRendererClass();

            pUnique.FieldCount = 1;

            pUnique.set_Field(0, pFieldName);

            ISimpleFillSymbol pSimFill = new SimpleFillSymbolClass();

            //给颜色

            IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false);

            IFeature pFt = pFtCursor.NextFeature();

            IFillSymbol pFillSymbol1;

            ////添加第一个符号
            //pFillSymbol1 = new SimpleFillSymbolClass();
            //pFillSymbol1.Color = GetRGBColor(103, 252, 179) as IColor;

            ////添加第二个符号
            //IFillSymbol pFillSymbol2 = new SimpleFillSymbolClass();
            //pFillSymbol2.Color = GetRGBColor(125, 155, 251) as IColor;

            //创建并设置随机色谱从上面的的图可以看出我们要给每一个值定义一种颜色,我们可以创建色谱,但是色谱的这些参数
              //我调不好这个没,因此掠过则个步骤,我重新定义了两个符号。

            IRandomColorRamp pColorRamp = new RandomColorRampClass();

            pColorRamp.StartHue = 0;

            pColorRamp.MinValue = 20;

            pColorRamp.MinSaturation = 15;

            pColorRamp.EndHue = 360;

            pColorRamp.MaxValue = 100;

            pColorRamp.MaxSaturation = 30;

            pColorRamp.Size = pCount ;

            //pColorRamp.Size = pUniqueValueRenderer.ValueCount;

            bool ok = true;

            pColorRamp.CreateRamp(out ok);

            IEnumColors pEnumRamp = pColorRamp.Colors;

            //IColor pColor = pEnumRamp.Next();

            int pIndex =pFt.Fields.FindField(pFieldName);

               //因为我只有24条记录,所以改变这些,这些都不会超过255或者为负数.求余

            int i = 0;

            while (pFt != null)
            {
                IColor pColor = pEnumRamp.Next();
                if(pColor ==null)
                {
                    pEnumRamp.Reset();
                    pColor = pEnumRamp.Next();

                }

                //if (i % 2 == 0)
                //{
                //    pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol1 as ISymbol);

                //}
                //else
                //{
                //    pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol2 as ISymbol);
                //}

                //i++;

                pFillSymbol1 = new SimpleFillSymbolClass();

                pFillSymbol1.Color = pColor;
                pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol1 as ISymbol);

                pFt = pFtCursor.NextFeature();

              //  pColor = pEnumRamp.Next();

            }

            pGeoFeaturelayer.Renderer = pUnique as IFeatureRenderer;

            pMapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Example #24
0
        private void btnAddAllValues_Click(object sender, EventArgs e)
        {
            //开始获得图层的表格和字段等信息
            IFillSymbol      pSymbol;
            IColor           pColor;
            IColor           pNextUniqueColor;
            IEnumColors      pEnumRamp;
            IQueryFilter     pQueryFilter;
            ICursor          pCursor;
            IRow             pNextRow;
            IRowBuffer       pNextRowBuffer;
            object           objTempValue = "";
            object           objCodeValue;
            ITable           pTable     = pFeatLayer as ITable;
            IRandomColorRamp pColorRamp = new RandomColorRampClass();

            m_colValues = new ArrayClass();
            if (comboBoxUnique.Text != "")
            {
                int iFieldNo = pTable.FindField(comboBoxUnique.Text);
                if (iFieldNo != -1)
                {
                    for (int i = 0; i <= 2; i++)
                    {
                        if (comboBoxEx1.SelectedIndex == i)
                        {
                            pColorRamp.StartHue      = m_intColorRampArray[i, 0];
                            pColorRamp.EndHue        = m_intColorRampArray[i, 1];
                            pColorRamp.MinValue      = m_intColorRampArray[i, 2];
                            pColorRamp.MaxValue      = m_intColorRampArray[i, 3];
                            pColorRamp.MinSaturation = m_intColorRampArray[i, 4];
                            pColorRamp.MaxSaturation = m_intColorRampArray[i, 5];
                        }
                    }
                    pColorRamp.Size = 100;
                    bool ok = true;
                    pColorRamp.CreateRamp(out ok);
                    pEnumRamp = pColorRamp.Colors;

                    pQueryFilter = new QueryFilterClass();
                    pQueryFilter.AddField(comboBoxUnique.Text);
                    pCursor  = pTable.Search(pQueryFilter, true);
                    pNextRow = pCursor.NextRow();

                    m_intSymbolsNum = 0;
                    //填加面状图层
                    if (m_strShapeType == "Fill Symbols")
                    {
                        IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
                        m_pSymbolsArray = new ESRI.ArcGIS.esriSystem.ArrayClass();
                        while (pNextRow != null)
                        {
                            pNextRowBuffer = pNextRow as IRowBuffer;
                            objCodeValue   = pNextRowBuffer.get_Value(iFieldNo);
                            if ((objTempValue != objCodeValue) || (m_intSymbolsNum == 0))
                            {
                                pNextUniqueColor = pEnumRamp.Next();
                                if (pNextUniqueColor == null)
                                {
                                    pEnumRamp.Reset();
                                    pNextUniqueColor = pEnumRamp.Next();
                                }
                                pFillSymbol.Color = pNextUniqueColor;
                                m_pSymbolsArray.Add(pFillSymbol);
                                m_colValues.Add(objCodeValue);
                                m_intSymbolsNum += 1;
                                objTempValue     = objCodeValue;
                                pFillSymbol      = null;
                            }
                            pNextRow = pCursor.NextRow();
                        }
                    }
                    //线图层
                    if (m_strShapeType == "Line Symbols")
                    {
                        ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
                        m_pSymbolsArray.RemoveAll();
                        while (pNextRow != null)
                        {
                            pNextRowBuffer = pNextRow as IRowBuffer;
                            objCodeValue   = pNextRowBuffer.get_Value(iFieldNo);
                            if ((objTempValue != objCodeValue) || (m_intSymbolsNum == 0))
                            {
                                pNextUniqueColor = pEnumRamp.Next();
                                if (pNextUniqueColor == null)
                                {
                                    pEnumRamp.Reset();
                                    pNextUniqueColor = pEnumRamp.Next();
                                }
                                pLineSymbol.Color = pNextUniqueColor;
                                m_pSymbolsArray.Add(pLineSymbol);
                                m_colValues.Add(objCodeValue);
                                m_intSymbolsNum += 1;
                                objTempValue     = objCodeValue;
                                pLineSymbol      = null;
                            }
                            pNextRow = pCursor.NextRow();
                        }
                    }
                    //点图层
                    if (m_strShapeType == "Marker Symbols")
                    {
                        IMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass();
                        m_pSymbolsArray.RemoveAll();
                        while (pNextRow != null)
                        {
                            pNextRowBuffer = pNextRow as IRowBuffer;
                            objCodeValue   = pNextRowBuffer.get_Value(iFieldNo);
                            if ((objTempValue != objCodeValue) || (m_intSymbolsNum == 0))
                            {
                                pNextUniqueColor = pEnumRamp.Next();
                                if (pNextUniqueColor == null)
                                {
                                    pEnumRamp.Reset();
                                    pNextUniqueColor = pEnumRamp.Next();
                                }
                                pMarkerSymbol.Color = pNextUniqueColor;
                                m_pSymbolsArray.Add(pMarkerSymbol);
                                m_colValues.Add(objCodeValue);
                                m_intSymbolsNum += 1;
                                pMarkerSymbol    = null;
                            }
                            pNextRow = pCursor.NextRow();
                        }
                    }
                    pColorRamp   = null;
                    pQueryFilter = null;
                    pColorRamp   = null;
                    //显示符号
                }
            }
        }
        //单一或多字段符号化
        private void UniqueValueRenderer(IFeatureLayer pFeatLyr, string[] sFieldName)
        {
            IFeatureLayer pFLayer = pLayer as IFeatureLayer;

            IGeoFeatureLayer geoLayer = pLayer as IGeoFeatureLayer;

            IFeatureClass fcls = pFLayer.FeatureClass;

            IQueryFilter pQueryFilter = new QueryFilterClass();

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

            IRandomColorRamp rx = new RandomColorRampClass();

            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 UniqueValueRendererClass();

            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 SimpleFillSymbolClass();

                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;
            //刷新地图和TOOCotrol
            IActiveView pActiveView = _MapControl.Map as IActiveView;

            pActiveView.Refresh();
            axTOCControl1.Update();
        }
Example #26
0
        private void UniqueValueRenderer(IFeatureLayer pFeatLyr, string sFieldName)
        {
            IGeoFeatureLayer     pGeoFeatureLayer   = pFeatLyr as IGeoFeatureLayer;
            ITable               pTable             = pFeatLyr as ITable;
            IUniqueValueRenderer pUniqueValueRender = new UniqueValueRendererClass();
            int intFieldNumber = pTable.FindField(sFieldName);

            pUniqueValueRender.FieldCount = 1;                              //设置唯一值符号化的关键字段为一个
            pUniqueValueRender.set_Field(0, sFieldName);                    //设置唯一值符号化的第一个关键字段
            IRandomColorRamp pRandomcolorramp = new RandomColorRampClass(); //随机颜色

            pRandomcolorramp.StartHue      = 0;
            pRandomcolorramp.MinValue      = 0;
            pRandomcolorramp.MinSaturation = 15;
            pRandomcolorramp.EndHue        = 360;
            pRandomcolorramp.MaxValue      = 100;
            pRandomcolorramp.MaxSaturation = 30;//到这儿为止
            IQueryFilter pQueryFilter = new QueryFilterClass();

            pRandomcolorramp.Size = pFeatLyr.FeatureClass.FeatureCount(pQueryFilter);//通过属性字段的值的个数来添加颜色个数
            bool bSuccess;

            pRandomcolorramp.CreateRamp(out bSuccess);
            IEnumColors pEnumRamp = pRandomcolorramp.Colors;

            //查询字段的值
            pQueryFilter = new QueryFilterClass();
            pQueryFilter.AddField(sFieldName);
            ICursor pCursor  = pTable.Search(pQueryFilter, true); //获取属性表中对应字段的值的游标
            IRow    pNextRow = pCursor.NextRow();                 //获取下一行,这边应是第一行

            while (pNextRow != null)                              //若不为空添加颜色并获取下一行循环到结束
            {
                IRowBuffer pnextrowBuffer   = pNextRow;
                object     codeValue        = pnextrowBuffer.Value[intFieldNumber];
                IColor     pnextuniquecolor = pEnumRamp.Next();
                if (pnextuniquecolor == null)
                {
                    pEnumRamp.Reset();
                    pnextuniquecolor = pEnumRamp.Next();
                }
                switch (pGeoFeatureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                {
                    IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
                    pFillSymbol.Color = pnextuniquecolor;
                    pUniqueValueRender.AddValue(codeValue.ToString(), "", pFillSymbol as ISymbol);
                    pNextRow = pCursor.NextRow();
                    break;
                }

                case esriGeometryType.esriGeometryPolyline:
                {
                    ILineSymbol plineSymbol = new SimpleLineSymbolClass();
                    plineSymbol.Color = pnextuniquecolor;
                    pUniqueValueRender.AddValue(codeValue.ToString(), "", plineSymbol as ISymbol);
                    pNextRow = pCursor.NextRow();
                    break;
                }

                case esriGeometryType.esriGeometryPoint:
                {
                    IMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass();
                    pMarkerSymbol.Color = pnextuniquecolor;
                    pUniqueValueRender.AddValue(codeValue.ToString(), "", pMarkerSymbol as ISymbol);
                    pNextRow = pCursor.NextRow();
                    break;
                }
                }
            }
            pGeoFeatureLayer.Renderer = pUniqueValueRender as IFeatureRenderer;
            axMapControl1.Refresh();
            axTOCControl1.Update();
        }
Example #27
0
        private IEnumColors CreateRdmColorRamp(int startHue, int endHue, int minValue, int maxValue, int minSaturation,
            int maxSaturation, int size, int seed)
        {
            IRandomColorRamp pRdmcolor = new RandomColorRampClass();
            pRdmcolor.StartHue = startHue;
            pRdmcolor.EndHue = endHue;
            pRdmcolor.MinValue = minValue;
            pRdmcolor.MaxValue = maxValue;
            pRdmcolor.MinSaturation = minSaturation;
            pRdmcolor.MaxSaturation = maxSaturation;
            pRdmcolor.Size = size;
            pRdmcolor.Seed = seed;
            bool b;
            pRdmcolor.CreateRamp(out b);

            return pRdmcolor.Colors;
        }
        /// <summary>
        /// 实现要素图层属性唯一值设色
        /// </summary>
        /// <param name="pFeatureLayer">需要设色的要素图层</param>
        /// <param name="fieldName">唯一值的属性字段</param>
        private void UniqueValueRenderer(IFeatureLayer pFeatureLayer, string fieldName)
        {
            IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
            ITable           pTable           = pFeatureLayer as ITable;
            int fieldNumber = pTable.FindField(fieldName);
            IUniqueValueRenderer pUniqueRenderer = new UniqueValueRendererClass();

            pUniqueRenderer.FieldCount = 1;
            pUniqueRenderer.set_Field(0, fieldName);

            //设置显示颜色的范围
            IRandomColorRamp pRandColorRamp = new RandomColorRampClass();

            pRandColorRamp.StartHue      = 0;
            pRandColorRamp.MinValue      = 85;
            pRandColorRamp.MinSaturation = 15;
            pRandColorRamp.EndHue        = 360;
            pRandColorRamp.MaxValue      = 100;
            pRandColorRamp.MaxSaturation = 30;

            //创建随机颜色带
            pRandColorRamp.Size = getUniqueValue(pFeatureLayer.FeatureClass, fieldName).Count;
            bool bSucess = false;

            pRandColorRamp.CreateRamp(out bSucess);

            IEnumColors pEnumColors      = pRandColorRamp.Colors;
            IColor      pNextUniqueColor = null;

            //属性唯一值
            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.AddField(fieldName);
            ICursor    pCursor        = pFeatureLayer.FeatureClass.Search(pQueryFilter, false) as ICursor;
            IRow       pNextRow       = pCursor.NextRow();
            object     codeValue      = null;
            IRowBuffer pNextRowBuffer = null;

            IFillSymbol   pFillSymbol   = null;
            ILineSymbol   pLineSymbol   = null;
            IMarkerSymbol pMarkerSymbol = null;

            while (pNextRow != null)
            {
                pNextRowBuffer   = pNextRow as IRowBuffer;
                codeValue        = pNextRowBuffer.get_Value(fieldNumber);
                pNextUniqueColor = pEnumColors.Next();
                if (pNextUniqueColor == null)
                {
                    pEnumColors.Reset();
                    pNextUniqueColor = pEnumColors.Next();
                }
                switch (pGeoFeatureLayer.FeatureClass.ShapeType)
                {
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                    pMarkerSymbol       = new SimpleMarkerSymbolClass();
                    pMarkerSymbol.Color = pNextUniqueColor;
                    pUniqueRenderer.AddValue(codeValue.ToString(), "", pMarkerSymbol as ISymbol);
                    pNextRow = pCursor.NextRow();
                    break;

                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                    pLineSymbol       = new SimpleLineSymbolClass();
                    pLineSymbol.Color = pNextUniqueColor;
                    pUniqueRenderer.AddValue(codeValue.ToString(), "", pLineSymbol as ISymbol);
                    pNextRow = pCursor.NextRow();
                    break;

                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                    pFillSymbol       = new SimpleFillSymbolClass();
                    pFillSymbol.Color = pNextUniqueColor;
                    pUniqueRenderer.AddValue(codeValue.ToString(), "", pFillSymbol as ISymbol);
                    pNextRow = pCursor.NextRow();
                    int k = pFillSymbol.Color.CMYK;
                    break;

                default:
                    break;
                }
            }
            pGeoFeatureLayer.Renderer = pUniqueRenderer as IFeatureRenderer;

            //必须手动清除COM对象,否则会造成内存溢出(尤其是IQueryFilter,ICursor)
            Marshal.ReleaseComObject(pQueryFilter);
            Marshal.ReleaseComObject(pCursor);
            Marshal.ReleaseComObject(pEnumColors);
        }
Example #29
0
        private IFeatureRenderer method_6(ITopology itopology_0, esriTopologyRenderer esriTopologyRenderer_0)
        {
            IUniqueValueRenderer renderer = null;
            IList               list;
            IFillSymbol         symbol;
            ILineSymbol         symbol2;
            bool                flag;
            IEnumColors         colors;
            IFillSymbol         symbol3;
            int                 num;
            ITopologyRule       rule;
            int                 topologyRuleType;
            ILineSymbol         symbol4;
            ISimpleMarkerSymbol symbol5;
            ISimpleMarkerSymbol symbol6;
            IRandomColorRamp    ramp = new RandomColorRampClass
            {
                StartHue      = 40,
                EndHue        = 120,
                MinValue      = 65,
                MaxValue      = 90,
                MinSaturation = 25,
                MaxSaturation = 45,
                Size          = 5,
                Seed          = 23
            };

            switch (esriTopologyRenderer_0)
            {
            case esriTopologyRenderer.esriTRAreaErrors:
                renderer = new UniqueValueRendererClass();
                list     = this.method_4(itopology_0);
                symbol   = new SimpleFillSymbolClass
                {
                    Color = ColorManage.CreatColor(255, 128, 128)
                };
                symbol2 = new SimpleLineSymbolClass
                {
                    Width = 2.5,
                    Color = ColorManage.CreatColor(255, 0, 0)
                };
                symbol.Outline         = symbol2;
                renderer.DefaultSymbol = (symbol as IClone).Clone() as ISymbol;
                ramp.Size = list.Count + 2;
                ramp.CreateRamp(out flag);
                colors = ramp.Colors;
                colors.Reset();
                symbol3       = (symbol as IClone).Clone() as IFillSymbol;
                symbol3.Color = colors.Next();
                renderer.AddValue("0", "必须大于集束容限值", symbol3 as ISymbol);
                renderer.set_Label("0", "必须大于集束容限值");
                for (num = 0; num < list.Count; num++)
                {
                    rule             = list[num] as ITopologyRule;
                    symbol3          = (symbol as IClone).Clone() as IFillSymbol;
                    symbol3.Color    = colors.Next();
                    topologyRuleType = (int)rule.TopologyRuleType;
                    renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType),
                                      symbol3 as ISymbol);
                    renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType));
                }
                break;

            case esriTopologyRenderer.esriTRLineErrors:
                renderer = new UniqueValueRendererClass();
                list     = this.method_3(itopology_0);
                symbol2  = new SimpleLineSymbolClass
                {
                    Width = 2.5,
                    Color = ColorManage.CreatColor(255, 128, 128)
                };
                renderer.DefaultSymbol = (symbol2 as IClone).Clone() as ISymbol;
                ramp.Size = list.Count + 2;
                ramp.CreateRamp(out flag);
                colors = ramp.Colors;
                colors.Reset();
                symbol4       = (symbol2 as IClone).Clone() as ILineSymbol;
                symbol4.Color = colors.Next();
                renderer.AddValue("0", "必须大于集束容限值", symbol4 as ISymbol);
                renderer.set_Label("0", "必须大于集束容限值");
                for (num = 0; num < list.Count; num++)
                {
                    rule             = list[num] as ITopologyRule;
                    symbol4          = (symbol2 as IClone).Clone() as ILineSymbol;
                    symbol4.Color    = colors.Next();
                    topologyRuleType = (int)rule.TopologyRuleType;
                    renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType),
                                      symbol4 as ISymbol);
                    renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType));
                }
                break;

            case esriTopologyRenderer.esriTRPointErrors:
                renderer = new UniqueValueRendererClass();
                list     = this.method_2(itopology_0);
                symbol5  = new SimpleMarkerSymbolClass
                {
                    Size  = 6.0,
                    Style = esriSimpleMarkerStyle.esriSMSSquare,
                    Color = ColorManage.CreatColor(255, 128, 128)
                };
                renderer.DefaultSymbol = (symbol5 as IClone).Clone() as ISymbol;
                if (list.Count > 0)
                {
                    ramp.Size = list.Count + 1;
                    ramp.CreateRamp(out flag);
                    colors = ramp.Colors;
                    colors.Reset();
                    symbol6 = null;
                    for (num = 0; num < list.Count; num++)
                    {
                        rule             = list[num] as ITopologyRule;
                        symbol6          = (symbol5 as IClone).Clone() as ISimpleMarkerSymbol;
                        symbol6.Color    = colors.Next();
                        topologyRuleType = (int)rule.TopologyRuleType;
                        renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType),
                                          symbol6 as ISymbol);
                        renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType));
                    }
                }
                break;

            case esriTopologyRenderer.esriTRAreaExceptions:
                renderer = new UniqueValueRendererClass();
                list     = this.method_4(itopology_0);
                symbol   = new SimpleFillSymbolClass
                {
                    Color = ColorManage.CreatColor(255, 255, 255)
                };
                symbol2 = new SimpleLineSymbolClass
                {
                    Width = 1.0,
                    Color = ColorManage.CreatColor(128, 255, 128)
                };
                symbol.Outline         = symbol2;
                renderer.DefaultSymbol = (symbol as IClone).Clone() as ISymbol;
                ramp.Size = list.Count + 2;
                ramp.CreateRamp(out flag);
                colors = ramp.Colors;
                colors.Reset();
                symbol3       = (symbol as IClone).Clone() as IFillSymbol;
                symbol3.Color = colors.Next();
                renderer.AddValue("0", "必须大于集束容限值", symbol3 as ISymbol);
                renderer.set_Label("0", "必须大于集束容限值");
                for (num = 0; num < list.Count; num++)
                {
                    rule             = list[num] as ITopologyRule;
                    symbol3          = (symbol as IClone).Clone() as IFillSymbol;
                    symbol3.Color    = colors.Next();
                    topologyRuleType = (int)rule.TopologyRuleType;
                    renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType),
                                      symbol3 as ISymbol);
                    renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType));
                }
                break;

            case esriTopologyRenderer.esriTRLineExceptions:
                renderer = new UniqueValueRendererClass();
                list     = this.method_3(itopology_0);
                symbol2  = new SimpleLineSymbolClass
                {
                    Width = 1.0,
                    Color = ColorManage.CreatColor(128, 255, 128)
                };
                renderer.DefaultSymbol = (symbol2 as IClone).Clone() as ISymbol;
                ramp.Size = list.Count + 2;
                ramp.CreateRamp(out flag);
                colors = ramp.Colors;
                colors.Reset();
                symbol4       = (symbol2 as IClone).Clone() as ILineSymbol;
                symbol4.Color = colors.Next();
                renderer.AddValue("0", "必须大于集束容限值", symbol4 as ISymbol);
                renderer.set_Label("0", "必须大于集束容限值");
                for (num = 0; num < list.Count; num++)
                {
                    rule             = list[num] as ITopologyRule;
                    symbol4          = (symbol2 as IClone).Clone() as ILineSymbol;
                    symbol4.Color    = colors.Next();
                    topologyRuleType = (int)rule.TopologyRuleType;
                    renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType),
                                      symbol4 as ISymbol);
                    renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType));
                }
                break;

            case esriTopologyRenderer.esriTRPointExceptions:
                renderer = new UniqueValueRendererClass();
                list     = this.method_2(itopology_0);
                symbol5  = new SimpleMarkerSymbolClass
                {
                    Size  = 5.0,
                    Style = esriSimpleMarkerStyle.esriSMSSquare,
                    Color = ColorManage.CreatColor(128, 255, 128)
                };
                renderer.DefaultSymbol = (symbol5 as IClone).Clone() as ISymbol;
                if (list.Count > 0)
                {
                    ramp.Size = list.Count + 1;
                    ramp.CreateRamp(out flag);
                    colors = ramp.Colors;
                    colors.Reset();
                    symbol6 = null;
                    for (num = 0; num < list.Count; num++)
                    {
                        rule             = list[num] as ITopologyRule;
                        symbol6          = (symbol5 as IClone).Clone() as ISimpleMarkerSymbol;
                        symbol6.Color    = colors.Next();
                        topologyRuleType = (int)rule.TopologyRuleType;
                        renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType),
                                          symbol6 as ISymbol);
                        renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType));
                    }
                }
                break;
            }
            return(renderer as IFeatureRenderer);
        }
Example #30
0
        public static void UniqueRender(ILayer currentLayer, string fieldName)
        {
            IGeoFeatureLayer     m_pGeoFeatureL;
            IUniqueValueRenderer pUniqueValueR;
            IFillSymbol          pFillSymbol;
            IColor           pNextUniqueColor;
            IEnumColors      pEnumRamp;
            ITable           pTable;
            int              lfieldNumber;
            IRow             pNextRow;
            IRowBuffer       pNextRowBuffer;
            ICursor          pCursor;
            IQueryFilter     pQueryFilter;
            string           codeValue;
            IRandomColorRamp pColorRamp;

            m_pGeoFeatureL = (IGeoFeatureLayer)currentLayer;
            pUniqueValueR  = new UniqueValueRendererClass();
            pTable         = (ITable)m_pGeoFeatureL;
            lfieldNumber   = 0;
            for (int i = 0; i < pTable.Fields.FieldCount; i++)
            {
                if (pTable.Fields.get_Field(i).Name.ToUpper().Contains(fieldName.ToUpper()))
                {
                    fieldName    = pTable.Fields.get_Field(i).Name;
                    lfieldNumber = i;
                    break;
                }
            }
            pUniqueValueR.FieldCount = 1;
            pUniqueValueR.set_Field(0, fieldName);
            pColorRamp               = new RandomColorRampClass();
            pColorRamp.StartHue      = 0;
            pColorRamp.MinValue      = 99;
            pColorRamp.MinSaturation = 15;
            pColorRamp.EndHue        = 360;
            pColorRamp.MaxValue      = 100;
            pColorRamp.MaxSaturation = 30;
            pColorRamp.Size          = 100;
            bool ok = true;

            pColorRamp.CreateRamp(out ok);
            pEnumRamp        = pColorRamp.Colors;
            pNextUniqueColor = null;
            pQueryFilter     = new QueryFilterClass();
            pQueryFilter.AddField(fieldName);
            pCursor  = pTable.Search(pQueryFilter, true);
            pNextRow = pCursor.NextRow();
            while (pNextRow != null)
            {
                pNextRowBuffer   = pNextRow;
                codeValue        = (string)pNextRowBuffer.get_Value(lfieldNumber);
                pNextUniqueColor = pEnumRamp.Next();
                if (pNextUniqueColor == null)
                {
                    pEnumRamp.Reset();
                    pNextUniqueColor = pEnumRamp.Next();
                }
                pFillSymbol       = new SimpleFillSymbolClass();
                pFillSymbol.Color = pNextUniqueColor;
                pUniqueValueR.AddValue(codeValue, fieldName, (ISymbol)
                                       pFillSymbol);
                pNextRow = pCursor.NextRow();
            }
            m_pGeoFeatureL.Renderer = (IFeatureRenderer)pUniqueValueR;
        }
        /// <summary>
        /// 按聚类号对凸包进行渲染
        /// </summary>
        /// <param name="pGeoFeatureLayer"></param>
        /// <param name="fieldName"></param>
        public void DefinePointUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName)
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();
            //Create the color ramp for the symbols in the renderer.
            pRandomColorRamp.MinSaturation = 20;
            pRandomColorRamp.MaxSaturation = 40;
            pRandomColorRamp.MinValue = 85;
            pRandomColorRamp.MaxValue = 100;
            pRandomColorRamp.StartHue = 76;
            pRandomColorRamp.EndHue = 188;
            pRandomColorRamp.UseSeed = true;
            pRandomColorRamp.Seed = 43;

            //Create the renderer.
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();

            /*             ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
                        pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSimpleFillSymbol.Outline.Width = 0.4;
            */
            ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
            pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
            pSimpleMarkerSymbol.Size = 5;
            pSimpleMarkerSymbol.Outline = true;
            IRgbColor pLineRgbColor = new RgbColorClass();
            pLineRgbColor.Red = 0;
            pLineRgbColor.Green = 0;
            pLineRgbColor.Blue = 0;
            pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor;

            //These properties should be set prior to adding values.
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, fieldName);
            pUniqueValueRenderer.DefaultSymbol = pSimpleMarkerSymbol as ISymbol;
            pUniqueValueRenderer.UseDefaultSymbol = true;

            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(fieldName);
            while (pFeature != null)
            {
                /*               ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass();
                               pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                               pClassSymbol.Outline.Width = 0.4;
               */
                ISimpleMarkerSymbol pClassSymbol = new SimpleMarkerSymbolClass();
                pClassSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                pClassSymbol.Size = 5;
                pClassSymbol.Outline = true;
                pClassSymbol.OutlineColor = pLineRgbColor as IColor;

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

                //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, fieldName, 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.
            pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool bOK;
            pRandomColorRamp.CreateRamp(out bOK);

            IEnumColors pEnumColors = pRandomColorRamp.Colors;
            pEnumColors.Reset();
            for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++)
            {
                string xv;
                xv = pUniqueValueRenderer.get_Value(j);
                if (xv != "")
                {
                    ISimpleMarkerSymbol pSimpleMarkerColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleMarkerSymbol;
                    pSimpleMarkerColor.Color = pEnumColors.Next();
                    pUniqueValueRenderer.set_Symbol(xv, pSimpleMarkerColor as ISymbol);

                }
            }
            pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
            pGeoFeatureLayer.DisplayField = fieldName;
        }
        public void UniqueValueRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, int pCount, string pFieldName)

        {
            IGeoFeatureLayer     pGeoFeaturelayer = pFtLayer as IGeoFeatureLayer;
            IUniqueValueRenderer pUnique          = new UniqueValueRendererClass();

            pUnique.FieldCount = 1;

            pUnique.set_Field(0, pFieldName);

            ISimpleFillSymbol pSimFill = new SimpleFillSymbolClass();

            //给颜色

            IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false);
            IFeature       pFt       = pFtCursor.NextFeature();

            IFillSymbol pFillSymbol1;

            ////添加第一个符号

            //pFillSymbol1 = new SimpleFillSymbolClass();

            //pFillSymbol1.Color = GetRGBColor(103, 252, 179) as IColor;

            ////添加第二个符号

            //IFillSymbol pFillSymbol2 = new SimpleFillSymbolClass();

            //pFillSymbol2.Color = GetRGBColor(125, 155, 251) as IColor;

            //创建并设置随机色谱从上面的的图可以看出我们要给每一个值定义一种颜色,我 们可以创建色谱,但是色谱的这些参数

            IRandomColorRamp pColorRamp = new RandomColorRampClass();

            pColorRamp.StartHue = 0;

            pColorRamp.MinValue = 20;

            pColorRamp.MinSaturation = 15;

            pColorRamp.EndHue = 360;

            pColorRamp.MaxValue = 100;

            pColorRamp.MaxSaturation = 30;
            pColorRamp.Size          = pCount;

            //pColorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool ok = true;

            pColorRamp.CreateRamp(out ok);
            IEnumColors pEnumRamp = pColorRamp.Colors;

            //IColor pColor = pEnumRamp.Next();

            int pIndex = pFt.Fields.FindField(pFieldName);

            //因为我只有24条记录,所以改变这些,这些都不会超过255或者为负数.求余

            int i = 0;

            while (pFt != null)

            {
                IColor pColor = pEnumRamp.Next();
                if (pColor == null)

                {
                    pEnumRamp.Reset();

                    pColor = pEnumRamp.Next();
                }

                //以下注释代码为自定义的两种颜色 ,如果不使用随机的颜色,可以采用这样的

                //if (i % 2 == 0)

                //{

                // pUnique.AddValue(Convert.ToString(pFt.get\_Value(pIndex)) , pFieldName, pFillSymbol1 as ISymbol);

                //}

                //else

                //{

                // pUnique.AddValue(Convert.ToString(pFt.get\_Value(pIndex)) , pFieldName, pFillSymbol2 as ISymbol);

                //}

                //i++;

                pFillSymbol1 = new SimpleFillSymbolClass();

                pFillSymbol1.Color = pColor;
                pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol1 as ISymbol);

                pFt = pFtCursor.NextFeature();

                // pColor = pEnumRamp.Next();
            }

            pGeoFeaturelayer.Renderer = pUnique as IFeatureRenderer;

            pMapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Example #33
0
        // 唯一值符号化
        public static void Symbology_UniqueValue(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            IUniqueValueRenderer pRenderer = new UniqueValueRendererClass()
            {
                FieldCount = 1
            };
            // 随机色带
            IColorRamp pColorRamp = new RandomColorRampClass()
            {
                StartHue = 0, MinSaturation = 0, MinValue = 0,
                EndHue   = 360, MaxSaturation = 100, MaxValue = 100,
                Size     = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass())
            };
            bool bOk = false;

            pColorRamp.CreateRamp(out bOk);
            IEnumColors  pColors      = pColorRamp.Colors;
            ITable       pTable       = featureLayer as ITable;
            int          fieldIndex   = pTable.FindField(fieldName);
            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.AddField(fieldName);
            ICursor pCursor = pTable.Search(pQueryFilter, true);
            IRow    pRow    = pCursor.NextRow();

            while (pRow != null)
            {
                IRowBuffer pRowBuffer = pRow as IRowBuffer;
                string     value      = pRowBuffer.get_Value(fieldIndex).ToString();
                IColor     pColor     = pColors.Next();
                ISymbol    pSymbol    = null;
                switch (featureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    pSymbol = new SimpleMarkerSymbolClass()
                    {
                        Color = pColor
                    };
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    pSymbol = new SimpleLineSymbolClass()
                    {
                        Color = pColor
                    };
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    pSymbol = new SimpleFillSymbolClass()
                    {
                        Color = pColor
                    };
                    break;
                }
                pRenderer.AddValue(value, "", pSymbol);
                pRow = pCursor.NextRow();
            }
            (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
            mapControl.Refresh();
            tocControl.Update();
        }
Example #34
0
        //Ϊդ��ͼ�����ݽ���Ψһֵ��ɫ
        public static IRasterLayer GetRLayerUniqueColor(IRaster pRaster, double dMaxDis)
        {
            try
            {
                IRasterBandCollection pBandCol = pRaster as IRasterBandCollection;
                IRasterBand pBand = pBandCol.Item(0) as IRasterBand;
                bool ExistTable;
                ITable pTable = null;
                pBand.HasTable(out ExistTable);
                if (ExistTable == false)
                {
                    pTable = pBand.AttributeTable as ITable;
                }

                int iNumOfValues = pTable.RowCount(null);
                string sFieldName = "Value";
                int iFieldIndex = pTable.FindField(sFieldName);
                IRandomColorRamp pRamp = new RandomColorRampClass();
                pRamp.Size = iNumOfValues;
                pRamp.Seed = 100;
                bool a = true;
                pRamp.CreateRamp(out a);
                IFillSymbol pFSymbol = new SimpleFillSymbolClass();
                IRasterUniqueValueRenderer pUVRen = new RasterUniqueValueRendererClass();
                IRasterRenderer pRasRen = pUVRen as IRasterRenderer;
                pRasRen.Raster = pRaster;
                pRasRen.Update();
                pUVRen.HeadingCount = 1;
                pUVRen.set_Heading(0, "�ȼ�");
                pUVRen.set_ClassCount(0, iNumOfValues);
                pUVRen.Field = sFieldName;
                //��ʼѭ��������ɫ
                double LabelValue;
                double s = Convert.ToDouble(dMaxDis / 5);
                IRgbColor pRGBColor = new RgbColorClass();

                for (int i = 0; i < iNumOfValues - 1; i++)
                {
                    IColor pColor = pRamp.get_Color(i);
                    IRow pRow = pTable.GetRow(i);
                    string sLabel = "";
                    LabelValue = Convert.ToDouble(pRow.get_Value(iFieldIndex));
                    if (LabelValue >= 0 || LabelValue <= s)
                    {
                        sLabel = "0" + "��" + s.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h1 = s * 2;
                    if (LabelValue >= s || LabelValue <= s * 2)
                    {
                        sLabel = s.ToString() + "��" + h1.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h2 = s * 3;
                    if (LabelValue >= s * 2 || LabelValue <= s * 3)
                    {
                        sLabel = h1.ToString() + "��" + h2.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h3 = s * 4;
                    if (LabelValue >= s * 3 || LabelValue <= s * 4)
                    {
                        sLabel = h2.ToString() + "��" + h3.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h4 = s * 5;
                    if (LabelValue >= s * 4 || LabelValue <= s * 5)
                    {
                        sLabel = h3.ToString() + "��" + h4.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    pUVRen.AddValue(0, i, LabelValue);
                    pUVRen.set_Label(0, i, sLabel);

                    pFSymbol.Color = pColor;
                    pUVRen.set_Symbol(0, i, pFSymbol as ISymbol);

                }
                pRasRen.Update();
                IRasterLayer pRLayer = new RasterLayerClass();
                pRLayer.CreateFromRaster(pRaster);
                pRLayer.Renderer = pUVRen as IRasterRenderer;
                return pRLayer;
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
Example #35
0
        /// <summary>
        /// 按聚类号对凸包进行渲染
        /// </summary>
        /// <param name="pGeoFeatureLayer"></param>
        /// <param name="fieldName"></param>
        public void DefinePolygonUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName)
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();

            //Create the color ramp for the symbols in the renderer.
            pRandomColorRamp.MinSaturation = 20;
            pRandomColorRamp.MaxSaturation = 40;
            pRandomColorRamp.MinValue      = 85;
            pRandomColorRamp.MaxValue      = 100;
            pRandomColorRamp.StartHue      = 76;
            pRandomColorRamp.EndHue        = 188;
            pRandomColorRamp.UseSeed       = true;
            pRandomColorRamp.Seed          = 43;

            //Create the renderer.
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();

            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();

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

            /*  ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
             * pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
             * pSimpleMarkerSymbol.Size = 5;
             * pSimpleMarkerSymbol.Outline = true;
             * IRgbColor pLineRgbColor = new RgbColorClass();
             * pLineRgbColor.Red = 0;
             * pLineRgbColor.Green = 0;
             * pLineRgbColor.Blue = 0;
             * pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor;
             */
            //These properties should be set prior to adding values.
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, fieldName);
            pUniqueValueRenderer.DefaultSymbol    = pSimpleFillSymbol as ISymbol;
            pUniqueValueRenderer.UseDefaultSymbol = true;

            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(fieldName);
            while (pFeature != null)
            {
                ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass();
                pClassSymbol.Style         = esriSimpleFillStyle.esriSFSSolid;
                pClassSymbol.Outline.Width = 0.4;

                /*    ISimpleMarkerSymbol pClassSymbol = new SimpleMarkerSymbolClass();
                 * pClassSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                 * pClassSymbol.Size = 5;
                 * pClassSymbol.Outline = true;
                 * pClassSymbol.OutlineColor = pLineRgbColor as IColor;
                 */
                string classValue;
                classValue = pFeature.get_Value(fieldIndex).ToString();

                //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, fieldName, 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.
            pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount;
            bool bOK;

            pRandomColorRamp.CreateRamp(out bOK);

            IEnumColors pEnumColors = pRandomColorRamp.Colors;

            pEnumColors.Reset();
            for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++)
            {
                string xv;
                xv = pUniqueValueRenderer.get_Value(j);
                if (xv != "")
                {
                    ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleFillSymbol;
                    pSimpleFillColor.Color = pEnumColors.Next();
                    pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol);
                }
            }
            pGeoFeatureLayer.Renderer     = (IFeatureRenderer)pUniqueValueRenderer;
            pGeoFeatureLayer.DisplayField = fieldName;
        }
Example #36
0
        private void RenderByUniqueValue(IFeatureLayer featureLayer, string fieldName)
        {
            string[] uniqueValues = GetUniqueValues(featureLayer, fieldName);

            if (uniqueValues != null)
            {
                IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass();

                uniqueValueRenderer.FieldCount = 1;

                uniqueValueRenderer.Field[0] = fieldName;

                IFeatureClass featureClass = featureLayer.FeatureClass;

                int n = featureClass.FindField(fieldName);

                IField field = featureClass.Fields.Field[n];

                if (field.Type == esriFieldType.esriFieldTypeString)
                {
                    // 如果实际字段值类型是字符串型

                    // 则 UniqueValueRenderer 组件对象的字段类型设置为 true

                    uniqueValueRenderer.set_FieldType(0, true);
                }
                else
                {
                    uniqueValueRenderer.set_FieldType(0, false);
                }

                IRandomColorRamp randomColorRamp = new RandomColorRampClass();

                randomColorRamp.StartHue = 30;

                randomColorRamp.EndHue = 50;

                randomColorRamp.MinSaturation = 20;

                randomColorRamp.MaxSaturation = 40;

                randomColorRamp.MinValue = 0;

                randomColorRamp.MaxValue = 100;

                randomColorRamp.Size = uniqueValues.Length;

                bool b;

                randomColorRamp.CreateRamp(out b);

                if (b)
                {
                    for (int i = 0; i < uniqueValues.Length; i++)
                    {
                        ISymbol symbol = null;

                        if (featureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            symbol = new SimpleFillSymbolClass();

                            (symbol as IFillSymbol).Outline.Width = 1.0;

                            (symbol as IFillSymbol).Color = randomColorRamp.get_Color(i);

                            uniqueValueRenderer.AddValue(uniqueValues[i], uniqueValues[i], symbol);
                        }
                        else if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            symbol = new SimpleLineSymbolClass();

                            (symbol as ILineSymbol).Width = 1.0;

                            (symbol as ILineSymbol).Color = randomColorRamp.get_Color(i);

                            uniqueValueRenderer.AddValue(uniqueValues[i], uniqueValues[i], symbol);
                        }
                    }
                }
                IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;

                if (geoFeatureLayer != null)
                {
                    geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer;

                    IActiveView activeView = axMapControl1.ActiveView;

                    activeView.ContentsChanged();

                    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                }
            }
        }
        public IFeatureRenderer UnqueValueRenderer(IFeatureWorkspace workspace, IFeatureClass fc)
        {
            try
            {
                string tablename = ((IDataset)fc).BrowseName;
                ITable ipTable = workspace.OpenTable(tablename);

                IFeatureCursor featureCursor = fc.Search(null, false);
                IDataStatistics dataStatistics = new DataStatisticsClass();
                dataStatistics.Cursor = featureCursor as ICursor;
                dataStatistics.Field = "gridcode";

                System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues;
                enumerator.Reset();

                while (enumerator.MoveNext())
                {
                    object myObject = enumerator.Current;
                }

                int uniqueValues = dataStatistics.UniqueValueCount;

                //Create colors for each unique value.
                IRandomColorRamp colorRamp = new RandomColorRampClass();
                colorRamp.Size = uniqueValues;
                colorRamp.Seed = 100;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);
                if (createColorRamp == false)
                {
                    return null;
                }

                IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass();
                IFeatureRenderer featRenderer = (IFeatureRenderer)uvRenderer;

                uvRenderer.FieldCount = 1;

                ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
                ISimpleFillSymbol fillSymbol2 = new SimpleFillSymbolClass();
                if (ShowNonVisibleData == true)
                {
                    fillSymbol.Color = new RgbColorClass() { Red = 255 } as IColor;
                    uvRenderer.AddValue("0", "", fillSymbol as ISymbol);
                    uvRenderer.set_Label("0", "Non-Visible");
                }
                    fillSymbol2.Color = new RgbColorClass() { Green = 255 } as IColor;
                    uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol);
                    uvRenderer.set_Label("1", "Visible by 1 Observer");

                    int field = ipTable.FindField("gridcode");
                    uvRenderer.set_Field(0, "gridcode");

                    for (int i = 2; i < uniqueValues; i++)
                    {
                        ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass();
                        newFillSymbol.Color = colorRamp.get_Color(i);
                        uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol);
                        string label = "Visible by " + i.ToString() + " Observers";
                        uvRenderer.set_Label(i.ToString(), label);
                    }

                return featRenderer;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return null;
            }
        }