//yjl20110826 add private ISymbol[] CreateSymbols(int count) { IColorRamp pColorRamp = (cmbColorRamp.SelectedItem as DevComponents.Editors.ComboItem).Tag as IColorRamp; bool bCreateRamp; pColorRamp.Size = count <= 1 ? 2 : count; pColorRamp.CreateRamp(out bCreateRamp); IEnumColors enumColors = pColorRamp.Colors; enumColors.Reset(); ESRI.ArcGIS.esriSystem.IObjectCopy copy = new ESRI.ArcGIS.esriSystem.ObjectCopyClass(); ISymbol[] symbols = new ISymbol[count]; ISymbol tmpSymbol = ModuleCommon.CreateSymbol(m_SymbologyStyleClass); for (int i = 0; i < count; i++) { symbols[i] = copy.Copy(tmpSymbol) as ISymbol; IColor pColor = enumColors.Next(); if (pColor == null) { enumColors.Reset(); enumColors.Next(); } ModuleCommon.ChangeSymbolColor(symbols[i], pColor); } return(symbols); }
/*不同渲染方式 * */ ///<summary> ///设置要素图层唯一值符号化 ///</summary> ///<param name="pFeatureLayer">特征层</param> private void UniqueValueRenderFlyr() { IGeoFeatureLayer geoFeatureLayer = null; geoFeatureLayer = getGeoLayer("Continents"); IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.set_Field(0, "SQMI"); ISimpleFillSymbol simpleFillSymbol = SymbolWorker.CreateSimpleFillSymbol() as ISimpleFillSymbol; IFeatureCursor featureCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature feature; if (featureCursor != null) { IEnumColors enumColors = SymbolWorker.CreateAlgorithmicColorRamp(8).Colors; IColor dullColor = enumColors.Next(); int fiedIndex = geoFeatureLayer.FeatureClass.Fields.FindField("SQMI"); for (int i = 0; i < 7; i++) { feature = featureCursor.NextFeature(); string nameValue = feature.get_Value(fiedIndex).ToString(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); uniqueValueRenderer.AddValue(nameValue, "SQMI", simpleFillSymbol as ISymbol); } } geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; }
private ISymbol[] CreateSymbols() { IColorRamp pColorRamp = (cmbColorRamp.SelectedItem as DevComponents.Editors.ComboItem).Tag as IColorRamp; bool bCreateRamp; pColorRamp.Size = levelInput.Value <= 1 ? 2 : levelInput.Value; pColorRamp.CreateRamp(out bCreateRamp); IEnumColors enumColors = pColorRamp.Colors; enumColors.Reset(); ISymbol[] symbols = new ISymbol[levelInput.Value]; ESRI.ArcGIS.esriSystem.IObjectCopy copy = new ESRI.ArcGIS.esriSystem.ObjectCopyClass(); for (int i = 0; i < levelInput.Value; i++) { symbols[i] = copy.Copy(labelPreviewFore.Tag) as ISymbol; IColor pColor = enumColors.Next(); if (pColor == null) { enumColors.Reset(); enumColors.Next(); } ModuleCommon.ChangeSymbolColor(symbols[i], pColor); } return(symbols); }
private void RefreshColorRamp() {//刷新符号颜色 if (flag) { return; } IColorRamp pColorRamp = (cmbColorRamp.SelectedItem as DevComponents.Editors.ComboItem).Tag as IColorRamp; bool bCreateRamp; pColorRamp.Size = levelInput.Value <= 1 ? 2 : levelInput.Value; pColorRamp.CreateRamp(out bCreateRamp); IEnumColors enumColors = pColorRamp.Colors; enumColors.Reset(); listValueItem.SmallImageList.Images.Clear(); for (int i = 0; i < listValueItem.Items.Count; i++) { IColor pColor = enumColors.Next(); if (pColor == null) { enumColors.Reset(); enumColors.Next(); } System.Windows.Forms.ListViewItem item = listValueItem.Items[i]; ModuleCommon.ChangeSymbolColor(item.Tag as ISymbol, pColor); listValueItem.SmallImageList.Images.Add(item.Name.Replace("Item", "Symbol"), ModuleCommon.Symbol2Picture(item.Tag as ISymbol, ModuleCommon.ImageWidth, ModuleCommon.ImageHeight)); listValueItem.Items[i].ImageKey = item.Name.Replace("Item", "Symbol"); } }
private void button4_Click(object sender, EventArgs e) { int selectedFieldIndex = m_pTarFeatureLayer.FeatureClass.Fields.FindField(comboBox1.SelectedItem.ToString()); IField selectedField = m_pTarFeatureLayer.FeatureClass.Fields.get_Field(selectedFieldIndex); IUniqueValueRenderer unqValueRenderr = new UniqueValueRendererClass(); #region UniqueValueRenderer需要定义字段数,字段名,并最后添加字段中每一种值对应的渲染方式(AddValue) unqValueRenderr.FieldCount = 1; unqValueRenderr.set_Field(0, selectedField.Name);//0是干什么的? #endregion IAlgorithmicColorRamp acr = new AlgorithmicColorRampClass(); acr.FromColor = m_pFillColor; acr.ToColor = m_pOutlineColor; acr.Size = m_pTarFeatureLayer.FeatureClass.FeatureCount(null); bool isOK; acr.CreateRamp(out isOK); #region 很迷,不知道为什么直接acr.colors.next遍历不了colorramp IEnumColors enumColor = acr.Colors; IColor curColor = enumColor.Next(); #endregion #region 开始遍历图层获取所有feature for (int i = 0; i < m_pTarFeatureLayer.FeatureClass.FeatureCount(null); i++) { IFeature curFeature = m_pTarFeatureLayer.FeatureClass.GetFeature(i); switch (m_pTarFeatureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: { ISimpleFillSymbol sfs = new SimpleFillSymbolClass(); sfs.Color = curColor; unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sfs as ISymbol); break; } case esriGeometryType.esriGeometryPoint: { ISimpleMarkerSymbol sms = new SimpleMarkerSymbolClass { Color = curColor }; unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sms as ISymbol); break; } case esriGeometryType.esriGeometryPolyline: { ISimpleLineSymbol sls = new SimpleLineSymbolClass(); sls.Color = curColor; unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sls as ISymbol); break; } } curColor = enumColor.Next(); } m_pTarGeoFeatureLayer.Renderer = unqValueRenderr as IFeatureRenderer; frmMainOper(OperationType.RefreshMapCtrl); frmMainOper(OperationType.UpdateTOCCtrl); #endregion }
private void LooRGBColors() { // // Move to the required Color to show. We only have space to show ten colors // at a time on the form. So when we wish to show the next ten colors, // (colors 11-20, 21-30 etc) we iterate the colors enumeration appropriately. // int lngMoveNext = 0; m_enumNewColors.Reset(); while (lngMoveNext < m_lngColors) { m_enumNewColors.Next(); lngMoveNext = lngMoveNext + 1; } // // Show colors in textboxes as necessary. // IColor colNew = null; int lngCount = 0; for (lngCount = 0; lngCount <= 9; lngCount++) { //commented the control array txtColor - OLD //With txtColor(lngCount) // colNew = m_enumNewColors.Next // ' // ' If getting the next color returns nothing, we have got to // ' the end of the colors enumeration. // ' // If colNew Is Nothing Then // Exit For // End If // .BackColor = System.Drawing.ColorTranslator.FromOle(colNew.RGB) // .Visible = True //End With colNew = m_enumNewColors.Next(); // // If getting the next color returns nothing, we have got to // the end of the colors enumeration. // if (colNew == null) break; TextBoxColors[lngCount].BackColor = System.Drawing.ColorTranslator.FromOle(colNew.RGB); TextBoxColors[lngCount].Visible = true; //Commented the control array lblIndex - OLD //With lblIndex(lngCount) // .Text = CStr(lngCount + m_lngColors) // .Visible = True //End With //LabelsIndex[lngCount].Text = System.Convert().ToString(lngCount + m_lngColors); LabelsIndex[lngCount].Text = Convert.ToString (lngCount+m_lngColors); LabelsIndex[lngCount].Visible = true; } }
public void CategoryUniqueValues(IGeoFeatureLayer geoLayer, string aFieldName) { IUniqueValueRenderer MyIUniqueValueRenderer; MyIUniqueValueRenderer = new UniqueValueRenderer(); MyIUniqueValueRenderer.FieldCount = 1; MyIUniqueValueRenderer.set_Field(0, aFieldName); int intFieldIndex; intFieldIndex = geoLayer.FeatureClass.FindField(aFieldName); IFeatureCursor MyIFeatureCursor; IQueryFilter MyQueryFilter; MyQueryFilter = new QueryFilter(); MyQueryFilter.SubFields = aFieldName; MyIFeatureCursor = geoLayer.FeatureClass.Search(MyQueryFilter, true); IRandomColorRamp MyIRandomColorRamp; MyIRandomColorRamp = new RandomColorRamp(); MyIRandomColorRamp.Size = 16; bool CheckColors; MyIRandomColorRamp.CreateRamp(out CheckColors); if (!CheckColors) { return; } IEnumColors MyIEnumColors = MyIRandomColorRamp.Colors; ISimpleMarkerSymbol MyISimpleMarkerSymbol; IColor MyIColor; IFeature MyIFeature; MyIFeature = MyIFeatureCursor.NextFeature(); while (MyIFeature != null) { MyISimpleMarkerSymbol = new SimpleMarkerSymbolClass(); MyIColor = MyIEnumColors.Next(); if ((MyIColor == null)) { MyIEnumColors.Reset(); MyIColor = MyIEnumColors.Next(); } MyISimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCross; MyISimpleMarkerSymbol.Color = MyIColor; MyISimpleMarkerSymbol.Size = 22; MyIUniqueValueRenderer.AddValue(MyIFeature.get_Value(intFieldIndex).ToString(), "", ((ISymbol)(MyISimpleMarkerSymbol))); MyIFeature = MyIFeatureCursor.NextFeature(); } geoLayer.Renderer = MyIUniqueValueRenderer as IFeatureRenderer; axMapControl1.ActiveView.Refresh(); }
/// <summary> /// 枚举颜色变为列表 /// </summary> /// <param name="pEnumColor"></param> /// <returns></returns> private static List <IColor> EnumColorsToList(IEnumColors pEnumColor) { pEnumColor.Reset(); List <IColor> aeColors = new List <IColor>(); IColor color = pEnumColor.Next(); while (color != null) { aeColors.Add(color); color = pEnumColor.Next(); } return(aeColors); }
private void iRandomColorRampToolStripMenuItem_Click(object sender, EventArgs e) { IMap mmap = axMapControl1.Map; IActiveView pActiveView = mmap as IActiveView; IGeometry pLine = axMapControl1.TrackLine(); ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); IEnumColors pEnumColors = CreateRdmColorRamp(140, 220, 35, 100, 32, 80, 12, 7); IColor pColor = pEnumColors.Next(); pLineSymbol.Color = pColor; pLineSymbol.Width = 2; pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; IElement element = new LineElementClass(); element.Geometry = pLine; ILineElement pLineElement = element as ILineElement; pLineElement.Symbol = pLineSymbol; IGraphicsContainer ppGraphicsContainer = mmap as IGraphicsContainer; ppGraphicsContainer.AddElement(pLineElement as IElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
//单一值专题图 private void button3_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer("Continents"); IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.set_Field(0, "continent"); //简单填充符号 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; IFeatureCursor featureCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature feature; if (featureCursor != null) { IEnumColors enumColors = CreateAlgorithmicColorRamp(8).Colors; int fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField("continent"); for (int i = 0; i < 8; i++) { feature = featureCursor.NextFeature(); string nameValue = feature.get_Value(fieldIndex).ToString(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); uniqueValueRenderer.AddValue(nameValue, "continent", simpleFillSymbol as ISymbol); } } geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }
//分级专题图 private void button2_Click(object sender, EventArgs e) { int classCount = 6; ITableHistogram tableHistogram; IBasicHistogram basicHistogram; ITable table; IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer("Continents"); ILayer layer = geoFeatureLayer as ILayer; table = layer as ITable; tableHistogram = new BasicTableHistogramClass(); //按照 数值字段分级 tableHistogram.Table = table; tableHistogram.Field = "sqmi"; basicHistogram = tableHistogram as IBasicHistogram; object values; object frequencys; //先统计每个值和各个值出现的次数 basicHistogram.GetHistogram(out values, out frequencys); //创建平均分级对象 IClassifyGEN classifyGEN = new QuantileClass(); //用统计结果进行分级 ,级别数目为classCount classifyGEN.Classify(values, frequencys, ref classCount); //获得分级结果,是个 双精度类型数组 double[] classes; classes = classifyGEN.ClassBreaks as double[]; IEnumColors enumColors = CreateAlgorithmicColorRamp(classes.Length).Colors; IColor color; IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass(); classBreaksRenderer.Field = "sqmi"; classBreaksRenderer.BreakCount = classCount; classBreaksRenderer.SortClassesAscending = true; ISimpleFillSymbol simpleFillSymbol; for (int i = 0; i < classes.Length - 1; i++) { color = enumColors.Next(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; classBreaksRenderer.set_Symbol(i, simpleFillSymbol as ISymbol); classBreaksRenderer.set_Break(i, classes[i]); } if (geoFeatureLayer != null) { geoFeatureLayer.Renderer = classBreaksRenderer as IFeatureRenderer; } this.axMapControl1.ActiveView.Refresh(); }
/// <summary> /// 栅格分级渲染(注意选中字段唯一值个数不能小于设置的唯一值个数) /// </summary> /// <param name="rasterClassRenderer">分级渲染设置</param> /// <param name="pStyleGalleryItem">颜色带样式</param> public void ClassRenderer(IRasterClassifyColorRampRenderer rasterClassRenderer, IStyleGalleryItem pStyleGalleryItem) { if (pStyleGalleryItem == null) { MessageBox.Show(@"Color ramp cannot be empty"); return; } IRasterRenderer rasterRend = (IRasterRenderer)rasterClassRenderer; rasterRend.Raster = rasterLayer.Raster; rasterRend.Update(); IEnumColors enumColors = RenderHelper.GetColorRamp(pStyleGalleryItem, rasterClassRenderer.ClassCount).Colors; enumColors.Reset(); IFillSymbol fillSymbol = new SimpleFillSymbolClass(); for (int i = 0; i < rasterClassRenderer.ClassCount; i++) { fillSymbol.Color = enumColors.Next(); rasterClassRenderer.set_Symbol(i, (ISymbol)fillSymbol); string label = Math.Round(rasterClassRenderer.Break[i], 2) + "-" + Math.Round(rasterClassRenderer.Break[i + 1], 2); rasterClassRenderer.set_Label(i, label); } rasterLayer.Renderer = rasterRend; }
//................................................. //................................................. //................................................. private void AssignColorRamp(string fieldname, List <RiskRankingRange> pRiskRankingRanges) { // Get Statistics Values for the Selected Field GetRankingStatistics(fieldname); if (_minriskvalue >= _maxriskvalue) { return; } if (pRiskRankingRanges.Count == 0) { return; } if (m_styleGalleryItem == null) { return; } if (m_featureLayer == null) { return; } m_classBreaksRenderer.Field = fieldname; m_classBreaksRenderer.BreakCount = pRiskRankingRanges.Count; m_classBreaksRenderer.MinimumBreak = 0; //Calculate the class interval by a simple mean value double interval = (_maxriskvalue - _minriskvalue) / pRiskRankingRanges.Count; //Get the color ramp IColorRamp colorRamp = (IColorRamp)m_styleGalleryItem.Item; //Set the size of the color ramp and recreate it colorRamp.Size = Convert.ToInt32(pRiskRankingRanges.Count); bool createRamp; colorRamp.CreateRamp(out createRamp); //Get the enumeration of colors from the color ramp IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); double currentBreak = m_classBreaksRenderer.MinimumBreak; ISimpleLineSymbol simpleLineSymbol; //Loop through each class break for (int i = 0; i <= pRiskRankingRanges.Count - 1; i++) { //Set class break m_classBreaksRenderer.set_Break(i, currentBreak); //Create simple fill symbol and set color simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = enumColors.Next(); //Add symbol to renderer m_classBreaksRenderer.set_Symbol(i, (ISymbol)simpleLineSymbol); currentBreak += interval; } }
private void setColor(IGeoFeatureLayer IGFL) { int classCount = 10; ITableHistogram tableHistogram; IBasicHistogram basicHistogram; ITable table; IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = IGFL; ILayer layer = geoFeatureLayer as ILayer; table = layer as ITable; tableHistogram = new BasicTableHistogramClass(); tableHistogram.Table = table; tableHistogram.Field = "HighTemperature"; basicHistogram = tableHistogram as IBasicHistogram; object values; object frequencys; basicHistogram.GetHistogram(out values, out frequencys); IClassifyGEN classifyGEN = new QuantileClass(); classifyGEN.Classify(values, frequencys, ref classCount); double[] classes; classes = classifyGEN.ClassBreaks as double[]; IEnumColors enumColors = CreateAlgorithmicColorRamp(classes.Length).Colors; IColor color; IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass(); classBreaksRenderer.Field = "HighTemperature"; classBreaksRenderer.BreakCount = classCount + 1; classBreaksRenderer.SortClassesAscending = true; ISimpleFillSymbol simpleFillSymbol; for (int i = 0; i < classes.Length; i++) { color = enumColors.Next(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; classBreaksRenderer.set_Symbol(i, simpleFillSymbol as ISymbol); classBreaksRenderer.set_Break(i, classes[i]); } if (geoFeatureLayer != null) { geoFeatureLayer.Renderer = classBreaksRenderer as IFeatureRenderer; } axMapControl1.ActiveView.Refresh(); }
private void mnuClassBreak_Click(object sender, EventArgs e) { ILayer pLayer = MainMap.get_Layer(0); ITable pTable = pLayer as ITable; IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer; int classCount = 6; ITableHistogram pTableHistogram; IBasicHistogram pBasicHistogram; pTableHistogram = new BasicTableHistogramClass(); //按照 数值字段分级 pTableHistogram.Table = pTable; pTableHistogram.Field = "AREA"; pBasicHistogram = pTableHistogram as IBasicHistogram; object values; object frequencys; //先统计每个值和各个值出现的次数 pBasicHistogram.GetHistogram(out values, out frequencys); //创建等间距分级对象 IClassifyGEN classifyGEN = new EqualIntervalClass(); //用统计结果进行分级 ,级别数目为classCount classifyGEN.Classify(values, frequencys, ref classCount); //获得分级结果,是个 双精度类型数组 double[] classes; classes = classifyGEN.ClassBreaks as double[]; IEnumColors enumColors = CreateAlgorithmicColorRamp(classes.Length).Colors; IColor pColor; IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = "AREA"; pClassBreaksRenderer.BreakCount = classCount; pClassBreaksRenderer.SortClassesAscending = true; ISimpleFillSymbol simpleFillSymbol; for (int i = 0; i < classes.Length - 1; i++) { pColor = enumColors.Next(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = pColor; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassBreaksRenderer.set_Symbol(i, simpleFillSymbol as ISymbol); pClassBreaksRenderer.set_Break(i, classes[i + 1]); } pGeoFeatureLayer.Renderer = pClassBreaksRenderer as IFeatureRenderer; MainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
private void cboColorRamp_SelectedIndexChanged(object sender, EventArgs e) { if (this.bool_0) { this.icolorRamp_0 = this.cboColorRamp.GetSelectStyleGalleryItem().Item as IColorRamp; (this.irasterClassifyColorRampRenderer_0 as IRasterClassifyUIProperties).ColorRamp = this.cboColorRamp.Text; if (this.irasterClassifyColorRampRenderer_0.ClassCount > 0) { bool flag; this.icolorRamp_0.Size = this.irasterClassifyColorRampRenderer_0.ClassCount; this.icolorRamp_0.CreateRamp(out flag); IEnumColors colors = this.icolorRamp_0.Colors; colors.Reset(); this.listView1.BeginUpdate(); for (int i = 0; i < this.irasterClassifyColorRampRenderer_0.ClassCount; i++) { ISymbol symbol = this.irasterClassifyColorRampRenderer_0.get_Symbol(i); if (symbol is IMarkerSymbol) { (symbol as IMarkerSymbol).Color = colors.Next(); } else if (symbol is ILineSymbol) { (symbol as ILineSymbol).Color = colors.Next(); } else if (symbol is IFillSymbol) { (symbol as IFillSymbol).Color = colors.Next(); } this.irasterClassifyColorRampRenderer_0.set_Symbol(i, symbol); if (this.listView1.Items[i] is ListViewItemEx) { (this.listView1.Items[i] as ListViewItemEx).Style = symbol; } this.listView1.Items[i].Tag = symbol; } this.listView1.EndUpdate(); this.listView1.Invalidate(); } } }
private void method_4(IColorRamp icolorRamp_1, IRasterClassifyColorRampRenderer irasterClassifyColorRampRenderer_1, int int_0, ITable itable_0, string string_0, string string_1) { try { bool flag; if (string_0.Length > 0) { irasterClassifyColorRampRenderer_1.ClassField = string_0; } if (string_1.Length > 0) { irasterClassifyColorRampRenderer_1.NormField = string_1; } IRasterRenderer renderer = (IRasterRenderer)irasterClassifyColorRampRenderer_1; renderer.Raster = this.irasterLayer_0.Raster; irasterClassifyColorRampRenderer_1.ClassCount = int_0; renderer.Update(); this.bool_0 = false; this.cboClassifyNum.SelectedIndex = irasterClassifyColorRampRenderer_1.ClassCount - 1; this.bool_0 = true; icolorRamp_1.Size = irasterClassifyColorRampRenderer_1.ClassCount; icolorRamp_1.CreateRamp(out flag); IEnumColors colors = icolorRamp_1.Colors; ISymbol symbol = null; for (int i = 0; i < irasterClassifyColorRampRenderer_1.ClassCount; i++) { string str; IColor color = colors.Next(); ISimpleFillSymbol symbol2 = new SimpleFillSymbolClass { Color = color, Style = esriSimpleFillStyle.esriSFSSolid }; symbol = symbol2 as ISymbol; irasterClassifyColorRampRenderer_1.set_Symbol(i, symbol); if (i == (irasterClassifyColorRampRenderer_1.ClassCount - 1)) { str = irasterClassifyColorRampRenderer_1.get_Break(i).ToString("0.####"); } else { str = irasterClassifyColorRampRenderer_1.get_Break(i).ToString("0.####") + " - " + irasterClassifyColorRampRenderer_1.get_Break(i + 1).ToString("0.####"); } irasterClassifyColorRampRenderer_1.set_Label(i, str); } } catch (Exception exception) { Logger.Current.Error("", exception, ""); } }
/// <summary> /// 获取符号颜色数组 /// </summary> /// <param name="ColorRamp"></param> /// <returns></returns> public static IList <string> GimmeArrayListForColorRamp(IColorRamp ColorRamp) { IEnumColors EColors = ColorRamp.Colors; IList <string> AL = new List <string>(); for (int i = 0; i <= ColorRamp.Size - 1; i++) { AL.Add(GimmeStringForColor(EColors.Next())); } return(AL); }
private void colorRampComboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (this.bool_0) { this.icolorRamp_0 = this.colorRampComboBox1.GetSelectColorRamp(); (this.iclassBreaksRenderer_0 as IClassBreaksUIProperties).ColorRamp = this.colorRampComboBox1.Text; if (this.iclassBreaksRenderer_0.BreakCount > 0) { bool flag; this.icolorRamp_0.Size = this.iclassBreaksRenderer_0.BreakCount; this.icolorRamp_0.CreateRamp(out flag); IEnumColors colors = this.icolorRamp_0.Colors; colors.Reset(); this.listView1.BeginUpdate(); for (int i = 0; i < this.iclassBreaksRenderer_0.BreakCount; i++) { ISymbol sym = this.iclassBreaksRenderer_0.get_Symbol(i); if (sym is IMarkerSymbol) { (sym as IMarkerSymbol).Color = colors.Next(); } else if (sym is ILineSymbol) { (sym as ILineSymbol).Color = colors.Next(); } else if (sym is IFillSymbol) { (sym as IFillSymbol).Color = colors.Next(); } this.iclassBreaksRenderer_0.set_Symbol(i, sym); if (this.listView1.Items[i] is ListViewItemEx) { (this.listView1.Items[i] as ListViewItemEx).Style = sym; } this.listView1.Items[i].Tag = sym; } this.listView1.EndUpdate(); this.listView1.Invalidate(); } } }
private int[,] RedToBlueColorRamps() { IEnumColors pEnumColors = null; int[,] arrSepLineColor = new int[10, 3]; IAlgorithmicColorRamp pColorRamp1 = new AlgorithmicColorRampClass(); IAlgorithmicColorRamp pColorRamp2 = new AlgorithmicColorRampClass(); pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; IRgbColor pColor1 = new RgbColor(); IRgbColor pColor2 = new RgbColor(); IRgbColor pColor3 = new RgbColor(); pColor1 = pSnippet.getRGB(165, 0, 38); pColor2 = pSnippet.getRGB(255, 255, 191); pColor3 = pSnippet.getRGB(49, 54, 149); pColorRamp1.FromColor = pColor1; pColorRamp1.ToColor = pColor2; pColorRamp2.FromColor = pColor2; pColorRamp2.ToColor = pColor3; Boolean blnOK = true; IMultiPartColorRamp pMultiColorRamp = new MultiPartColorRampClass(); pMultiColorRamp.Ramp[0] = pColorRamp1; pMultiColorRamp.Ramp[1] = pColorRamp2; pMultiColorRamp.Size = 10; pMultiColorRamp.CreateRamp(out blnOK); pEnumColors = pMultiColorRamp.Colors; pEnumColors.Reset(); for (int k = 0; k < 10; k++) { IColor pColor = pEnumColors.Next(); IRgbColor pRGBColor = new RgbColorClass(); pRGBColor.RGB = pColor.RGB; arrSepLineColor[k, 0] = pRGBColor.Red; arrSepLineColor[k, 1] = pRGBColor.Green; arrSepLineColor[k, 2] = pRGBColor.Blue; } return(arrSepLineColor); }
public IUniqueValueRenderer MakeUniqueValueRenderer() { IFeatureLayer data = (this.cboLayers.SelectedItem as LayerObject).Layer as IFeatureLayer; IUniqueValueRenderer renderer = new UniqueValueRendererClass(); ISymbol symbol = this.method_3(data.FeatureClass.ShapeType); if (symbol != null) { renderer.FieldCount = 1; renderer.set_Field(0, this.cboFields.Text); renderer.DefaultLabel = "默认符号"; renderer.DefaultSymbol = symbol; renderer.UseDefaultSymbol = true; try { bool flag; string str = this.method_4(data.FeatureClass.ShapeType); this.icolorRamp_0.Size = this.listView1.Items.Count; this.icolorRamp_0.CreateRamp(out flag); IEnumColors colors = this.icolorRamp_0.Colors; colors.Reset(); for (int i = 0; i < this.listView1.Items.Count; i++) { ISymbol symbol2; ListViewItem item = this.listView1.Items[i]; IStyleGalleryItem item2 = SymbolFind.FindStyleGalleryItem(item.SubItems[0].Text, this.m_pSG, this.cboStyleGrally.Text, str, ""); if (item2 == null) { IColor color = colors.Next(); symbol2 = (symbol as IClone).Clone() as ISymbol; this.method_2(symbol2, color); } else { symbol2 = (item2.Item as IClone).Clone() as ISymbol; } renderer.AddValue(item.SubItems[0].Text, null, symbol2); } (data as IGeoFeatureLayer).Renderer = renderer as IFeatureRenderer; (this.imap_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, data, null); return(renderer); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } } return(renderer); }
private void btn_OK_Click(object sender, EventArgs e) { string FieldName = cbx_Field.SelectedItem.ToString(); IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; pGeoFeatureLayer.ScaleSymbols = false; ITable pTable = (ITable)pGeoFeatureLayer; if (pTable.FindField(FieldName) == -1) { return; } else { IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, FieldName); IColorRamp pColorRamp = (IColorRamp)m_StyleGallertItem.Item; pColorRamp.Size = pTable.RowCount(null); bool ok = true; pColorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = pColorRamp.Colors; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(FieldName); //依据某个字段在表中找出指向所有行的游标对象 ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pNextRow = pCursor.NextRow(); //遍历所有的要素 IColor pNextUniqueColor; string codeValue; while (pNextRow != null) { codeValue = pNextRow.get_Value(pTable.FindField(FieldName)).ToString(); //获得随机颜色带中的任意一种颜色 pNextUniqueColor = pEnumRamp.Next(); IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pNextUniqueColor; //将每次得到的要素字段值和修饰它的符号放入着色对象中 pUniqueValueRenderer.AddValue(codeValue, FieldName, (ISymbol)pFillSymbol); pNextRow = pCursor.NextRow(); } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } }
/// <summary> /// 唯一值法渲染器(UniqueValueRender)——根据特征的某不同属性值来绘制该特征的符号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 唯一值法渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //定义IGeoFeatureLayer变量, 提供一个要素图层对成员控制地理特征的入口 IGeoFeatureLayer geoFeatureLayer = getGeoLayer("北部湾"); //使用查询的方式, 获得参与渲染的记录条数 int get_Count = geoFeatureLayer.FeatureClass.FeatureCount(null); //提供操作唯一值的相关成员 IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); //设置渲染的字段个数范围:0~3个 //这里仅设置1个字段 uniqueValueRenderer.FieldCount = 1; //设置渲染字段, 并制定到索引处 //索引从0开始; 设定渲染字段为"地市名" uniqueValueRenderer.set_Field(0, "地市名"); //简单填充符号 ISimpleFillSymbol simpleFillSymbol; //获得指向渲染要素的游标 IFeatureCursor pFtCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature pFeature; if (pFtCursor != null) { //定义枚举颜色带, 调用函数, 生成随机颜色带 IEnumColors enumColors = CreateRandomColorRamp(get_Count).Colors; //查找到"地市名"字段的索引(index) int fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField("地市名"); while ((pFeature = pFtCursor.NextFeature()) != null) { //获取要素值 string nameValue = pFeature.get_Value(fieldIndex).ToString(); //实例化填充符号 //使用填充符号来赋值地图的背景值 simpleFillSymbol = new SimpleFillSymbolClass(); //给要素附上样式 simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; //给要素附上颜色 simpleFillSymbol.Color = enumColors.Next() as IColor; //值和符号对应 uniqueValueRenderer.AddValue(nameValue, "地市", simpleFillSymbol as ISymbol); } } //赋值目标图层的渲染器属性 geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; axMapControl1.Refresh(); //刷新axMapControl1 axTOCControl1.Update(); //更新axTOCControl1 }
public void DrawSymbolinListViewwithCb(int intGCBreakeCount, double[] cb) { try { if (cb == null) { return; } strClassificationMethod = "Breaks maximum " + cboMethod.Text + " between Observations"; pRender = new ClassBreaksRenderer(); pRender.Field = cboValueField.Text; pRender.BreakCount = intGCBreakeCount; pRender.MinimumBreak = cb[0]; string strColorRamp = cboColorRamp.Text; pEnumColors = MultiPartColorRamp(strColorRamp, cboAlgorithm.Text, intGCBreakeCount); pEnumColors.Reset(); arrColors = new int[intGCBreakeCount, 3]; for (int k = 0; k < intGCBreakeCount; k++) { IColor pColor = pEnumColors.Next(); IRgbColor pRGBColor = new RgbColorClass(); pRGBColor.RGB = pColor.RGB; arrColors[k, 0] = pRGBColor.Red; arrColors[k, 1] = pRGBColor.Green; arrColors[k, 2] = pRGBColor.Blue; } pEnumColors.Reset(); UpdateRange(lvSymbol, intGCBreakeCount); } catch (Exception ex) { MessageBox.Show(this.Handle.ToString() + " Error:" + ex.Message); return; } }
private void button2_Click(object sender, System.EventArgs e) { //Create a new ClassBreaksRenderer and set properties m_classBreaksRenderer = new ClassBreaksRenderer(); m_classBreaksRenderer.Field = comboBox1.SelectedItem.ToString(); m_classBreaksRenderer.BreakCount = Convert.ToInt32(textBox1.Text); m_classBreaksRenderer.MinimumBreak = Convert.ToDouble(textBox2.Text); //Calculate the class interval by a simple mean value double interval = (Convert.ToDouble(textBox3.Text) - m_classBreaksRenderer.MinimumBreak) / m_classBreaksRenderer.BreakCount; //Get the color ramp IColorRamp colorRamp = (IColorRamp)m_styleGalleryItem.Item; //Set the size of the color ramp and recreate it colorRamp.Size = Convert.ToInt32(textBox1.Text); bool createRamp; colorRamp.CreateRamp(out createRamp); //Get the enumeration of colors from the color ramp IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); double currentBreak = m_classBreaksRenderer.MinimumBreak; ISimpleFillSymbol simpleFillSymbol; //Loop through each class break for (int i = 0; i <= m_classBreaksRenderer.BreakCount - 1; i++) { //Set class break m_classBreaksRenderer.set_Break(i, currentBreak); //Create simple fill symbol and set color simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); //Add symbol to renderer m_classBreaksRenderer.set_Symbol(i, (ISymbol)simpleFillSymbol); currentBreak += interval; } //Hide the form this.Hide(); }
public void createClassBreakRender(string ClassField) { int classCount = 5; ILayer pLayer = axMapControl1.get_Layer(2); IFeatureLayer pFeatLayer = (IFeatureLayer)pLayer; IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)pLayer; double[] classes; //classes = classifyGEN.ClassBreaks as double[]; classes = new double[] { 0, 1, 2, 3, 3 }; IEnumColors enumColors = CreateAlgorithmicColorRamp(classes.Length).Colors; IColor color; IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass(); classBreaksRenderer.Field = ClassField; classBreaksRenderer.BreakCount = classCount;//分级数目 classBreaksRenderer.SortClassesAscending = true; ISimpleLineSymbol simpleLineSymbol; for (int i = 0; i < classes.Length - 1; i++) { color = enumColors.Next(); simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = color; simpleLineSymbol.Width = 4.0; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; classBreaksRenderer.set_Symbol(i, simpleLineSymbol as ISymbol); classBreaksRenderer.set_Break(i, classes[i]); } if (geoFeatureLayer != null) { geoFeatureLayer.Renderer = classBreaksRenderer as IFeatureRenderer; //刷新地图和TOOCotrol IActiveView pActiveView = axMapControl1.Map as IActiveView; pActiveView.Refresh(); axTOCControl1.Update(); } }
private void button4_Click(object sender, EventArgs e) { IEnumColors pEnumColors = null; IColor color; pEnumColors = CreatePresetColorRamp().Colors; pEnumColors.Reset(); this.pictureBox1.BackColor = ColorTranslator.FromOle(pEnumColors.Next().RGB); this.pictureBox2.BackColor = ColorTranslator.FromOle(pEnumColors.Next().RGB); this.pictureBox3.BackColor = ColorTranslator.FromOle(pEnumColors.Next().RGB); this.pictureBox4.BackColor = ColorTranslator.FromOle(pEnumColors.Next().RGB); this.pictureBox5.BackColor = ColorTranslator.FromOle(pEnumColors.Next().RGB); this.pictureBox6.BackColor = ColorTranslator.FromOle(pEnumColors.Next().RGB); }
/// <summary> /// 添加唯一值和设置标注符号 /// </summary> /// <param name="uniqueValueRenderer">唯一值渲染</param> /// <param name="uniqueValue">唯一值</param> /// <param name="enumColors">颜色带</param> private static void AddValueAndSetLabelSymbol <T>(IRasterUniqueValueRenderer uniqueValueRenderer, List <T> uniqueValue, IEnumColors enumColors) { IFillSymbol fillSymbol = new SimpleFillSymbolClass(); for (int i = 0; i < uniqueValue.Count; i++) { object currentValue = uniqueValue[i]; uniqueValueRenderer.AddValue(0, i, currentValue); fillSymbol.Color = enumColors.Next(); string valueLabel = currentValue.ToString(); if (StringHelper.IsNumeric(valueLabel)) { //获取四位小数的字符串 valueLabel = GetRound(currentValue); } uniqueValueRenderer.set_Label(0, i, valueLabel); uniqueValueRenderer.set_Symbol(0, i, (ISymbol)fillSymbol); } }
/// <summary> /// 单一值渲染(多字段) /// </summary> /// <param name="layerName">图层名</param> /// <param name="RenderField">多字段名</param> /// <param name="FillStyle">样式</param> /// <param name="valueCount">每个字段中唯一值的个数</param> public void CreateUniqueValueRander(ILayer pLayer, string[] RenderField, esriSimpleFillStyle FillStyle, int[] valueCount) { IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = pLayer as IGeoFeatureLayer; IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer(); //可以设置多个字段 uniqueValueRenderer.FieldCount = RenderField.Length; //0-3个 for (int i = 0; i < RenderField.Length; i++) { uniqueValueRenderer.set_Field(i, RenderField[i]); } //简单填充符号 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(); simpleFillSymbol.Style = FillStyle; IFeatureCursor featureCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature feature; if (featureCursor != null) { for (int i = 0; i < RenderField.Length; i++) { IEnumColors enumColors = CreateAlgorithmicColorRamp(); int fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField(RenderField[i]); for (int j = 0; j < valueCount[i]; j++) { feature = featureCursor.NextFeature(); string nameValue = feature.get_Value(fieldIndex).ToString(); simpleFillSymbol = new SimpleFillSymbol(); simpleFillSymbol.Color = enumColors.Next(); uniqueValueRenderer.AddValue(nameValue, RenderField[i], simpleFillSymbol as ISymbol); } } } geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; }
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()); }
void IThematic.SingleRender() { //_ftLayer = (IFeatureLayer)_mapControl.get_Layer(0); _geoFeatureLayer = (IGeoFeatureLayer)_ftLayer; _ftClass = _ftLayer.FeatureClass; _table = (ITable)_ftClass; _interval = (this._maxValue - this._minValue) / this._breakCount; _renderer.Field = _fieldName; _renderer.BreakCount = _breakCount; _renderer.SortClassesAscending = true; _colorFrom.Hue = 60; _colorFrom.Saturation = 100; _colorFrom.Value = 96; _colorTo.Hue = 0; _colorTo.Saturation = 100; _colorTo.Value = 96; _algClrRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; _algClrRamp.FromColor = _colorFrom; _algClrRamp.ToColor = _colorTo; _algClrRamp.Size = _breakCount; bool ok; _algClrRamp.CreateRamp(out ok); _enumColors = _algClrRamp.Colors; IColor pColor; _currentValue = _minValue;//_renderer.MinimumBreak; for (int breakIndex = 0; breakIndex < _breakCount; breakIndex++) { pColor = _enumColors.Next(); _symbol = new SimpleFillSymbolClass(); _symbol.Color = pColor; _symbol.Style = esriSimpleFillStyle.esriSFSSolid; _renderer.set_Break(breakIndex, _currentValue); _renderer.set_Symbol(breakIndex, (ISymbol)_symbol); _currentValue += _interval; } _mapControl.AddLayer(_ftLayer,0); _geoFeatureLayer.Renderer = (IFeatureRenderer)_renderer; _mapControl.ActiveView.Refresh(); _tocControl.Update(); //_tableHistogram.Field = _fieldName; //_tableHistogram.Table = _table; //_classify. }