//分级专题图 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="layer"></param> /// <param name="strField"></param> /// <param name="numDesiredClasses"></param> public static void ClassBreaksMap(IFeatureLayer layer, string strField, int numDesiredClasses) { double[] classes = { 147.744196, 213.149274, 506.677245, 742.234523, 1096.249126, 4864.483353 }; //断点值,两端分别是渲染字段的最小值和最大值 IEnumColors pEnumColors; //颜色带 Color startColor = Color.FromArgb(100, 100, 190, 150); //低值颜色 Color endColor = Color.FromArgb(30, 0, 200, 0); //高值颜色 IGeoFeatureLayer pGeoFeatureLayer; ITable pTable; IClassifyGEN pClassify; ITableHistogram pTableHistogram; IBasicHistogram pBasicHistogram; object dataFrequency; object dataValues; int classesCount; IClassBreaksRenderer pClassBreaksRenderer; IColor pColor; ISimpleFillSymbol pSimpleFillSymbol; int breakIndex; pGeoFeatureLayer = (IGeoFeatureLayer)layer; pTable = (ITable)pGeoFeatureLayer.FeatureClass; pTableHistogram = new BasicTableHistogramClass(); pBasicHistogram = (IBasicHistogram)pTableHistogram; pTableHistogram.Field = strField; pTableHistogram.Table = pTable; pBasicHistogram.GetHistogram(out dataValues, out dataFrequency); pClassify = new EqualIntervalClass(); try { pClassify.Classify(dataValues, dataFrequency, ref numDesiredClasses); } catch (Exception ee) { //MessageBox.Show(ee.Message); } //classes = (double[])pClassify.ClassBreaks; //classes[0] = 147.744196; //classes[1]=213.149274; //classes[2]=506.677245; //classes[3]=742.234523; //classes[4]=1096.249126; //classes[5] = 4864.483353; classesCount = classes.GetUpperBound(0); pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = strField; pClassBreaksRenderer.BreakCount = classesCount; pClassBreaksRenderer.SortClassesAscending = true; pEnumColors = ProduceEnumColors(startColor, endColor, classesCount);//产生色带 for (breakIndex = 0; breakIndex < classesCount; breakIndex++) { pColor = pEnumColors.Next(); pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassBreaksRenderer.set_Symbol(breakIndex, pSimpleFillSymbol as ISymbol); pClassBreaksRenderer.set_Break(breakIndex, classes[breakIndex + 1]); } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer; MainFrom.m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
/// <summary> /// ClassBreakRender分级渲染:根据数字字段的值分组渲染图层 /// </summary> /// <param name="geoFeatureLayer">操作图层</param> /// <param name="fieldName">操作字段名</param> /// <param name="breakCount">分级数量</param> /// <param name="outLineColor">分组符号的外框颜色</param> public static void SetClassBreakRenderer(this IGeoFeatureLayer geoFeatureLayer, string fieldName, int breakCount, IColor outLineColor) { //获取该字段的最大值、最小值 var statisticsResults = geoFeatureLayer.FeatureClass.Statistics(fieldName, null); double max = statisticsResults.Maximum; double min = statisticsResults.Minimum; //设置分级数,字段 IClassBreaksRenderer cbRender = new ClassBreaksRendererClass(); cbRender.MinimumBreak = min; //最小值 cbRender.Field = fieldName; //分级字段 cbRender.BreakCount = breakCount; //分级数量 //设置每一级的分段范围,符号 var lineSymbol = SymbolCreate.GetSimpleLineSymbol(outLineColor);//新建边线符号 for (int i = 0; i < breakCount; i++) { var color = ColorCreate.GetIColor(0, 250 / breakCount * (breakCount - i), 0); cbRender.set_Break(i, (max - min) * (i + 1) / breakCount + min); cbRender.set_Symbol(i, new SimpleFillSymbolClass { Outline = lineSymbol, Color = color }); } geoFeatureLayer.Renderer = (IFeatureRenderer)cbRender; }
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); }
public static void classifyRender(IFeatureLayer featLayer, string classMethod, string fieldName, IColorRamp colorRamp, int count) { try { //值分级 IBasicHistogram pBasicHis = new BasicTableHistogramClass(); ITableHistogram pTabHis = (ITableHistogram)pBasicHis; IClassifyGEN pClassify = null; switch (classMethod) { case "等间距分级": pClassify = new EqualIntervalClass(); break; case "自然断点分级": pClassify = new NaturalBreaksClass(); break; } pTabHis.Field = fieldName; ILayer Layer = (ILayer)featLayer; ITable pTab = (ITable)Layer; pTabHis.Table = pTab; object doubleArrVal, longArrFreq; pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq); int nDes = count; pClassify.Classify(doubleArrVal, longArrFreq, ref nDes); double[] ClassNum; ClassNum = (double[])pClassify.ClassBreaks; int ClassCountResult = ClassNum.GetUpperBound(0); IClassBreaksRenderer pRender = new ClassBreaksRendererClass(); pRender.BreakCount = ClassCountResult; pRender.Field = fieldName; ISimpleFillSymbol pSym; IColor pColor; for (int j = 0; j < ClassCountResult; j++) { pColor = colorRamp.get_Color(j * (colorRamp.Size - 1) / (ClassCountResult - 1)); pRender.set_Symbol(j, getISymbolByGeomType(featLayer, pColor)); pRender.set_Break(j, ClassNum[j + 1]); pRender.set_Label(j, ClassNum[j].ToString("0.00") + " - " + ClassNum[j + 1].ToString("0.00")); } IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Layer; pGeoLyr.Renderer = (IFeatureRenderer)pRender; } catch { XtraMessageBox.Show("嗯,哪个,就一个值,别分级了好不好^_^"); } }
/// <summary> /// 根据容积率大小进行梯度颜色显示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { //梯度颜色算法 IAlgorithmicColorRamp pAlgoColorRamp = new AlgorithmicColorRampClass(); pAlgoColorRamp.Size = MyArray.Length; IRgbColor pFromColor = new RgbColorClass(), pToColor = new RgbColorClass(); pFromColor.Red = 255; pFromColor.Green = 255; pFromColor.Blue = 255; pToColor.Red = 0; pToColor.Green = 255; pToColor.Blue = 255; pAlgoColorRamp.FromColor = pFromColor; pAlgoColorRamp.ToColor = pToColor; bool ok = true; pAlgoColorRamp.CreateRamp(out ok); IClassBreaksRenderer pRender = new ClassBreaksRendererClass(); pRender.BreakCount = MyArray.Length; pRender.Field = "Plot_Ratio"; ISimpleFillSymbol pSym; System.Array.Sort(MyArray); for (int i = 0; i < MyArray.Length; i++) { pRender.set_Break(i, (double)MyArray.GetValue(i)); pSym = new SimpleFillSymbolClass(); pSym.Color = pAlgoColorRamp.get_Color(i); pRender.set_Symbol(i, (ISymbol)pSym); } IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Form1.mainForm.axMapControl1.get_Layer(1);//确保先加入地块图层 pGeoLyr.Renderer = (IFeatureRenderer)pRender; Form1.mainForm.axMapControl1.Refresh(); Form1.mainForm.axTOCControl1.Update(); }
private IClassBreaksRenderer CreateClassBreaksRenderer(IFeatureClass featureClass) { classify(); if (gClassbreaks == null) { MessageBox.Show("请先分类...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } 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; pClassBreaksRenderer.BackgroundSymbol = fillSymbol; IMarkerSymbol symbol = null; if (markerSymbol == null) { MessageBox.Show("请先选择点符号", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } //需要注意的是分级着色对象中的symbol和break的下标都是从0开始 double sizeInterval = (maxSize - minSize) / ClassesCount; for (int i = 0; i < ClassesCount; i++) { symbol = markerSymbol; symbol.Size = minSize + i * sizeInterval; pClassBreaksRenderer.set_Symbol(i, symbol as ISymbol); pClassBreaksRenderer.set_Break(i, gClassbreaks[i + 1]); } return(pClassBreaksRenderer); }
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 static void userRender(IFeatureLayer featLayer, string classMethod, string fieldName, IColorRamp colorRamp, int count, double[] values) { if (values.Length != count) { XtraMessageBox.Show("好像有一些问题,要不重试一下"); return; } IClassBreaksRenderer pRender = new ClassBreaksRendererClass(); pRender.BreakCount = count; pRender.Field = fieldName; IColor pColor; for (int i = 0; i < count; i++) { pColor = colorRamp.get_Color(i); pRender.set_Symbol(i, getISymbolByGeomType(featLayer, pColor)); pRender.set_Break(i, values[i]); } IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)featLayer; pGeoLyr.Renderer = (IFeatureRenderer)pRender; }
private void button5_Click(object sender, EventArgs e) { //先用TableHistogram统计,然后用某种实现IClassifyGEN的类来分类(classify),然后用ClassBreaksRenderer设置每个级别的渲染方式 //SetBreak()的参数是该分类的下标,该分类的值上限 ITable table = m_pTarFeatureLayer as ITable; ITableHistogram tableHistogram = new BasicTableHistogramClass(); IBasicHistogram basicHistogram = tableHistogram as IBasicHistogram; int curFieldIndex = m_pTarFeatureLayer.FeatureClass.Fields.FindField(comboBox1.SelectedItem.ToString()); IField curField = m_pTarFeatureLayer.FeatureClass.Fields.get_Field(curFieldIndex); tableHistogram.Table = table; tableHistogram.Field = curField.Name; basicHistogram.GetHistogram(out object v, out object f); IClassifyGEN clyGen = new EqualIntervalClass(); clyGen.Classify(v, f, trackBar2.Value); double[] classes = clyGen.ClassBreaks as double[]; int classCount = classes.GetUpperBound(0); IClassBreaksRenderer cbr = new ClassBreaksRendererClass { Field = curField.Name, BreakCount = classCount }; IAlgorithmicColorRamp acr = new AlgorithmicColorRampClass { FromColor = m_pFillColor, ToColor = m_pOutlineColor, Size = classCount }; acr.CreateRamp(out _); IEnumColors enumC = acr.Colors; IColor curColor = enumC.Next(); for (int i = 0; i < classCount; i++) { switch (m_pTarFeatureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: { ISimpleFillSymbol sfs = new SimpleFillSymbolClass { Color = curColor }; cbr.set_Symbol(i, sfs as ISymbol); cbr.set_Break(i, classes[i + 1]); break; } case esriGeometryType.esriGeometryPolyline: { ISimpleLineSymbol sls = new SimpleLineSymbolClass(); sls.Color = curColor; sls.Style = esriSimpleLineStyle.esriSLSSolid; cbr.set_Symbol(i, sls as ISymbol); cbr.set_Break(i, classes[i + 1]); break; } } curColor = enumC.Next(); } m_pTarGeoFeatureLayer.Renderer = cbr as IFeatureRenderer; frmMainOper(OperationType.RefreshMapCtrl); frmMainOper(OperationType.UpdateTOCCtrl); }
private IClassBreaksRenderer CreateClassBreaksRenderer(IFeatureClass featureClass, string breakMethod) { ITable pTable = (ITable)featureClass; //从pTable的strRendererField字段中得到信息给datavalues和datafrequency两个数组 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; pTableHistogram.Field = strRendererField; if (strNormalizeField.ToLower() != "none") pTableHistogram.NormField = strNormalizeField; pTableHistogram.Table = pTable; object dataFrequency; object dataValues; pHistogram.GetHistogram(out dataValues, out dataFrequency); //下面是分级方法,用于根据获得的值计算得出符合要求的数据 //根据条件计算出Classes和ClassesCount,numDesiredClasses为预定的分级数目 IClassifyGEN pClassify = null; int numDesiredClasses = classCount; switch (breakMethod) { case "等间隔": pClassify = new EqualIntervalClass(); break; case "已定义的间隔": pClassify = new DefinedIntervalClass(); IIntervalRange2 intervalRange = pClassify as IIntervalRange2; intervalRange.IntervalRange = dblDefinedInterval; break; case "分位数": pClassify = new QuantileClass(); break; case "自然裂点": pClassify = new NaturalBreaksClass(); break; case "标准差": pClassify = new StandardDeviationClass(); IStatisticsResults pStatRes = pHistogram as IStatisticsResults; IDeviationInterval pStdDev = pClassify as IDeviationInterval; pStdDev.Mean = pStatRes.Mean; pStdDev.StandardDev = pStatRes.StandardDeviation; pStdDev.DeviationInterval = dblStdDevInterval; break; default: break; } if (pClassify == null) return null; pClassify.Classify(dataValues, dataFrequency, ref numDesiredClasses); //返回一个数组 double[] classBreaks = (double[])pClassify.ClassBreaks; int ClassesCount = classBreaks.GetUpperBound(0); nudClassCount.Value = ClassesCount; IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = strRendererField; if (strNormalizeField.ToLower() != "none") pClassBreaksRenderer.NormField = strNormalizeField; //设置着色对象的分级数目 pClassBreaksRenderer.BreakCount = ClassesCount; pClassBreaksRenderer.SortClassesAscending = true; if (colorRamp == null) { MessageBox.Show("请先选择色带!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return null; } //通过色带设置各级分类符号的颜色 colorRamp.Size = ClassesCount; bool createRamp; colorRamp.CreateRamp(out createRamp); IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); IColor pColor = null; ISymbol symbol = null; if (gloabalSymbol == null) { MessageBox.Show("请选择符号...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return null; } //需要注意的是分级着色对象中的symbol和break的下标都是从0开始 for (int i = 0; i < ClassesCount; i++) { pColor = enumColors.Next(); switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: IMarkerSymbol markerSymbol = gloabalSymbol as IMarkerSymbol; markerSymbol.Color = pColor; symbol = markerSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolyline: ILineSymbol lineSymbol = gloabalSymbol as ILineSymbol; lineSymbol.Color = pColor; symbol = lineSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolygon: IFillSymbol fillSymbol = gloabalSymbol as IFillSymbol; fillSymbol.Color = pColor; symbol = fillSymbol as ISymbol; break; default: break; } pClassBreaksRenderer.set_Symbol(i, symbol); pClassBreaksRenderer.set_Break(i, classBreaks[i + 1]); } return pClassBreaksRenderer; }
public void ApplyClassBreaks(IGeoFeatureLayer geoLayer, string aFieldName, long numBreaks) { // Create a table from the geo feature layer ITable table; table = geoLayer as ITable; ITableHistogram tableHistogram; tableHistogram = new BasicTableHistogramClass(); tableHistogram.Table = table; // equivalent to geoLayer.FeatureClass // Retrieve frequency data from the field tableHistogram.Field = aFieldName; // MessageBox.Show("Field is: " & tableHistogram.Field) IHistogram histogram; histogram = tableHistogram as IHistogram; object vValues; object vFreqs; histogram.GetHistogram(out vValues, out vFreqs); // Classify the data IClassifyGEN classifyGEN = new EqualIntervalClass(); int intBreaks; intBreaks = Convert.ToInt32(numBreaks); classifyGEN.Classify(vValues, vFreqs, ref intBreaks); double[] vBreaks = (double[])classifyGEN.ClassBreaks; // need an array // Create the class breaks renderer IClassBreaksRenderer classBreaksRenderer; classBreaksRenderer = new ClassBreaksRendererClass(); classBreaksRenderer.Field = aFieldName; // passed as a String to the sub routine classBreaksRenderer.BreakCount = (int)(numBreaks); IRgbColor fromColor = new RgbColorClass(); fromColor.UseWindowsDithering = true; fromColor.RGB = Microsoft.VisualBasic.Information.RGB(255, 255, 0); IRgbColor toColor = new RgbColorClass(); toColor.UseWindowsDithering = true; toColor.RGB = Microsoft.VisualBasic.Information.RGB(255, 0, 0); // Set up the fill symbol ISimpleFillSymbol sym = new SimpleFillSymbolClass(); IColor fillColor; MessageBox.Show("vBreaks.Length: " + vBreaks.Length.ToString()); IEnumColors colors; colors = GetColors(fromColor.RGB, toColor.RGB, numBreaks); for (int i = 0; (i <= vBreaks.Length - 2); i++) // Length = 6; subtracted 2; why?? { fillColor = colors.Next(); sym.Color = fillColor; classBreaksRenderer.set_Break(i, vBreaks[(i + 1)]); classBreaksRenderer.set_Symbol(i, sym as ISymbol); geoLayer.Renderer = classBreaksRenderer as IFeatureRenderer; this.m_mapControl.ActiveView.Refresh(); this.m_toolbar.Update(); } }
/// <summary> /// 分等级法渲染器(ClassBreakRenderer), 可以用分级的颜色和符号来绘制 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 分等级法渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //数据分成10个等级 int classCount = 10; //声明一个ITableHistogram变量 //该变量用于控制从表格中生成的直方图的样式 ITableHistogram pTableHistogram; //声明一个IBasicHistogram变量 //该变量用于控制从不同数据源中生成的直方图 IBasicHistogram pBasicHistogram; //实例化表格对象 ITable pTable; //获取生成分级专题图的目标图层 IGeoFeatureLayer pGeoFeatureLayer; //获取渲染图层 pGeoFeatureLayer = getGeoLayer("北部湾"); //将pGeoFeatureLayer强转成ILayer ILayer pLayer = pGeoFeatureLayer as ILayer; //将目标图层(要素类)的属性表强转成ITable pTable = pLayer as ITable; //实例化 //BasicTableHistogram采用表对象输入数据的结构(如自然断点、分位数)生成直方图。 pTableHistogram = new BasicTableHistogramClass(); //赋值pTableHistogram的Table属性字段 pTableHistogram.Table = pTable; //确定分级字段 pTableHistogram.Field = "年"; //pTableHistogram强制转换为IBasicHistogram pBasicHistogram = pTableHistogram as IBasicHistogram; //先统计每个值出现的次数, 输出结果赋予values, frequencys object values; object frequencys; //out参数可以在一个方法中返回多个不同类型的值 pBasicHistogram.GetHistogram(out values, out frequencys); //创建平均分级对象 IClassifyGEN pClassifyGEN = new QuantileClass(); //用统计结果(values——值, frequences——出现频率)进行分级, 级别数目为classCount pClassifyGEN.Classify(values, frequencys, ref classCount); double[] classes; classes = pClassifyGEN.ClassBreaks as double[]; //获得分级结果, 是个双精度类型数组 //注意:获得双精度数组记录条数出现不可修复性错误, 故使用以下代码修复该错误 double[] myclasses; myclasses = new double[classCount]; //当classes不为null时 if (classes != null) { //遍历classes, 从后往前移一位 for (int j = 0; j < classCount; j++) { myclasses[j] = classes[j + 1]; } } //定义一个颜色枚举变量, 通过函数获取颜色带 IEnumColors pEnumColors = CreateAlgorithmicColorRamp(myclasses.Length).Colors; IColor color; //声明并实例化分级渲染器对象类 //该变量提供成员控制渐变色、渐变符号专题图的制作 IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass(); //确定分级渲染的属性字段 classBreaksRenderer.Field = "年"; //分级数量 classBreaksRenderer.BreakCount = classCount; //指示该专题图是否按升序显示 classBreaksRenderer.SortClassesAscending = true; //简单填充符号(ISimpleFillSymbol) //该变量提供对成员的访问, 控制简单的填充符号 ISimpleFillSymbol simpleFillSymbol; //通过一个循环, 给所有渲染的等级附上渲染颜色 for (int i = 0; i < myclasses.Length; i++) { color = pEnumColors.Next(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; //设置填充的样式(Style)为实体填充 simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; //指定分级渲染的符号(Symbol) classBreaksRenderer.set_Symbol(i, simpleFillSymbol as ISymbol); //按照分级进行渲染 classBreaksRenderer.set_Break(i, myclasses[i]); } if (pGeoFeatureLayer != null) { //调用Renderer属性, 具体说明如何通过图层要素渲染器绘制图层 pGeoFeatureLayer.Renderer = classBreaksRenderer as IFeatureRenderer; } axMapControl1.Refresh(); //刷新axMapControl1 axTOCControl1.Update(); //更新axTOCControl1 }
public ClassRender(AxMapControl pMapControl, String LayerName, int ClassCount, string Field) { IGeoFeatureLayer pGeolayer; ILayer pLayer; IActiveView pActiveView; IEnumLayer pEnumLayer; pEnumLayer = pMapControl.Map.get_Layers(null, true); if (pEnumLayer == null) { return; } pEnumLayer.Reset(); int i = 0; int LayerIndex = -1; for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next()) { i++; if (pLayer.Name == LayerName) { LayerIndex = i - 1; break; } } if (LayerIndex == -1) { MessageBox.Show("没有找到要渲染的图层"); return; } pGeolayer = pMapControl.Map.get_Layer(LayerIndex) as IGeoFeatureLayer; pActiveView = pMapControl.ActiveView; //以下是为了统计和分类所需要的对象 ITable pTable; IClassifyGEN pClassify; //C#要用这个不同于VB中的,分类对象。 ITableHistogram pTableHist; //相当于一个统计表 IBasicHistogram pBasicHist; //这个对象有一个很重要的方法 double[] ClassNum; int ClassCountResult;//返回分类个数。 IHsvColor pFromColor; IHsvColor pToColor;//用于构建另外一个颜色带对象。 IAlgorithmicColorRamp pAlgo; pTable = pGeolayer as ITable; IMap pMap; pMap = pMapControl.Map; pMap.ReferenceScale = 0; pBasicHist = new BasicTableHistogramClass();//也可以实例化 pTableHist。学会这个灵活的思维 pTableHist = pBasicHist as ITableHistogram; pTableHist.Table = pTable; pTableHist.Field = Field; object datavalus; object Frenquen; pBasicHist.GetHistogram(out datavalus, out Frenquen);//获得数据和相应的频数。 pClassify = new EqualIntervalClass(); try { pClassify.Classify(datavalus, Frenquen, ref ClassCount); } catch (Exception e) { MessageBox.Show(e.Message); } // 分类完成 ClassNum = (double[])pClassify.ClassBreaks; ClassCountResult = ClassNum.GetUpperBound(0);//返回分级个数。 IClassBreaksRenderer pClassBreak; pClassBreak = new ClassBreaksRendererClass(); pClassBreak.Field = Field; pClassBreak.BreakCount = ClassCountResult; pClassBreak.SortClassesAscending = true; pAlgo = new AlgorithmicColorRampClass(); pAlgo.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pFromColor = Hsv(60, 100, 96); pToColor = Hsv(0, 100, 96); pAlgo.FromColor = pFromColor; pAlgo.ToColor = pToColor; pAlgo.Size = ClassCountResult; bool ok; pAlgo.CreateRamp(out ok); IEnumColors pEnumColor; pEnumColor = pAlgo.Colors; pEnumColor.Reset(); IColor pColor; ISimpleFillSymbol pSimFill; /* IRgbColor[] pRgbColor;//可以构造颜色 * * pRgbColor = new IRgbColor[ClassCountResult]; * * for (int j = 0; j < ClassCountResult; j++) * { * int R = 50; * * int G = 100; * * int B = 50; * * R = R + 50; * * if (R > 250) * { * R = 50; * } * if (G > 250) * { * G = 100; * } * if (B > 250) * { * B = 50; * } * * G = G + 100; * * B = B + 50; * * * * pRgbColor[j] = ColorRgb(R, G, B); * * } */ for (int indexColor = 0; indexColor <= ClassCountResult - 1; indexColor++) { pColor = pEnumColor.Next(); pSimFill = new SimpleFillSymbolClass(); pSimFill.Color = pColor; // pSimFill.Color = pRgbColor[indexColor ]; pSimFill.Style = esriSimpleFillStyle.esriSFSSolid; //染色 pClassBreak.set_Symbol(indexColor, pSimFill as ISymbol); pClassBreak.set_Break(indexColor, ClassNum[indexColor + 1]); } pGeolayer.Renderer = pClassBreak as IFeatureRenderer; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); new MainForm().axTOCControl1.Update(); }
/// <summary> /// 分级色彩渲染 /// </summary> /// <param name="pMapControl"></param> /// <param name="pFtLayer"></param> /// <param name="ClassCount"></param> /// <param name="pFieldName"></param> public static void ClassRender(IActiveView activeView, IFeatureLayer pFtLayer, int ClassCount, string pFieldName) { IGeoFeatureLayer pGeolayer; IActiveView pActiveView; pGeolayer = pFtLayer as IGeoFeatureLayer; //以下是为了统计和分类所需要的对象 ITable pTable; IClassifyGEN pClassify; //C\#要作为分类对象。 ITableHistogram pTableHist; //相当于一个统计表 IBasicHistogram pBasicHist; //这个对象有一个很重要的方法 double[] ClassNum = new double[6]; int ClassCountResult; //返回分类个数。 IHsvColor pFromColor; IRgbColor pToColor; //用于构建另外一个颜色带对象。 IAlgorithmicColorRamp pAlgo; ITable pTable = pGeolayer as ITable; pBasicHist = new BasicTableHistogramClass(); //也可以实例化pTableHist pTableHist = pBasicHist as ITableHistogram; pTableHist.Table = pTable; pTableHist.Field = pFieldName; object datavalus; object Frenquen; pBasicHist.GetHistogram(out datavalus, out Frenquen); //获得数据和相应的频数。 pClassify = new EqualIntervalClass(); try { pClassify.Classify(datavalus, Frenquen, ref ClassCount); } catch (Exception e) { MessageBox.Show(e.Message); } // 分类完成 //ClassNum = (double[])pClassify.ClassBreaks;\ ClassNum[0] = 10.0; ClassNum[1] = 50.0; ClassNum[2] = 100.0; ClassNum[3] = 1000.0; ClassNum[4] = 10000.0; ClassNum[5] = 80000.0; ClassCountResult = ClassNum.GetUpperBound(0); //返回分级个数。 IClassBreaksRenderer pClassBreak; pClassBreak = new ClassBreaksRendererClass(); pClassBreak.Field = pFieldName; pClassBreak.BreakCount = ClassCountResult; pClassBreak.SortClassesAscending = true; IAlgorithmicColorRamp pAlgo = new AlgorithmicColorRampClass(); pAlgo.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; IColor pFromColor = GetRgbColor(255, 240, 240); pToColor = GetRgbColor(255, 0, 0); pAlgo.FromColor = pFromColor; pAlgo.ToColor = pToColor; pAlgo.Size = ClassCountResult; bool ok; pAlgo.CreateRamp(out ok); IEnumColors pEnumColor; pEnumColor = pAlgo.Colors; pEnumColor.Reset(); IColor pColor; ISimpleFillSymbol pSimFill; for (int indexColor = 0; indexColor <= ClassCountResult - 1; indexColor++) { pColor = pEnumColor.Next(); pSimFill = new SimpleFillSymbolClass(); pSimFill.Color = pColor; // pSimFill.Color = pRgbColor[indexColor ]; pSimFill.Style = esriSimpleFillStyle.esriSFSSolid; //染色 pClassBreak.set_Symbol(indexColor, pSimFill as ISymbol); pClassBreak.set_Break(indexColor, ClassNum[indexColor + 1]); } pGeolayer.Renderer = pClassBreak as IFeatureRenderer; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
private void polygonClassificationDye(ILayer pLayer) { IGeoFeatureLayer pGeoFeatureLayer; ITable pTable; IClassifyGEN pClassify; ITableHistogram pTableHistogram; IBasicHistogram pHistogram; object dataFrequency; object dataValues; double[] Classes; int ClassesCount; IClassBreaksRenderer pClassBreakRenderer; IHsvColor pFromColor; IHsvColor pToColor; IAlgorithmicColorRamp pAIgorithmicCR; IEnumColors pEnumColors; bool ok; IColor pColor; ISimpleFillSymbol pSimpleFillS; int IbreakIndex; string strPopFiled = cbField1.Text; int numDesiredClasses; try { numDesiredClasses = int.Parse(textBox1.Text.ToString()); } catch { MessageBox.Show("请输入分级个数"); return; } IMap pMap = axMapControl1.Map; pMap.ReferenceScale = 0; pGeoFeatureLayer = pLayer as IGeoFeatureLayer; //从pTable的id字段中得到信息给dataValues和dataFrequency两个数组 pTable = (ITable)pGeoFeatureLayer.FeatureClass; pTableHistogram = new BasicTableHistogramClass(); pHistogram = (IBasicHistogram)pTableHistogram; pTableHistogram.Field = strPopFiled; pTableHistogram.Table = pTable; pHistogram.GetHistogram(out dataValues, out dataFrequency); //下面是分级方法,用于根据获取的值计算出符号要求的数据 pClassify = new EqualIntervalClass(); try { pClassify.Classify(dataValues, dataFrequency, ref numDesiredClasses); } catch (Exception ex) { MessageBox.Show(ex.Message); } //返回一个数组 Classes = (double[])pClassify.ClassBreaks; ClassesCount = Classes.GetUpperBound(0); pClassBreakRenderer = new ClassBreaksRendererClass(); pClassBreakRenderer.Field = strPopFiled; //设置着色对象的分级数目 pClassBreakRenderer.BreakCount = ClassesCount; pClassBreakRenderer.SortClassesAscending = true; //产生分级着色需要的颜色带对象的起止颜色对象 pFromColor = new HsvColorClass(); pFromColor.Hue = 60; pFromColor.Saturation = 100; pFromColor.Value = 96; pToColor = new HsvColorClass(); pToColor.Hue = 0; pToColor.Saturation = 100; pToColor.Value = 96; //产生颜色带对象 pAIgorithmicCR = new AlgorithmicColorRampClass(); pAIgorithmicCR.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pAIgorithmicCR.FromColor = pFromColor; pAIgorithmicCR.ToColor = pToColor; pAIgorithmicCR.Size = ClassesCount; pAIgorithmicCR.CreateRamp(out ok); //获得颜色 pEnumColors = pAIgorithmicCR.Colors; //分类着色对象中的symbol和break的下标是从0开始 for (IbreakIndex = 0; IbreakIndex <= ClassesCount - 1; IbreakIndex++) { pColor = pEnumColors.Next(); pSimpleFillS = new SimpleFillSymbolClass(); pSimpleFillS.Color = pColor; pSimpleFillS.Style = esriSimpleFillStyle.esriSFSSolid; //这里是构造函数不同颜色着色的方法 pClassBreakRenderer.set_Symbol(IbreakIndex, (ISymbol)pSimpleFillS); //着色对象的断点 pClassBreakRenderer.set_Break(IbreakIndex, Classes[IbreakIndex + 1]); } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreakRenderer; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public static void Symbology_GraduatedColors(IFeatureLayer featureLayer, string fieldName, int numClasses, IMapControl2 mapControl, AxTOCControl tocControl) { // 获取渲染字段的值及其出现的频率 ITable pTable = featureLayer as ITable; IBasicHistogram pBasicHistogram = new BasicTableHistogramClass() { Field = fieldName, Table = pTable }; object dataFrequency, dataValue; // 频率和值 pBasicHistogram.GetHistogram(out dataValue, out dataFrequency); // 数据分级 IClassifyGEN pClassifyGEN = new EqualIntervalClass(); // 等间隔 //IClassifyGEN pClassifyGEN = new GeometricalIntervalClass(); // 几何间隔 //IClassifyGEN pClassifyGEN = new NaturalBreaksClass(); // 自然裂变 //IClassifyGEN pClassifyGEN = new QuantileClass(); // 分位数 //IClassifyGEN pClassifyGEN = new StandardDeviationClass(); // 标准偏差 try { pClassifyGEN.Classify(dataValue, dataFrequency, numClasses); } catch { } double[] Classes = pClassifyGEN.ClassBreaks as double[]; int ClassesCount = Classes.GetUpperBound(0); IClassBreaksRenderer pRenderer = new ClassBreaksRendererClass() { // 分类字段 分类数目 升序 Field = fieldName, BreakCount = ClassesCount, SortClassesAscending = true }; // 生成颜色色带 IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRamp() { FromColor = GetRgbColor(255, 200, 200), ToColor = GetRgbColor(255, 0, 0), Size = ClassesCount }; bool bOk = false; pColorRamp.CreateRamp(out bOk); IEnumColors pColors = pColorRamp.Colors; // 逐一设置填充符号及每一分级的分级断点 for (int index = 0; index < ClassesCount; index++) { IColor pColor = pColors.Next(); ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pColor }; break; } pRenderer.set_Symbol(index, pSymbol); // 每级的符号 pRenderer.set_Break(index, Classes[index + 1]); // 每级的断点 } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }
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 IClassBreaksRenderer CreateClassBreaksRenderer(IFeatureClass featureClass) { classify(); if (gClassbreaks == null) { MessageBox.Show("请先分类...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return null; } 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; pClassBreaksRenderer.BackgroundSymbol = fillSymbol; IMarkerSymbol symbol = null; if (markerSymbol == null) { MessageBox.Show("请先选择点符号", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return null; } //需要注意的是分级着色对象中的symbol和break的下标都是从0开始 double sizeInterval = (maxSize - minSize) / ClassesCount; for (int i = 0; i < ClassesCount; i++) { symbol = markerSymbol; symbol.Size = minSize + i * sizeInterval; pClassBreaksRenderer.set_Symbol(i, symbol as ISymbol); pClassBreaksRenderer.set_Break(i, gClassbreaks[i + 1]); } return pClassBreaksRenderer; }
private void resultSymbologyTab() { IGeoFeatureLayer pGeoFeatureLayer = this.pLayer as IGeoFeatureLayer; TreeNode currentNode = this.trvSymbologyShows.SelectedNode; if (currentNode.Text == "单一符号") { if (this.singleSymbol == null) { return; } ISimpleRenderer pSimpleRender = new SimpleRendererClass(); pSimpleRender.Symbol = this.singleSymbol; pSimpleRender.Label = this.txtSingleSymbolLabel.Text; pSimpleRender.Description = this.txtSingleSymbolDescription.Text; pGeoFeatureLayer.Renderer = pSimpleRender as IFeatureRenderer; } else if (currentNode.Text == "唯一值") { if (this.lsvUniqueValue.Items.Count == 0 || this.pUniValueColorRamp == null) { return; } this.pUniValueColorRamp.Size = this.lsvUniqueValue.Items.Count - 1; bool IsColorRampCreatedOK = false; this.pUniValueColorRamp.CreateRamp(out IsColorRampCreatedOK); if (IsColorRampCreatedOK) { IEnumColors pEnumColors = pUniValueColorRamp.Colors; pEnumColors.Reset(); IUniqueValueRenderer pUniqueValueRender = new UniqueValueRendererClass(); pUniqueValueRender.FieldCount = 1; pUniqueValueRender.set_Field(0, this.cbbUniValueField.Text); IColor pColor; if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolygon) { ISimpleFillSymbol pSimpleFillSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleFillSymbol); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolyline) { ISimpleLineSymbol pSimpleLineSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleLineSymbol); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPoint) { ISimpleMarkerSymbol pSimpleMarkerSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleMarkerSymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRender; } } else if (currentNode.Text == "分级颜色") { if (this.lsvClassBreaksSymbol.Items.Count == 0 || this.pClassBreaksColorRamp == null) { return; } int classCount = int.Parse(this.cbbClassBreaksCount.Text); IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.BreakCount = classCount; pClassBreaksRenderer.Field = this.cbbClassBreakField.Text; pClassBreaksRenderer.SortClassesAscending = true; IColorRamp pColorRamp = this.pClassBreaksColorRamp; pColorRamp.Size = classCount; bool ok; pColorRamp.CreateRamp(out ok); if (!ok) { return; } IEnumColors pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); IColor pColor; if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolygon) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号(此处为SimpleFillSymbol) { pColor = pEnumColors.Next(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]);//设置临界值,注意下标,关键!!! pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleFillSymbol);//设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Description(i, this.lsvClassBreaksSymbol.Items[i].Text); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolyline) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号 { pColor = pEnumColors.Next(); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Color = pColor; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleLineSymbol);//设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]);//设置临界值,注意下标,关键!!! } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPoint) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号 { pColor = pEnumColors.Next(); ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Color = pColor; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleMarkerSymbol);//设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]);//设置临界值,注意下标,关键!!! } } pGeoFeatureLayer.Renderer = pClassBreaksRenderer as IFeatureRenderer; } }
// 分级色彩符号化 public static void GraduatedColors(IFeatureLayer featureLayer, string fieldName, int numClasses, IMapControl2 mapControl, AxTOCControl tocControl) { object dataFrequency; object dataValue; int breakIndex; ITable pTable = featureLayer.FeatureClass as ITable; ITableHistogram pTableHistogram = new BasicTableHistogramClass() { Field = fieldName, Table = pTable }; IBasicHistogram pBasicHistogram = (IBasicHistogram)pTableHistogram; // 获取渲染字段的值及其出现的频率 pBasicHistogram.GetHistogram(out dataValue, out dataFrequency); IClassifyGEN pClassifyGEN = new EqualIntervalClass(); try { pClassifyGEN.Classify(dataValue, dataFrequency, ref numClasses); } catch { } // 返回一个数组 double[] Classes = pClassifyGEN.ClassBreaks as double[]; int ClassesCount = Classes.GetUpperBound(0); IClassBreaksRenderer pRenderer = new ClassBreaksRendererClass() { // 分级字段 分级数目 分级后的图例是否按升级顺序排序 Field = fieldName, BreakCount = ClassesCount, SortClassesAscending = true }; // 设置分级说色所需颜色带的起止颜色 //IHsvColor pFromColor = GetHsvColor(0, 50, 96); //IHsvColor pToColor = GetHsvColor(80, 100, 96); IRgbColor pFromColor = GetRgbColor(255, 200, 200); IRgbColor pToColor = GetRgbColor(255, 0, 0); // 生成颜色带对象 IAlgorithmicColorRamp pColorRamp = CreateColorRamp(pFromColor, pToColor, ClassesCount); // 获取色带颜色集 IEnumColors pEnumColors = pColorRamp.Colors; // 逐一设置填充符号及每一分级的分级断点 for (breakIndex = 0; breakIndex < ClassesCount; breakIndex++) { IColor pColor = pEnumColors.Next(); ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pColor, Style = esriSimpleFillStyle.esriSFSSolid }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pColor }; break; } // 设置填充符号 pRenderer.set_Symbol(breakIndex, pSymbol); // 设置每一级的分级断点 pRenderer.set_Break(breakIndex, Classes[breakIndex + 1]); } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }
/// <summary> /// 分级符号渲染矢量数据 /// </summary> /// <param name="pFeatureLayer"></param> /// <param name="mField"></param> public void SimpleRenderByColor(IFeatureLayer pFeatureLayer, string mField) { //分5类 int breakCount = 5; try { var pGeoFeatureLayer = (IGeoFeatureLayer)pFeatureLayer; //计算最大最小值 var pTable = (ITable)pGeoFeatureLayer; if (pTable.FindField(mField) == -1) { MessageBox.Show("此类型水质数据不存在"); return; } IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(""); var pCursor = pTable.Search(pQueryFilter, true); //获取统计结果 IDataStatistics pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pCursor; //设置要统计字段的名称 pDataStatistics.Field = mField; //获取统计的结果 //背景色 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = GetColor(0, 0, 0); //点符号样式 ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Outline = true; pSimpleMarkerSymbol.OutlineColor = GetColor(0, 0, 0); //分级符号 //获取统计数据及频率 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = mField; pTableHistogram.Table = pTable; object dataValue, dataFrequency; IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHistogram(out dataValue, out dataFrequency); IClassifyGEN pClassifyGen = new NaturalBreaksClass(); //产生种类 pClassifyGen.Classify(dataValue, dataFrequency, ref breakCount); object ob = pClassifyGen.ClassBreaks; double[] classes = (double[])ob; int classesCount = classes.Length; //定义分类渲染 IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = mField; pClassBreaksRenderer.BreakCount = classesCount; pClassBreaksRenderer.SortClassesAscending = true; pClassBreaksRenderer.MinimumBreak = classes[0]; //设置要素颜色 IColor pColor = GetColor(0, 217, 0); for (int i = 0; i < classesCount; i++) { ISimpleFillSymbol pFillSymbol1 = new SimpleFillSymbolClass(); pSimpleMarkerSymbol.Color = pColor; pFillSymbol1.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleMarkerSymbol.Size = 2 * (i + 1); pClassBreaksRenderer.BackgroundSymbol = pFillSymbol1; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleMarkerSymbol); pClassBreaksRenderer.set_Break(i, classes[i]); } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer; this._pMap.AddLayer(pGeoFeatureLayer); IActiveView pActiveView = _pMap as IActiveView; if (pActiveView != null) { pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); pActiveView.Extent = pActiveView.FullExtent; } } catch (Exception e) { MessageBox.Show("渲染出错!\n" + e.ToString()); } }
private IClassBreaksRenderer CreateClassBreaksRenderer(IFeatureClass featureClass, string breakMethod) { ITable pTable = (ITable)featureClass; //从pTable的strRendererField字段中得到信息给datavalues和datafrequency两个数组 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; pTableHistogram.Field = strRendererField; if (strNormalizeField.ToLower() != "none") { pTableHistogram.NormField = strNormalizeField; } pTableHistogram.Table = pTable; object dataFrequency; object dataValues; pHistogram.GetHistogram(out dataValues, out dataFrequency); //下面是分级方法,用于根据获得的值计算得出符合要求的数据 //根据条件计算出Classes和ClassesCount,numDesiredClasses为预定的分级数目 IClassifyGEN pClassify = null; int numDesiredClasses = classCount; switch (breakMethod) { case "等间隔": pClassify = new EqualIntervalClass(); break; case "已定义的间隔": pClassify = new DefinedIntervalClass(); IIntervalRange2 intervalRange = pClassify as IIntervalRange2; intervalRange.IntervalRange = dblDefinedInterval; break; case "分位数": pClassify = new QuantileClass(); break; case "自然裂点": pClassify = new NaturalBreaksClass(); break; case "标准差": pClassify = new StandardDeviationClass(); IStatisticsResults pStatRes = pHistogram as IStatisticsResults; IDeviationInterval pStdDev = pClassify as IDeviationInterval; pStdDev.Mean = pStatRes.Mean; pStdDev.StandardDev = pStatRes.StandardDeviation; pStdDev.DeviationInterval = dblStdDevInterval; break; default: break; } if (pClassify == null) { return(null); } pClassify.Classify(dataValues, dataFrequency, ref numDesiredClasses); //返回一个数组 double[] classBreaks = (double[])pClassify.ClassBreaks; int ClassesCount = classBreaks.GetUpperBound(0); nudClassCount.Value = ClassesCount; IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = strRendererField; if (strNormalizeField.ToLower() != "none") { pClassBreaksRenderer.NormField = strNormalizeField; } //设置着色对象的分级数目 pClassBreaksRenderer.BreakCount = ClassesCount; pClassBreaksRenderer.SortClassesAscending = true; if (colorRamp == null) { MessageBox.Show("请先选择色带!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } //通过色带设置各级分类符号的颜色 colorRamp.Size = ClassesCount; bool createRamp; colorRamp.CreateRamp(out createRamp); IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); IColor pColor = null; ISymbol symbol = null; if (gloabalSymbol == null) { MessageBox.Show("请选择符号...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } //需要注意的是分级着色对象中的symbol和break的下标都是从0开始 for (int i = 0; i < ClassesCount; i++) { pColor = enumColors.Next(); switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: IMarkerSymbol markerSymbol = gloabalSymbol as IMarkerSymbol; markerSymbol.Color = pColor; symbol = markerSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolyline: ILineSymbol lineSymbol = gloabalSymbol as ILineSymbol; lineSymbol.Color = pColor; symbol = lineSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolygon: IFillSymbol fillSymbol = gloabalSymbol as IFillSymbol; fillSymbol.Color = pColor; symbol = fillSymbol as ISymbol; break; default: break; } pClassBreaksRenderer.set_Symbol(i, symbol); pClassBreaksRenderer.set_Break(i, classBreaks[i + 1]); } return(pClassBreaksRenderer); }
public void GraduatedColors(IFeatureLayer pfeatLyr, string sFieldName, int numclasses) { IGeoFeatureLayer pGeoFeatureL = pfeatLyr as IGeoFeatureLayer; object dataFrequency; object dataValues; bool ok; int breakIndex; ITable pTable = pGeoFeatureL.FeatureClass as ITable;//各个字段变成一个表 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); IBasicHistogram pBasicHistogram = (IBasicHistogram)pTableHistogram; pTableHistogram.Field = sFieldName; pTableHistogram.Table = pTable; pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);//获取渲染值及其出现的频率 IClassifyGEN pClassify = new EqualIntervalClass(); pClassify.Classify(dataValues, dataFrequency, ref numclasses);//进行等级划分 double[] Classes = pClassify.ClassBreaks as double[]; int classescount = Classes.GetUpperBound(0); IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = sFieldName; //分段字段 pClassBreaksRenderer.BreakCount = classescount; //设置分级数目 pClassBreaksRenderer.SortClassesAscending = true; //分机后的图例是否按升级顺序排列 //分级颜色带的开始颜色和结束颜色(即分级颜色在此范围内) IHsvColor pFromColor = new HsvColorClass(); //起始颜色 pFromColor.Hue = 0; //黄色 pFromColor.Saturation = 50; pFromColor.Value = 96; IHsvColor ptocolor = new HsvColorClass(); //终止颜色 ptocolor.Hue = 80; //不知道什么颜色 ptocolor.Saturation = 100; ptocolor.Value = 96; //产生颜色带对象 IAlgorithmicColorRamp pAlgorithmicColorRamp = new AlgorithmicColorRampClass(); pAlgorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pAlgorithmicColorRamp.FromColor = pFromColor; pAlgorithmicColorRamp.ToColor = ptocolor; pAlgorithmicColorRamp.Size = classescount; pAlgorithmicColorRamp.CreateRamp(out ok); //获得颜色 IEnumColors pEnumColors = pAlgorithmicColorRamp.Colors; //symbol和break下标从0开始 for (breakIndex = 0; breakIndex <= classescount - 1; breakIndex++) { IColor pColor = pEnumColors.Next(); switch (pGeoFeatureL.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: { ISimpleFillSymbol pSimpleFills = new SimpleFillSymbolClass(); pSimpleFills.Color = pColor; pSimpleFills.Style = esriSimpleFillStyle.esriSFSSolid; pClassBreaksRenderer.set_Symbol(breakIndex, (ISymbol)pSimpleFills); //设置填充符号 pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]); //设定每一分级的分级断点 break; } case esriGeometryType.esriGeometryPolyline: { ISimpleLineSymbol pSimplelines = new SimpleLineSymbolClass(); pSimplelines.Color = pColor; pClassBreaksRenderer.set_Symbol(breakIndex, (ISymbol)pSimplelines); //设置填充符号 pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]); //设定每一分级的分级断点 break; } case esriGeometryType.esriGeometryPoint: { ISimpleMarkerSymbol pSimplemaker = new SimpleMarkerSymbolClass(); pSimplemaker.Color = pColor; pClassBreaksRenderer.set_Symbol(breakIndex, (ISymbol)pSimplemaker); //设置填充符号 pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]); //设定每一分级的分级断点 break; } } } pGeoFeatureL.Renderer = (IFeatureRenderer)pClassBreaksRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); }
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(); }
void ClassifyColor() { IGeoFeatureLayer geoFeatureLayer = mapControl.Map.get_Layer(17) as IGeoFeatureLayer; string a = geoFeatureLayer.Name; object dataFrequency, dataValues; ITableHistogram tableHistogram = new BasicTableHistogramClass(); IBasicHistogram basicHistogram = (IBasicHistogram)tableHistogram; tableHistogram.Field = cmbSelField.Text; tableHistogram.Table = geoFeatureLayer.FeatureClass as ITable; basicHistogram.GetHistogram(out dataValues, out dataFrequency); IClassifyGEN classifyGEN = new EqualIntervalClass(); classifyGEN.Classify(dataValues, dataFrequency, Convert.ToInt32(cmbnumclasses.Text)); double[] classes = classifyGEN.ClassBreaks as double[]; int classesCount = classes.GetUpperBound(0); IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass(); classBreaksRenderer.Field = cmbSelField.Text; classBreaksRenderer.BreakCount = classesCount; classBreaksRenderer.SortClassesAscending = true; IHsvColor fromColor = new HsvColorClass(); fromColor.Hue = 0; fromColor.Saturation = 50; fromColor.Value = 96; IHsvColor toColor = new HsvColorClass(); toColor.Hue = 80; toColor.Saturation = 100; toColor.Value = 96; bool ok; //产生色带 IAlgorithmicColorRamp algorithmicCR = new AlgorithmicColorRampClass(); algorithmicCR.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; algorithmicCR.FromColor = fromColor; algorithmicCR.ToColor = toColor; algorithmicCR.Size = classesCount; algorithmicCR.CreateRamp(out ok); //获得颜色 IEnumColors enumColors = algorithmicCR.Colors; for (int breakIndex = 0; breakIndex <= classesCount - 1; breakIndex++) { IColor color = enumColors.Next(); ISimpleFillSymbol simpleFill = new SimpleFillSymbolClass(); simpleFill.Color = color; simpleFill.Style = esriSimpleFillStyle.esriSFSSolid; classBreaksRenderer.set_Symbol(breakIndex, (ISymbol)simpleFill); classBreaksRenderer.set_Break(breakIndex, classes[breakIndex + 1]); } geoFeatureLayer.Renderer = (IFeatureRenderer)classBreaksRenderer; mapControl.Refresh(); mapControl.ActiveView.Refresh(); tocControl.Update(); }
public ClassRender(AxMapControl pMapControl, IFeatureLayer pFtLayer, int ClassCount, string pFieldName) { IGeoFeatureLayer pGeolayer; IActiveView pActiveView; pGeolayer = pFtLayer as IGeoFeatureLayer; pActiveView = pMapControl.ActiveView; //������Ϊ��ͳ�ƺͷ�������Ҫ�Ķ��� ITable pTable; IClassifyGEN pClassify;//C#Ҫ�������ͬ��VB�еģ�������� ITableHistogram pTableHist;//�൱��һ��ͳ�Ʊ� IBasicHistogram pBasicHist;//���������һ������Ҫ�ķ��� double[] ClassNum; int ClassCountResult;//���ط�������� IHsvColor pFromColor; IHsvColor pToColor;//���ڹ�������һ����ɫ������ IAlgorithmicColorRamp pAlgo; pTable = pGeolayer as ITable; IMap pMap; pMap = pMapControl.Map; pMap.ReferenceScale = 0; pBasicHist = new BasicTableHistogramClass();//Ҳ����ʵ���� pTableHist��ѧ���������˼ά pTableHist = pBasicHist as ITableHistogram; pTableHist.Table = pTable; pTableHist.Field = pFieldName; object datavalus; object Frenquen; pBasicHist.GetHistogram(out datavalus,out Frenquen);//������ݺ���Ӧ��Ƶ���� pClassify = new EqualIntervalClass(); try { pClassify.Classify(datavalus, Frenquen, ref ClassCount); } catch (Exception e) { MessageBox.Show(e.Message); } // ������� ClassNum = (double[])pClassify.ClassBreaks; ClassCountResult = ClassNum.GetUpperBound(0);//���طּ������� IClassBreaksRenderer pClassBreak; pClassBreak = new ClassBreaksRendererClass(); pClassBreak.Field = pFieldName; pClassBreak.BreakCount = ClassCountResult; pClassBreak.SortClassesAscending = true; pAlgo = new AlgorithmicColorRampClass(); pAlgo.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pFromColor = Hsv(60, 100, 96); pToColor = Hsv(0, 100, 96); pAlgo.FromColor = pFromColor; pAlgo.ToColor = pToColor; pAlgo.Size = ClassCountResult; bool ok; pAlgo.CreateRamp(out ok); IEnumColors pEnumColor; pEnumColor = pAlgo.Colors; pEnumColor.Reset(); IColor pColor; ISimpleFillSymbol pSimFill; /* IRgbColor[] pRgbColor;//���Թ�����ɫ pRgbColor = new IRgbColor[ClassCountResult]; for (int j = 0; j < ClassCountResult; j++) { int R = 50; int G = 100; int B = 50; R = R + 50; if (R > 250) { R = 50; } if (G > 250) { G = 100; } if (B > 250) { B = 50; } G = G + 100; B = B + 50; pRgbColor[j] = ColorRgb(R, G, B); } */ for (int indexColor = 0; indexColor <= ClassCountResult - 1; indexColor++) { pColor = pEnumColor.Next(); pSimFill = new SimpleFillSymbolClass(); pSimFill.Color = pColor; // pSimFill.Color = pRgbColor[indexColor ]; pSimFill.Style = esriSimpleFillStyle.esriSFSSolid; //Ⱦɫ pClassBreak.set_Symbol(indexColor, pSimFill as ISymbol); pClassBreak.set_Break(indexColor, ClassNum[indexColor + 1]); } pGeolayer.Renderer = pClassBreak as IFeatureRenderer; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
/// <summary> /// Class Break Render /// </summary> /// <param name="currentLayer"></param> /// <param name="breakCount"></param> /// <author>Shen Yongyuan</author> /// <date>20091114</date> public static void ClassBreakRender(ILayer currentLayer, int breakCount, string fieldName, ref double[] Classes, ref int[] Colors, bool reverse) { //Get All Value object dataFrequency = null; object dataValues = null; ITableHistogram pTableHistogram = new BasicTableHistogramClass(); IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; pTableHistogram.Field = fieldName; pTableHistogram.Table = (currentLayer as IGeoFeatureLayer).DisplayFeatureClass as ITable; pHistogram.GetHistogram(out dataValues, out dataFrequency); //Class IClassifyGEN pClassify = new EqualIntervalClass(); pClassify.Classify(dataValues, dataFrequency, ref breakCount); //Set Class Breaks Classes = (double[])pClassify.ClassBreaks; int ClassesCount = Classes.GetUpperBound(0); IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = fieldName; //Set From to Color IHsvColor pFromColor = new HsvColorClass(); pFromColor.Hue = reverse ? 105 : 353; pFromColor.Saturation = reverse ? 46 : 56; pFromColor.Value = reverse ? 76 : 92; IHsvColor pToColor = new HsvColorClass(); pToColor.Hue = reverse ? 353 : 105; pToColor.Saturation = reverse ? 56 : 46; pToColor.Value = reverse ? 92 : 76; //Get Color IAlgorithmicColorRamp pAlgorithmicCR = new AlgorithmicColorRampClass(); pAlgorithmicCR.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pAlgorithmicCR.FromColor = pFromColor; pAlgorithmicCR.ToColor = pToColor; pAlgorithmicCR.Size = ClassesCount; bool ok = false; pAlgorithmicCR.CreateRamp(out ok); IEnumColors pEnumColors = pAlgorithmicCR.Colors; //Set Break Count pClassBreaksRenderer.BreakCount = ClassesCount; pClassBreaksRenderer.SortClassesAscending = true; //Set Break Interval for (int lbreakIndex = 0; lbreakIndex <= ClassesCount - 1; lbreakIndex++) { IColor pColor = pEnumColors.Next(); Colors[lbreakIndex] = pColor.RGB; ISimpleFillSymbol pSimpleFillS = new SimpleFillSymbolClass(); pSimpleFillS.Color = pColor; pSimpleFillS.Style = esriSimpleFillStyle.esriSFSSolid; pClassBreaksRenderer.set_Symbol(lbreakIndex, (ISymbol)pSimpleFillS); pClassBreaksRenderer.set_Break(lbreakIndex, Classes[lbreakIndex + 1]); } //Set Render (currentLayer as IGeoFeatureLayer).Renderer = pClassBreaksRenderer as IFeatureRenderer; }
private void btnClassBreakRender_Click(object sender, EventArgs e) { //先用一个ITableHistogram对象从一个要素类获取某一字段的所有值及频率,即dataValues和dataFrequency,这两个数组是分组的基本数据 //取得两个数组后,系统用IClassGEN对象对它们进行分级,得到classes及classCount,前者是分级临界点值的数组,后者为分级数目 //根据得到的分级数目和颜色带对象,可以分别设置ClassBreakRender对象的不同符号,产生不同的效果 IGeoFeatureLayer pGeoFeatLyr; ITable pTable; object dataValues; object dataFrequency; string strOutput; pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer; pTable = pGeoFeatLyr as ITable; //以下代码用TableHistogram和BasicHistogram统计出Table某一字段的值和值的频率 ITableHistogram pTableHistogram; pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Table = pTable;//需传入一个ITable pTableHistogram.Field = "GDP_1999(";//统计的字段 IBasicHistogram pBasicHistogram; pBasicHistogram = pTableHistogram as IBasicHistogram; pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);//关键 //以下代码用IClassifyGEN和EqualInterval对象,基于分段数目,生成各段的临界值,并放在一个数组当中 IClassifyGEN pClassifyGen = new EqualIntervalClass(); double[] classes; int classCount = 5; pClassifyGen.Classify(dataValues, dataFrequency, ref classCount);//用到了上面ITableHistogram生成的值和值频率数组,关键!!!!!! classes = pClassifyGen.ClassBreaks as double[];//注意,此对象下标从1开始(我觉得0为最开头,所以临界值从1开始有意义),关键!!!!!! //classCount = classes.Length; 此处应该为6 //for (int i = 0; i < classes.Length; i++) //{ // MessageBox.Show(classes[i].ToString()); //} //MessageBox.Show(classCount.ToString()); IClassBreaksRenderer pClassBreakRenderer = new ClassBreaksRendererClass();//设置分段着色属性 pClassBreakRenderer.Field = "GDP_1999("; pClassBreakRenderer.BreakCount = 5;//分成5段 pClassBreakRenderer.SortClassesAscending = true; //以下代码生成颜色带 IHsvColor pFromColor = getHsvColor(60, 100, 96); IHsvColor pToColor = getHsvColor(0, 100, 96); IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass(); pColorRamp.FromColor = pFromColor as IColor; pColorRamp.ToColor = pToColor as IColor; pColorRamp.Size = classCount;//生成颜色的数目 //MessageBox.Show(classCount.ToString()); bool ok; pColorRamp.CreateRamp(out ok);//创建颜色带,关键!!! if (ok)//如果颜色带成功生成的话 { IEnumColors pEnumColors = pColorRamp.Colors;//存放生成颜色带的各颜色 pEnumColors.Reset();//是必须吗?????关键!!! IColor pColor; ISimpleFillSymbol pSimpleFillSymbol; //ISimpleMarkerSymbol pSimpleMarkerSymbol; for (int i = 0; i < classCount; i++)//为每个值范围设置符号(此处为SimpleFillSymbol) { pColor = pEnumColors.Next(); pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; //pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); //pSimpleMarkerSymbol.Color = pColor; pClassBreakRenderer.set_Symbol(i, (ISymbol)pSimpleFillSymbol);//设置Symbol,关键!!! pClassBreakRenderer.set_Break(i, classes[i + 1]);//设置临界值,注意下标,关键!!! } pGeoFeatLyr.Renderer = pClassBreakRenderer as IFeatureRenderer; this.mainMapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); //this.axTOCControl.SetBuddyControl(this.mainMapControl.Object); this.axTOCControl.Update(); } }
public void LayerRender() { try { //值分级 IBasicHistogram pBasicHis = new BasicTableHistogramClass(); ITableHistogram pTabHis = (ITableHistogram)pBasicHis; IClassifyGEN pClassify = null; switch (classname) { case "自然断点分级": pClassify = new NaturalBreaksClass(); break; case "等间距分级": pClassify = new EqualIntervalClass(); break; } pTabHis.Field = FiledName; //IGeoFeatureLayer geolayer = (IGeoFeatureLayer)Layer; ITable pTab = (ITable)Layer; pTabHis.Table = pTab; object doubleArrVal, longArrFreq; pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq); int nDes = count; pClassify.Classify(doubleArrVal, longArrFreq, ref nDes); object classes = pClassify.ClassBreaks; double[] ClassNum; ClassNum = (double[])pClassify.ClassBreaks; int ClassCountResult = ClassNum.GetUpperBound(0); IClassBreaksRenderer pRender = new ClassBreaksRendererClass(); pRender.BreakCount = ClassCountResult; pRender.Field = FiledName; ISimpleFillSymbol pSym; IColor pColor; for (int j = 0; j < ClassCountResult; j++) { pColor = ramp.get_Color(j * (ramp.Size / ClassCountResult)); pSym = new SimpleFillSymbolClass(); pSym.Color = pColor; pRender.set_Symbol(j, (ISymbol)pSym); pRender.set_Break(j, ClassNum[j + 1]); if (ClassNum[j].ToString().Contains(".")) { pRender.set_Label(j, ClassNum[j].ToString("0.000") + " - " + ClassNum[j + 1].ToString("0.000")); } else { pRender.set_Label(j, ClassNum[j].ToString() + " - " + ClassNum[j + 1].ToString()); } } IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Layer; pGeoLyr.Renderer = (IFeatureRenderer)pRender; axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); axtoccontrol.Update(); } catch (Exception e) { MessageBox.Show(e.Message); } }
//分级专题图 private void button2_Click(object sender, EventArgs e) { int classCount = 6; ITableHistogram tableHistogram; IBasicHistogram basicHistogram; ITable table; IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer("东丰县行政区域"); ILayer layer = geoFeatureLayer as ILayer; table = layer as ITable; tableHistogram = new BasicTableHistogramClass(); //按照 数值字段分级 tableHistogram.Table = table; tableHistogram.Field = "NAME"; 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 = "NAME"; 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(); }
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 resultSymbologyTab() { IGeoFeatureLayer pGeoFeatureLayer = this.pLayer as IGeoFeatureLayer; TreeNode currentNode = this.trvSymbologyShows.SelectedNode; if (currentNode.Text == "单一符号") { if (this.singleSymbol == null) { return; } ISimpleRenderer pSimpleRender = new SimpleRendererClass(); pSimpleRender.Symbol = this.singleSymbol; pSimpleRender.Label = this.txtSingleSymbolLabel.Text; pSimpleRender.Description = this.txtSingleSymbolDescription.Text; pGeoFeatureLayer.Renderer = pSimpleRender as IFeatureRenderer; } else if (currentNode.Text == "唯一值") { if (this.lsvUniqueValue.Items.Count == 0 || this.pUniValueColorRamp == null) { return; } this.pUniValueColorRamp.Size = this.lsvUniqueValue.Items.Count - 1; bool IsColorRampCreatedOK = false; this.pUniValueColorRamp.CreateRamp(out IsColorRampCreatedOK); if (IsColorRampCreatedOK) { IEnumColors pEnumColors = pUniValueColorRamp.Colors; pEnumColors.Reset(); IUniqueValueRenderer pUniqueValueRender = new UniqueValueRendererClass(); pUniqueValueRender.FieldCount = 1; pUniqueValueRender.set_Field(0, this.cbbUniValueField.Text); IColor pColor; if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolygon) { ISimpleFillSymbol pSimpleFillSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleFillSymbol); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolyline) { ISimpleLineSymbol pSimpleLineSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleLineSymbol); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPoint) { ISimpleMarkerSymbol pSimpleMarkerSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleMarkerSymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRender; } } else if (currentNode.Text == "分级颜色") { if (this.lsvClassBreaksSymbol.Items.Count == 0 || this.pClassBreaksColorRamp == null) { return; } int classCount = int.Parse(this.cbbClassBreaksCount.Text); IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.BreakCount = classCount; pClassBreaksRenderer.Field = this.cbbClassBreakField.Text; pClassBreaksRenderer.SortClassesAscending = true; IColorRamp pColorRamp = this.pClassBreaksColorRamp; pColorRamp.Size = classCount; bool ok; pColorRamp.CreateRamp(out ok); if (!ok) { return; } IEnumColors pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); IColor pColor; if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolygon) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号(此处为SimpleFillSymbol) { pColor = pEnumColors.Next(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]); //设置临界值,注意下标,关键!!! pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleFillSymbol); //设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Description(i, this.lsvClassBreaksSymbol.Items[i].Text); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolyline) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号 { pColor = pEnumColors.Next(); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Color = pColor; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleLineSymbol); //设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]); //设置临界值,注意下标,关键!!! } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPoint) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号 { pColor = pEnumColors.Next(); ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Color = pColor; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleMarkerSymbol); //设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]); //设置临界值,注意下标,关键!!! } } pGeoFeatureLayer.Renderer = pClassBreaksRenderer as IFeatureRenderer; } }