private void cmdCancel_Click(object eventSender, System.EventArgs eventArgs) { // // User pressed Cancel, so we set the colors enumeration to nothing and // unload the form. // m_enumNewColors = null; this.Close(); }
private void btnSelectColorRamp_Click(object sender, EventArgs e) { ColorRampForm colorRampForm = new ColorRampForm(); colorRampForm.ShowDialog(); colorRamp = colorRampForm.m_styleGalleryItem.Item as IColorRamp; colorRampForm.Dispose(); if (colorRamp == null) { return; } gEnumColors = colorRamp.Colors; gEnumColors.Reset(); }
/// <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); }
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 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); }
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); } }
private void UpdateRamp() { // // Create a new AlgorithmicColorRamp object, and get it's // IAlgorithmicColorRamp interface. // IAlgorithmicColorRamp AlgortihmicColorRamp = null; AlgortihmicColorRamp = new ESRI.ArcGIS.Display.AlgorithmicColorRamp(); // // Set the size of the color ramp to the number of classes // to be renderered. // AlgortihmicColorRamp.Size = m_lngClasses; // // Set the color ramps properties. // IRgbColor RGBColor = null; RGBColor = new RgbColor(); RGBColor.RGB = System.Drawing.ColorTranslator.ToOle(txtStartColor.BackColor); AlgortihmicColorRamp.FromColor = RGBColor; RGBColor.RGB = System.Drawing.ColorTranslator.ToOle(txtEndColor.BackColor); AlgortihmicColorRamp.ToColor = RGBColor; AlgortihmicColorRamp.Algorithm = (esriColorRampAlgorithm)cmbAlgorithm.SelectedIndex; bool boolRamp = false; if (AlgortihmicColorRamp.Size > 0) { boolRamp = true; AlgortihmicColorRamp.CreateRamp(out boolRamp); if (boolRamp) { m_enumNewColors = AlgortihmicColorRamp.Colors; m_enumNewColors.Reset(); cmdOK.Enabled = true; // // Check if we should be showing the colors. // if (chkShowColors.CheckState == System.Windows.Forms.CheckState.Checked) { // // Populate the Colors textbox array and it's labels. // m_lngColors = 0; ShowColorsArray(); } } } }
private void RefreshColorRamp() {//刷新符号颜色 if (flag) { return; } IColorRamp pColorRamp = (cmbColorRamp.SelectedItem as DevComponents.Editors.ComboItem).Tag as IColorRamp; bool bCreateRamp; pColorRamp.Size = 5; pColorRamp.CreateRamp(out bCreateRamp); IEnumColors enumColors = pColorRamp.Colors; enumColors.Reset(); }
/// <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 }
private IEnumColors GetEnumColorsBySelectColorRamp(int colorSize) { if (colorRamp == null) { MessageBox.Show("请选择色带...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } colorRamp.Size = colorSize; bool createRamp; colorRamp.CreateRamp(out createRamp); IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); return(enumColors); }
private void RefreshColorRamp() {//ˢзûºÅÑÕÉ« if (flag) { return; } IColorRamp pColorRamp = (cmbColorRamp.SelectedItem as DevComponents.Editors.ComboItem).Tag as IColorRamp; bool bCreateRamp; int count = listAddField.Items.Count + listAllField.Items.Count; pColorRamp.Size = count <= 1 ? 2 : count; pColorRamp.CreateRamp(out bCreateRamp); IEnumColors enumColors = pColorRamp.Colors; enumColors.Reset(); listAddField.SmallImageList.Images.Clear(); for (int i = 0; i < listAllField.Items.Count; i++) { IColor pColor = enumColors.Next(); if (pColor == null) { enumColors.Reset(); enumColors.Next(); } System.Windows.Forms.ListViewItem item = listAllField.Items[i]; ModuleCommon.ChangeSymbolColor(item.Tag as ISymbol, pColor); } for (int i = 0; i < listAddField.Items.Count; i++) { IColor pColor = enumColors.Next(); if (pColor == null) { enumColors.Reset(); enumColors.Next(); } System.Windows.Forms.ListViewItem item = listAddField.Items[i]; ModuleCommon.ChangeSymbolColor(item.Tag as ISymbol, pColor); listAddField.SmallImageList.Images.Add(item.Name.Replace("Item", "Symbol"), ModuleCommon.Symbol2Picture(item.Tag as ISymbol, ModuleCommon.ImageWidth, ModuleCommon.ImageHeight)); listAddField.Items[i].ImageKey = item.Name.Replace("Item", "Symbol"); } listAddField.Refresh(); }
private void colorRampComboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (this.bool_0) { IFields fields = this.igeoFeatureLayer_0.FeatureClass.Fields; this.ienumColors_0 = this.method_1(this.colorRampComboBox1.GetSelectColorRamp(), fields.FieldCount); this.ienumColors_0.Reset(); this.ichartRenderer_0.ColorScheme = this.colorRampComboBox1.Text; ISymbolArray chartSymbol = this.ichartRenderer_0.ChartSymbol as ISymbolArray; for (int i = 0; i < chartSymbol.SymbolCount; i++) { IFillSymbol symbol = chartSymbol.get_Symbol(i) as IFillSymbol; symbol.Color = this.ienumColors_0.Next(); } this.SelectFieldslistView.Invalidate(); } }
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(); } }
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 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); }
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 IEnumColors CreateAlgorithmicColorRamp() { IRandomColorRamp pRandomColorRamp = new RandomColorRamp(); pRandomColorRamp.StartHue = 0; pRandomColorRamp.EndHue = 120; pRandomColorRamp.MinValue = 0; pRandomColorRamp.MaxValue = 90; pRandomColorRamp.MinSaturation = 0; pRandomColorRamp.MaxSaturation = 45; pRandomColorRamp.Size = 20; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 40; bool bture = true; pRandomColorRamp.CreateRamp(out bture); IEnumColors pEnuColors = pRandomColorRamp.Colors; return(pEnuColors); }
/// <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 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 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()); }
/// <summary> /// UniqueValueRenderer唯一值渲染:统计字段不重复值进行分组渲染图层 /// </summary> /// <param name="geoFeatureLayer"></param> /// <param name="fieldName">唯一值字段</param> public static void SetUniqueValueRenderer(this IGeoFeatureLayer geoFeatureLayer, string fieldName) { ITable table = (ITable)geoFeatureLayer.FeatureClass; IQueryFilter queryFilter = new QueryFilter(); queryFilter.AddField(fieldName); var cursor = table.Search(queryFilter, true); //获取字段中各要素属性唯一值 IDataStatistics dataStatistics = new DataStatisticsClass { Field = fieldName, Cursor = cursor }; var enumreator = dataStatistics.UniqueValues; var fieldCount = dataStatistics.UniqueValueCount; IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass(); uvRenderer.FieldCount = 1; //单值渲染 uvRenderer.set_Field(0, fieldName); //渲染字段 IEnumColors enumColor = GetColorRamp(fieldCount).Colors; enumColor.Reset(); while (enumreator.MoveNext()) { var value = enumreator.Current?.ToString(); if (value == null) { continue; } IColor color = enumColor.Next(); ISymbol symbol = GetDefaultSymbol(geoFeatureLayer.FeatureClass.ShapeType, color); uvRenderer.AddValue(value, fieldName, symbol); } geoFeatureLayer.Renderer = (IFeatureRenderer)uvRenderer; }
private void DotDensityRendererCtrl_Load(object sender, EventArgs e) { this.method_2(); if (this.istyleGallery_0 != null) { IEnumStyleGalleryItem item = this.istyleGallery_0.get_Items("Color Ramps", "", ""); item.Reset(); for (IStyleGalleryItem item2 = item.Next(); item2 != null; item2 = item.Next()) { this.colorRampComboBox1.Add(item2); } item = null; GC.Collect(); } if (this.colorRampComboBox1.Items.Count == 0) { this.colorRampComboBox1.Enabled = false; } else { this.colorRampComboBox1.Text = this.idotDensityRenderer_0.ColorScheme; if (this.colorRampComboBox1.SelectedIndex == -1) { this.colorRampComboBox1.SelectedIndex = 0; this.idotDensityRenderer_0.ColorScheme = this.colorRampComboBox1.Text; } IFields fields = this.igeoFeatureLayer_0.FeatureClass.Fields; this.ienumColors_0 = this.method_1(this.colorRampComboBox1.GetSelectColorRamp(), fields.FieldCount); this.ienumColors_0.Reset(); } if (this.igeoFeatureLayer_0 != null) { this.method_0(); } this.bool_0 = true; }
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. }
private void btn_ok_Click(object sender, EventArgs e) { IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; //Find the selected field in the feature layer IFeatureClass featureClass = m_FeatureLayer.FeatureClass; string pFileName = cbx_Field.SelectedItem.ToString(); if (pFileName == "None") { MessageBox.Show("不可用的字段,请选择其它图层"); return; } IField field = featureClass.Fields.get_Field(featureClass.FindField(pFileName)); //Get a feature cursor ICursor cursor = (ICursor)m_FeatureLayer.Search(null, false); //Create a DataStatistics object and initialize properties IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = field.Name; dataStatistics.Cursor = cursor; //Get the result statistics IStatisticsResults statisticsResults = dataStatistics.Statistics; //Set the values min min and max values m_MinOfField = statisticsResults.Minimum; m_MaxOfField = statisticsResults.Maximum; m_classBreaksRenderer = new ClassBreaksRenderer(); m_classBreaksRenderer.Field = cbx_Field.SelectedItem.ToString(); m_classBreaksRenderer.BreakCount = (int)numUD_TotalClasses.Value; m_classBreaksRenderer.MinimumBreak = m_MinOfField; double interval = (m_MaxOfField - m_MinOfField) / 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(numUD_TotalClasses.Value); 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 rhough 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; } pGeoFeatureLayer.Renderer = (IFeatureRenderer)m_classBreaksRenderer; // geofeaturelayer.Renderer = (IFeatureRenderer)classBreaksRenderer; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pGeoFeatureLayer, null); }
private IEnumColors MultiPartColorRamp(string strColorRamp, string strAlgorithm, int intGCBreakeCount) { try { IEnumColors pEnumColors = null; if (strColorRamp == "Blue Light to Dark" || strColorRamp == "Green Light to Dark" || strColorRamp == "Orange Light to Dark" || strColorRamp == "Red Light to Dark") { IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass(); switch (strAlgorithm) { case "HSV": pColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; break; case "CIE Lab": pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; break; case "Lab LCh": pColorRamp.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm; break; default: pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; break; } IRgbColor pColor1 = new RgbColor(); IRgbColor pColor2 = new RgbColor(); switch (strColorRamp) { case "Blue Light to Dark": pColor1 = pSnippet.getRGB(239, 243, 255); pColor2 = pSnippet.getRGB(8, 81, 156); break; case "Green Light to Dark": pColor1 = pSnippet.getRGB(237, 248, 233); pColor2 = pSnippet.getRGB(0, 109, 44); break; case "Orange Light to Dark": pColor1 = pSnippet.getRGB(254, 237, 222); pColor2 = pSnippet.getRGB(166, 54, 3); break; case "Red Light to Dark": pColor1 = pSnippet.getRGB(254, 229, 217); pColor2 = pSnippet.getRGB(165, 15, 21); break; default: pColor1 = pSnippet.getRGB(254, 229, 217); pColor2 = pSnippet.getRGB(165, 15, 21); break; } Boolean blnOK = true; pColorRamp.FromColor = pColor1; pColorRamp.ToColor = pColor2; pColorRamp.Size = intGCBreakeCount; pColorRamp.CreateRamp(out blnOK); //arrColors = new int [intGCBreakeCount,3]; pEnumColors = pColorRamp.Colors; } else if (strColorRamp == "Custom") { Boolean blnOK = true; frmColorRamps m_pColorRamps = System.Windows.Forms.Application.OpenForms["frmColorRamps"] as frmColorRamps; IMultiPartColorRamp pMultiColorRamp = m_pColorRamps.pMulitColorRampsResults; pMultiColorRamp.Size = intGCBreakeCount; pMultiColorRamp.CreateRamp(out blnOK); pEnumColors = pMultiColorRamp.Colors; } else { IAlgorithmicColorRamp pColorRamp1 = new AlgorithmicColorRampClass(); IAlgorithmicColorRamp pColorRamp2 = new AlgorithmicColorRampClass(); switch (strAlgorithm) { case "HSV": pColorRamp1.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pColorRamp2.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; break; case "CIE Lab": pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; break; case "Lab LCh": pColorRamp1.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm; pColorRamp2.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm; break; default: pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; break; } IRgbColor pColor1 = new RgbColor(); IRgbColor pColor2 = new RgbColor(); IRgbColor pColor3 = new RgbColor(); switch (strColorRamp) { case "Blue to Red": pColor1 = pSnippet.getRGB(49, 54, 149); pColor2 = pSnippet.getRGB(255, 255, 191); pColor3 = pSnippet.getRGB(165, 0, 38); break; case "Green to Purple": pColor1 = pSnippet.getRGB(0, 68, 27); pColor2 = pSnippet.getRGB(247, 247, 247); pColor3 = pSnippet.getRGB(64, 0, 75); break; case "Green to Red": pColor1 = pSnippet.getRGB(0, 104, 55); pColor2 = pSnippet.getRGB(255, 255, 191); pColor3 = pSnippet.getRGB(165, 0, 38); break; case "Purple to Brown": pColor1 = pSnippet.getRGB(45, 0, 75); pColor2 = pSnippet.getRGB(247, 247, 247); pColor3 = pSnippet.getRGB(127, 59, 8); break; default: pColor1 = pSnippet.getRGB(49, 54, 149); pColor2 = pSnippet.getRGB(255, 255, 191); pColor3 = pSnippet.getRGB(165, 0, 38); break; } 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 = intGCBreakeCount; pMultiColorRamp.CreateRamp(out blnOK); pEnumColors = pMultiColorRamp.Colors; } pEnumColors.Reset(); return(pEnumColors); } catch (Exception ex) { MessageBox.Show(this.Handle.ToString() + " Error:" + ex.Message); return(null); } }
public void DrawSymbolinListView() { try { lvSymbol.Items.Clear(); string strGCRenderField = cboValueField.Text; string strUncernfld = cboUncernFld.Text; intGCBreakeCount = Convert.ToInt32(nudGCNClasses.Value); int intValueFldIdx = pFClass.FindField(strGCRenderField); int intUncernfldIdx = pFClass.FindField(strUncernfld); if (intUncernfldIdx == -1 || intValueFldIdx == -1 || cboMethod.Text == "") { return; } ITable pTable = (ITable)pFClass; ITableSort pTableSort = new TableSort(); pTableSort.Table = pTable; ICursor pCursor = (ICursor)pFClass.Search(null, false); pTableSort.Cursor = pCursor as ICursor; pTableSort.Fields = strGCRenderField; pTableSort.set_Ascending(strGCRenderField, true); // call the sort pTableSort.Sort(null); // retrieve the sorted rows IFeatureCursor pSortedCursor = pTableSort.Rows as IFeatureCursor; if (cboMethod.Text == "Class Seperability") { cb = ClassSeparabilityMeasure(intGCBreakeCount, intNofFeatures, pSortedCursor, intValueFldIdx, intUncernfldIdx); } else if (cboMethod.Text == "Bhattacharyya distance") { //cb = BhattaDist(intGCBreakeCount, intNofFeatures, pSortedCursor, intValueFldIdx, intUncernfldIdx); MessageBox.Show("Under Reviewing"); return; } if (cb == null) { return; } strClassificationMethod = "Breaks maximum " + cboMethod.Text + " between Observations"; pRender = new ClassBreaksRenderer(); pRender.Field = strGCRenderField; 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 btnSelectColorRamp_Click(object sender, EventArgs e) { ColorRampForm colorRampForm = new ColorRampForm(); colorRampForm.ShowDialog(); colorRamp = colorRampForm.m_styleGalleryItem.Item as IColorRamp; colorRampForm.Dispose(); if (colorRamp == null) return; gEnumColors = colorRamp.Colors; gEnumColors.Reset(); }
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); }
private void StatisticsSymbols_Load(object sender, EventArgs e) { CbxLayersAddItems(); colorRamp = GetColorRamp(10); gEnumColors = colorRamp.Colors; gEnumColors.Reset(); lvRendererFields.View = View.List; }
private IUniqueValueRenderer CreateRenderer(IFeatureClass featureClass) { int uniqueValuesCount = GetUniqueValuesCount(featureClass, strRendererField); System.Collections.IEnumerator enumerator = GetUniqueValues(featureClass, strRendererField); if (uniqueValuesCount == 0) { return(null); } IEnumColors pEnumRamp = GetEnumColorsByRandomColorRamp(uniqueValuesCount); //IEnumColors pEnumRamp = GetEnumColorsBySelectColorRamp(uniqueValuesCount); pEnumRamp.Reset(); IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass(); //只用一个字段进行单值着色 pUniqueValueR.FieldCount = 1; //用于区分着色的字段 pUniqueValueR.set_Field(0, strRendererField); IColor pColor = null; ISymbol symbol = null; enumerator.Reset(); while (enumerator.MoveNext()) { object codeValue = enumerator.Current; pColor = pEnumRamp.Next(); switch (featureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass() as ISimpleMarkerSymbol; markerSymbol.Color = pColor; symbol = markerSymbol as ISymbol; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass() as ISimpleLineSymbol; lineSymbol.Color = pColor; symbol = lineSymbol as ISymbol; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass() as ISimpleFillSymbol; fillSymbol.Color = pColor; symbol = fillSymbol as ISymbol; break; default: break; } //将每次得到的要素字段值和修饰它的符号放入着色对象中 pUniqueValueR.AddValue(codeValue.ToString(), strRendererField, symbol); } return(pUniqueValueR); }
private IClassBreaksRenderer CreateClassBreaksRenderer(IFeatureClass featureClass) { if (colorRamp == null) { MessageBox.Show("请先选择色带!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } classify(); int ClassesCount = gClassbreaks.GetUpperBound(0); if (ClassesCount == 0) { return(null); } nudClassCount.Value = ClassesCount; IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = strRendererField; if (strNormalizeField.ToLower() != "none") { pClassBreaksRenderer.NormField = strNormalizeField; } //设置着色对象的分级数目 pClassBreaksRenderer.BreakCount = ClassesCount; pClassBreaksRenderer.SortClassesAscending = true; //通过色带设置各级分类符号的颜色 colorRamp.Size = ClassesCount; bool createRamp; colorRamp.CreateRamp(out createRamp); IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); IColor pColor = null; ISymbol symbol = null; //需要注意的是分级着色对象中的symbol和break的下标都是从0开始 for (int i = 0; i < ClassesCount; i++) { pColor = enumColors.Next(); switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = pColor; symbol = simpleMarkerSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolyline: ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = pColor; symbol = simpleLineSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolygon: ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = pColor; symbol = simpleFillSymbol as ISymbol; break; default: break; } pClassBreaksRenderer.set_Symbol(i, symbol); pClassBreaksRenderer.set_Break(i, gClassbreaks[i + 1]); } return(pClassBreaksRenderer); }
//单一或多字段符号化 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(); }