public void LayerRender() { try { //IFeatureLayer pFeatureLayer = featLayer; 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(); IClone pSourceClone = pSimFillSymbol as IClone; ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol; string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString(); pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol); } //为每个符号设置颜色 for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { string xv = pUniqueValueRenderer.get_Value(i); if (xv != "") { ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv); pNextSymbol.Color = colorRamp.get_Color(i * (colorRamp.Size / pUniqueValueRenderer.ValueCount)); pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol); if (xv.Contains(".")) { pUniqueValueRenderer.set_Label(xv, xv.Substring(0, xv.IndexOf(".") + 4)); } else { pUniqueValueRenderer.set_Label(xv, xv); } } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); axtoccontrol.Update(); } catch (Exception e) { MessageBox.Show(e.Message); } }
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; }
private IUniqueValueRenderer CreateTrackUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 0; color.Blue = 0; color.Green = 255; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)simpleLineSymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) { return(uniqueRenderer); } while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) { bValFound = true; } } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)simpleLineSymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return(uniqueRenderer); }
private IUniqueValueRenderer CreateUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 255; color.Blue = 0; color.Green = 0; ICharacterMarkerSymbol charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 12.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = 96; charMarkersymbol.Size = 12.0; charMarkersymbol.Color = (IColor)color; IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.MinSaturation = 20; randomColorRamp.MaxSaturation = 40; randomColorRamp.MaxValue = 85; randomColorRamp.MaxValue = 100; randomColorRamp.StartHue = 75; randomColorRamp.EndHue = 190; randomColorRamp.UseSeed = true; randomColorRamp.Seed = 45; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)charMarkersymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) { return(uniqueRenderer); } while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) { bValFound = true; } } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 10.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = rand.Next(40, 118); charMarkersymbol.Size = 20.0; charMarkersymbol.Color = (IColor)color; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)charMarkersymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return(uniqueRenderer); }
private IUniqueValueRenderer CreateTrackUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 0; color.Blue = 0; color.Green = 255; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)simpleLineSymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) return uniqueRenderer; while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) bValFound = true; } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)simpleLineSymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return uniqueRenderer; }
private IUniqueValueRenderer CreateUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 255; color.Blue = 0; color.Green = 0; ICharacterMarkerSymbol charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 12.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = 96; charMarkersymbol.Size = 12.0; charMarkersymbol.Color = (IColor)color; IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.MinSaturation = 20; randomColorRamp.MaxSaturation = 40; randomColorRamp.MaxValue = 85; randomColorRamp.MaxValue = 100; randomColorRamp.StartHue = 75; randomColorRamp.EndHue = 190; randomColorRamp.UseSeed = true; randomColorRamp.Seed = 45; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)charMarkersymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) return uniqueRenderer; while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) bValFound = true; } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 10.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = rand.Next(40, 118); charMarkersymbol.Size = 20.0; charMarkersymbol.Color = (IColor)color; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)charMarkersymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return uniqueRenderer; }
/// <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; }
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; }
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; }
/// <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; }