/// <summary> /// 设置分级算法 /// </summary> /// <param name="classProperties">栅格分级渲染属性</param> /// <param name="classMethod">分级算法</param> private static void SetClassMethod(IRasterClassifyUIProperties classProperties, string classMethod) { //分级方法初始化 IClassifyGEN pClassifyGen; //判断分级方法,以获取分段点 switch (classMethod) { case "Equal Interval": pClassifyGen = new EqualIntervalClass(); break; case "Natural Breaks": pClassifyGen = new NaturalBreaksClass(); break; case "Quantile": pClassifyGen = new QuantileClass(); break; case "Geometrical Interval": pClassifyGen = new GeometricalIntervalClass(); break; default: pClassifyGen = new NaturalBreaksClass(); break; } //获取分级算法UID classProperties.ClassificationMethod = pClassifyGen.ClassID; }
//分级专题图 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(); }
private void cboClassifyMethod_SelectedIndexChanged(object sender, EventArgs e) { IClassify classify; if (this.bool_0) { classify = null; switch (this.cboClassifyMethod.SelectedIndex) { case 0: classify = new EqualIntervalClass(); goto Label_0043; case 1: classify = new QuantileClass(); goto Label_0043; case 2: classify = new NaturalBreaksClass(); goto Label_0043; } } return; Label_0043: (this.iclassBreaksRenderer_0 as IClassBreaksUIProperties).Method = classify.ClassID; if (this.cboClassifyNum.SelectedIndex >= 0) { this.method_3(); } else { this.cboClassifyNum.SelectedIndex = 4; } }
private void classify() { if (layer2Symbolize == null) { return; } IFeatureClass featureClass = layer2Symbolize.FeatureClass; ITable pTable = (ITable)featureClass; 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 = new NaturalBreaksClass(); switch (strClassifyMethod) { case "等间隔分类": pClassify = new EqualIntervalClass(); break; //case "预定义间隔分类": // pClassify = new DefinedIntervalClass(); // break; case "分位数分类": pClassify = new QuantileClass(); break; case "自然裂点分类": pClassify = new NaturalBreaksClass(); break; case "标准差分类": pClassify = new StandardDeviationClass(); break; case "几何间隔分类": pClassify = new GeometricalIntervalClass(); break; default: break; } int numDesiredClasses = gClassCount; pClassify.Classify(dataValues, dataFrequency, ref numDesiredClasses); gClassbreaks = (double[])pClassify.ClassBreaks; }
private void btnClassiFy_Click(object sender, EventArgs e) { ITable pTable = this.pLayer as ITable; object dataValues; object dataFrequency; //以下代码用TableHistogram和BasicHistogram统计出Table某一字段的值和值的频率 ITableHistogram pTableHistogram; pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Table = pTable; //需传入一个ITable pTableHistogram.Field = this.cbbClassBreakField.Text; //统计的字段 IBasicHistogram pBasicHistogram; pBasicHistogram = pTableHistogram as IBasicHistogram; pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);//关键 //以下代码用IClassifyGEN和EqualInterval对象,基于分段数目,生成各段的临界值,并放在一个数组当中 IClassifyGEN pClassifyGEN; switch (this.cbbClassBreaksMethod.SelectedIndex) { case 0: pClassifyGEN = new EqualIntervalClass(); break; case 1: pClassifyGEN = new GeometricalIntervalClass(); break; case 2: pClassifyGEN = new NaturalBreaksClass(); break; case 3: pClassifyGEN = new QuantileClass(); break; default: pClassifyGEN = new EqualIntervalClass(); break; } //double[] classes; int classCount = int.Parse(this.cbbClassBreaksCount.Text); pClassifyGEN.Classify(dataValues, dataFrequency, ref classCount); //用到了上面ITableHistogram生成的值和值频率数组,关键!!!!!! this.classBreaks = pClassifyGEN.ClassBreaks as double[]; //注意,此对象下标从1开始(我觉得0为最开头,所以临界值从1开始有意义),关键!!!!!! this.lsvClassBreaksSymbol.Items.Clear(); string currentRange; for (int i = 0; i < classCount; i++) { currentRange = this.classBreaks[i].ToString() + " ~ " + this.classBreaks[i + 1].ToString(); this.lsvClassBreaksSymbol.Items.Add(currentRange); this.lsvClassBreaksSymbol.Items[i].SubItems.Add(currentRange); } }
private double[] fnClassification(IFeatureLayer pFLayer, decimal NClasses, string strClassifiedField, string ClassifiedMethod) { try { IFeatureClass pFClass = pFLayer.FeatureClass; //Create Rendering of Mean Value at Target Layer int intBreakeCount = Convert.ToInt32(NClasses); ITable pTable = (ITable)pFClass; IClassifyGEN pClassifyGEN; switch (ClassifiedMethod) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strClassifiedField; pTableHistogram.Table = pTable; IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; object xVals, frqs; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intBreakeCount); double[] cb = (double[])pClassifyGEN.ClassBreaks; return(cb); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return(null); } }
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 classify() { if (layer2Symbolize == null) { return; } IFeatureClass featureClass = layer2Symbolize.FeatureClass; ITable pTable = featureClass as ITable; ITableHistogram pTableHistogram = new BasicTableHistogramClass(); IBasicHistogram pHistogram = pTableHistogram as IBasicHistogram; pTableHistogram.Field = strRendererField; if (strNormalizeField.ToLower() != "none") { pTableHistogram.NormField = strNormalizeField; } pTableHistogram.Table = pTable; object dataFrequency; object dataValues; pHistogram.GetHistogram(out dataValues, out dataFrequency); IClassifyGEN pClassify = new NaturalBreaksClass(); switch (strClassifyMethod) { case "Equal Interval": pClassify = new EqualIntervalClass(); break; case "Quantile": pClassify = new QuantileClass(); break; case "Natural Breaks": pClassify = new NaturalBreaksClass(); break; case "Geometrical Interval": pClassify = new GeometricalIntervalClass(); break; default: break; } int numDesiredClass = gClassCount; pClassify.Classify(dataValues, dataFrequency, ref numDesiredClass); gClassbreaks = (double[])pClassify.ClassBreaks; }
private void InitializeClassificationArguments() { var quantileClass = new QuantileClass(); _selectedClassificationMethod = quantileClass; ListOfClassificationMethod = new BindingList <IClassifyGEN> { new NaturalBreaksClass(), quantileClass, new EqualIntervalClass(), new GeometricalIntervalClass() }; NumberOfClasses = new BindingList <int>(Enumerable.Range(2, 19).ToList()); _selectedNumberOfClasses = 5; }
private void cboClassifyMethod_SelectedIndexChanged(object sender, EventArgs e) { IClassify classify; if (this.bool_0) { classify = null; switch (this.cboClassifyMethod.SelectedIndex) { case 0: (this.itinColorRampRenderer_0 as IClassBreaksUIProperties).Method = new UIDClass(); this.cboClassifyNum.Enabled = false; break; case 1: classify = new EqualIntervalClass(); goto Label_006D; case 2: classify = new QuantileClass(); goto Label_006D; case 3: classify = new NaturalBreaksClass(); goto Label_006D; } } return; Label_006D: this.cboClassifyNum.Enabled = true; (this.itinColorRampRenderer_0 as IClassBreaksUIProperties).Method = classify.ClassID; if (this.cboClassifyNum.SelectedIndex >= 0) { this.method_4(); } else { this.cboClassifyNum.SelectedIndex = 4; } }
private void btnApply_Click(object sender, EventArgs e) { try { string strLayerName = cboSourceLayer.Text; if (cboSourceLayer.Text == "" || cboValueField.Text == "" || cboUField.Text == "") { MessageBox.Show("Assign proper layer and field"); return; } int intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName); ILayer pLayer = mForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; //Create Rendering of Mean Value at Target Layer int intGCBreakeCount = Convert.ToInt32(nudGCNClasses.Value); string strGCRenderField = cboValueField.Text; IGeoFeatureLayer pGeofeatureLayer; if (chkNewLayer.Checked == true) { IFeatureLayer pflOutput = new FeatureLayerClass(); pflOutput.FeatureClass = pFClass; pflOutput.Name = txtNewLayer.Text; pflOutput.Visible = true; pGeofeatureLayer = (IGeoFeatureLayer)pflOutput; } else { pGeofeatureLayer = (IGeoFeatureLayer)pFLayer; } ITable pTable = (ITable)pFClass; IClassifyGEN pClassifyGEN; switch (cboGCClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strGCRenderField; pTableHistogram.Table = pTable; IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; object xVals, frqs; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intGCBreakeCount); ClassBreaksRenderer pRender = new ClassBreaksRenderer(); double[] cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strGCRenderField; pRender.BreakCount = intGCBreakeCount; pRender.MinimumBreak = cb[0]; //' create our color ramp IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass(); pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; IRgbColor pColor1 = new RgbColor(); IRgbColor pColor2 = new RgbColor(); //Can Change the color in here! pColor1.Red = picSymolfrom.BackColor.R; pColor1.Green = picSymolfrom.BackColor.G; pColor1.Blue = picSymolfrom.BackColor.B; Boolean blnOK = true; pColor2.Red = picSymbolTo.BackColor.R; pColor2.Green = picSymbolTo.BackColor.G; pColor2.Blue = picSymbolTo.BackColor.B; pColorRamp.FromColor = pColor1; pColorRamp.ToColor = pColor2; pColorRamp.Size = intGCBreakeCount; pColorRamp.CreateRamp(out blnOK); IEnumColors pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); IRgbColor pColorOutline = new RgbColor(); //Can Change the color in here! pColorOutline.Red = picGCLineColor.BackColor.R; pColorOutline.Green = picGCLineColor.BackColor.G; pColorOutline.Blue = picGCLineColor.BackColor.B; double dblGCOutlineSize = Convert.ToDouble(nudGCLinewidth.Value); ICartographicLineSymbol pOutLines = new CartographicLineSymbol(); pOutLines.Width = dblGCOutlineSize; pOutLines.Color = (IColor)pColorOutline; //' use this interface to set dialog properties IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender; pUIProperties.ColorRamp = "Custom"; ISimpleFillSymbol pSimpleFillSym; //' be careful, indices are different for the diff lists for (int j = 0; j < intGCBreakeCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString(); pUIProperties.LowBreak[j] = cb[j]; pSimpleFillSym = new SimpleFillSymbolClass(); pSimpleFillSym.Color = pEnumColors.Next(); pSimpleFillSym.Outline = pOutLines; pRender.Symbol[j] = (ISymbol)pSimpleFillSym; } pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender; if (chkNewLayer.Checked == true) { mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer); } ////* Uncertainty Part *//// //Declare variables in if parts if (tcUncern.SelectedIndex == 0) //Graduated Color { int intUncernBreakCount = Convert.ToInt32(nudCoNClasses.Value); string strUncerFieldName = cboUField.Text; IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; switch (cboTeClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strUncerFieldName; pTableHistogram.Table = pTable; pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intUncernBreakCount); pRender = new ClassBreaksRenderer(); cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strUncerFieldName; pRender.BreakCount = intUncernBreakCount; pRender.MinimumBreak = cb[0]; IClassBreaksUIProperties pUIColProperties = (IClassBreaksUIProperties)pRender; pUIColProperties.ColorRamp = "Custom"; pColorRamp = new AlgorithmicColorRampClass(); pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; pColor1 = new RgbColor(); pColor2 = new RgbColor(); //Can Change the color in here! pColor1 = pSnippet.getRGB(picCoColorFrom.BackColor.R, picCoColorFrom.BackColor.G, picCoColorFrom.BackColor.B); pColor2 = pSnippet.getRGB(picCoColorTo.BackColor.R, picCoColorTo.BackColor.G, picCoColorTo.BackColor.B); if (pColor1 == null || pColor2 == null) { return; } blnOK = true; pColorRamp.FromColor = pColor1; pColorRamp.ToColor = pColor2; pColorRamp.Size = intUncernBreakCount; pColorRamp.CreateRamp(out blnOK); pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); pColorOutline = pSnippet.getRGB(picCoLineColor.BackColor.R, picCoLineColor.BackColor.G, picCoLineColor.BackColor.B); if (pColorOutline == null) { return; } double dblCoOutlineSize = Convert.ToDouble(nudCoLinewidth.Value); pOutLines = new CartographicLineSymbol(); pOutLines.Width = dblCoOutlineSize; pOutLines.Color = (IColor)pColorOutline; //' use this interface to set dialog properties pUIColProperties = (IClassBreaksUIProperties)pRender; pUIColProperties.ColorRamp = "Custom"; ISimpleMarkerSymbol pSimpleMarkerSym; double dblCoSymSize = Convert.ToDouble(nudCoSymbolSize.Value); //' be careful, indices are different for the diff lists for (int j = 0; j < intUncernBreakCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString(); pUIColProperties.LowBreak[j] = cb[j]; pSimpleMarkerSym = new SimpleMarkerSymbolClass(); pSimpleMarkerSym.Size = dblCoSymSize; pSimpleMarkerSym.Color = pEnumColors.Next(); pSimpleMarkerSym.Outline = true; pSimpleMarkerSym.OutlineColor = pColorOutline; pSimpleMarkerSym.OutlineSize = dblCoOutlineSize; pRender.Symbol[j] = (ISymbol)pSimpleMarkerSym; } pGFLUncern.Renderer = (IFeatureRenderer)pRender; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } else if (tcUncern.SelectedIndex == 1) //Texture { //Create Rendering of Uncertainty at Target Layer int intUncernBreakCount = Convert.ToInt32(nudTeNClasses.Value); string strUncerFieldName = cboUField.Text; IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; switch (cboTeClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strUncerFieldName; pTableHistogram.Table = pTable; pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intUncernBreakCount); pRender = new ClassBreaksRenderer(); cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strUncerFieldName; pRender.BreakCount = intUncernBreakCount; pRender.MinimumBreak = cb[0]; IClassBreaksUIProperties pUITexProperties = (IClassBreaksUIProperties)pRender; pUITexProperties.ColorRamp = "Custom"; ILineFillSymbol pLineFillSym = new LineFillSymbolClass(); double dblFromSep = Convert.ToDouble(nudSeperationFrom.Value); double dblToSep = Convert.ToDouble(nudSeperationTo.Value); double dblInstantSep = (dblFromSep - dblToSep) / Convert.ToDouble(intUncernBreakCount - 1); double dblFromAngle = Convert.ToDouble(nudAngleFrom.Value); double dblToAngle = Convert.ToDouble(nudAngleFrom.Value); // Remove the angle part (04/16) double dblInstantAngle = (dblToAngle - dblFromAngle) / Convert.ToDouble(intUncernBreakCount - 1); double dblLinewidth = Convert.ToDouble(nudTeLinewidth.Value); IRgbColor pLineColor = new RgbColor(); pLineColor.Red = picTeLineColor.BackColor.R; pLineColor.Green = picTeLineColor.BackColor.G; pLineColor.Blue = picTeLineColor.BackColor.B; //' be careful, indices are different for the diff lists for (int j = 0; j < intUncernBreakCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 5).ToString() + " - " + Math.Round(cb[j + 1], 5).ToString(); pUITexProperties.LowBreak[j] = cb[j]; pLineFillSym = new LineFillSymbolClass(); pLineFillSym.Angle = dblFromAngle + (dblInstantAngle * Convert.ToDouble(j)); pLineFillSym.Color = pLineColor; pLineFillSym.Separation = dblFromSep - (dblInstantSep * Convert.ToDouble(j)); pLineFillSym.LineSymbol.Width = dblLinewidth; pRender.Symbol[j] = (ISymbol)pLineFillSym; } pGFLUncern.Renderer = (IFeatureRenderer)pRender; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } else if (tcUncern.SelectedIndex == 2) //For Proportional Symbols { string strUncerFieldName = cboUField.Text; double dblMinPtSize = Convert.ToDouble(nudProSymbolSize.Value); double dblLineWidth = Convert.ToDouble(nudProLinewidth.Value); IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; //Find Fields int intUncernIdx = pTable.FindField(strUncerFieldName); //Find Min value //Set to initial value for min IField pUncernField = pTable.Fields.get_Field(intUncernIdx); ICursor pCursor = pTable.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = pUncernField.Name; pDataStat.Cursor = pCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMinValue = pStatResults.Minimum; double dblMaxValue = pStatResults.Maximum; pCursor.Flush(); IRgbColor pSymbolRgb = pSnippet.getRGB(picProSymbolColor.BackColor.R, picProSymbolColor.BackColor.G, picProSymbolColor.BackColor.B); if (pSymbolRgb == null) { return; } IRgbColor pLineRgb = pSnippet.getRGB(picProiLineColor.BackColor.R, picProiLineColor.BackColor.G, picProiLineColor.BackColor.B); if (pLineRgb == null) { return; } ISimpleMarkerSymbol pSMarkerSym = new SimpleMarkerSymbolClass(); pSMarkerSym.Style = esriSimpleMarkerStyle.esriSMSCircle; pSMarkerSym.Size = dblMinPtSize; pSMarkerSym.OutlineSize = dblLineWidth; pSMarkerSym.Outline = true; pSMarkerSym.OutlineColor = (IColor)pLineRgb; pSMarkerSym.Color = (IColor)pSymbolRgb; IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; IProportionalSymbolRenderer pUncernRender = new ProportionalSymbolRendererClass(); pUncernRender.LegendSymbolCount = 2; //Need to be changed 0219 pUncernRender.Field = strUncerFieldName; pUncernRender.MaxDataValue = dblMaxValue; pUncernRender.MinDataValue = dblMinValue; pUncernRender.MinSymbol = (ISymbol)pSMarkerSym; pUncernRender.ValueUnit = esriUnits.esriUnknownUnits; pUncernRender.BackgroundSymbol = null; pUncernRender.CreateLegendSymbols(); pGFLUncern.Renderer = (IFeatureRenderer)pUncernRender; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } else if (tcUncern.SelectedIndex == 3) // Bar { string strUncerFieldName = cboUField.Text; double dblMaxLength = Convert.ToDouble(nudMaxBarHeight.Value); double dblBarWidth = Convert.ToDouble(nudBarWidth.Value); IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; int intUncernIdx = pTable.FindField(strUncerFieldName); IField pUncernField = pTable.Fields.get_Field(intUncernIdx); ICursor pCursor = pTable.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = pUncernField.Name; pDataStat.Cursor = pCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMaxValue = pStatResults.Maximum; pCursor.Flush(); IChartRenderer chartRenderer = new ChartRendererClass(); IRendererFields rendererFields = chartRenderer as IRendererFields; rendererFields.AddField(strUncerFieldName); IBarChartSymbol barChartSymbol = new BarChartSymbolClass(); barChartSymbol.Width = dblBarWidth; IMarkerSymbol markerSymbol = barChartSymbol as IMarkerSymbol; markerSymbol.Size = dblMaxLength; IChartSymbol chartSymbol = barChartSymbol as IChartSymbol; chartSymbol.MaxValue = dblMaxValue; ISymbolArray symbolArray = barChartSymbol as ISymbolArray; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = pSnippet.getRGB(picBarSymCol.BackColor.R, picBarSymCol.BackColor.G, picBarSymCol.BackColor.B); if (fillSymbol.Color == null) { return; } symbolArray.AddSymbol(fillSymbol as ISymbol); if (chk3D.Checked) { I3DChartSymbol p3DChartSymbol = barChartSymbol as I3DChartSymbol; p3DChartSymbol.Display3D = true; p3DChartSymbol.Thickness = 3; } chartRenderer.ChartSymbol = barChartSymbol as IChartSymbol; SimpleFillSymbol pBaseFillSym = new SimpleFillSymbolClass(); //pBaseFillSym.Color = pSnippet.getRGB(picBarSymCol.BackColor.R, picBarSymCol.BackColor.G, picBarSymCol.BackColor.B); //chartRenderer.BaseSymbol = pBaseFillSym as ISymbol; chartRenderer.UseOverposter = false; chartRenderer.CreateLegend(); IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; pGFLUncern.Renderer = (IFeatureRenderer)chartRenderer; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } #region illumination //This function is not applied in this version. 032317 HK //} // else if (tcUncern.SelectedIndex == 4) //illumination // { // frmProgress pfrmProgress = new frmProgress(); // pfrmProgress.lblStatus.Text = "Processing:"; // pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; // pfrmProgress.Show(); // string strUncerFieldName = cboUField.Text; // IGeoDataset geoDataset_output = createRasterfromPolygon(pFClass, strUncerFieldName, pFLayer, 100); // double altitude = Convert.ToDouble(nudAltitude.Value); // double azimuth = Convert.ToDouble(nudAzimuth.Value); // object zFactor = Convert.ToDouble(nudZFactor.Value); // ISurfaceOp2 pSurfOP = new RasterSurfaceOpClass(); // IRaster pOutputDS = (IRaster)pSurfOP.HillShade(geoDataset_output, azimuth, altitude, true, ref zFactor); // ((IDataset)geoDataset_output).Delete(); // // Create a raster for viewing // ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = new ESRI.ArcGIS.Carto.RasterLayerClass(); // rasterLayer.CreateFromRaster(pOutputDS); // //Calculate hillshade value at slope 0 to set as background value // double dblRadian = (Math.PI / 180) * (90 - altitude); // double dblBackValue = Math.Truncate(255 * Math.Cos(dblRadian)); // IRasterStretch pRasterStretch = new RasterStretchColorRampRendererClass(); // IColor pColor = new RgbColorClass(); // pColor.NullColor = true; // pColor.Transparency = 0; // pRasterStretch.Background = true; // pRasterStretch.BackgroundColor = pColor; // pRasterStretch.set_BackgroundValues(ref dblBackValue); // rasterLayer.Name = "Uncertainty of " + strGCRenderField; // rasterLayer.Renderer = pRasterStretch as IRasterRenderer; // rasterLayer.Renderer.Update(); // //Apply Transparency // ILayerEffects pLayerEffect = (ILayerEffects)rasterLayer; // pLayerEffect.Transparency = Convert.ToInt16(nudTransparent.Value); // pfrmProgress.Close(); // // Add the raster to the map // pActiveView.FocusMap.AddLayer(rasterLayer); // } // mForm.axMapControl1.ActiveView.Refresh(); // mForm.axTOCControl1.Update(); #endregion } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
private void getBreaksValues(ClassifyMethodName ClassifyMethod,ILayer layer,string fieldName,double intervl,bool bfeuq) { ITableHistogram tableHistogram = new BasicTableHistogramClass(); tableHistogram.Table = ((IDisplayTable)layer).DisplayTable; tableHistogram.Field = fieldName; object valueArray = null, freq = null; IBasicHistogram basicHistogram = (IBasicHistogram)tableHistogram; basicHistogram.GetHistogram(out valueArray, out freq); IClassify classify = null; int breakNum = (int)intervl; //����� switch (ClassifyMethod) { case ClassifyMethodName.EqualInterval: { EqualIntervalClass eq = new EqualIntervalClass(); eq.Classify(valueArray, freq, ref breakNum); classify = (IClassify)eq; break; } case ClassifyMethodName.StandardDeviation: { StandardDeviationClass sd = new StandardDeviationClass(); IStatisticsResults stat = basicHistogram as IStatisticsResults; classify = sd as IClassify; classify.SetHistogramData(valueArray, freq); IDeviationInterval di = sd as IDeviationInterval; di.DeviationInterval = 1; di.Mean = stat.Mean; di.StandardDev = stat.StandardDeviation; classify.Classify(ref breakNum); break; } case ClassifyMethodName.Quantile: { Quantile qc = new QuantileClass(); qc.Classify(valueArray, freq, ref breakNum); classify = qc as IClassify; break; } case ClassifyMethodName.NaturalBreaks: { NaturalBreaksClass nb = new NaturalBreaksClass(); nb.Classify(valueArray, freq, ref breakNum); classify = nb as IClassify; break; } case ClassifyMethodName.DefinedInterval: { DefinedIntervalClass di = new DefinedIntervalClass(); di.IntervalRange = intervl; di.Classify(valueArray, freq, ref breakNum); classify = di as IClassify; break; } default: { EqualIntervalClass eq = new EqualIntervalClass(); eq.Classify(valueArray, freq, ref breakNum); classify = (IClassify)eq; break; } } object o = classify.ClassBreaks; System.Array breakArray = o as System.Array; IFrequencyStatistics freqstat = basicHistogram as IFrequencyStatistics; lscBreakValues.Items.Clear(); foreach (object oo in breakArray) { lscBreakValues.Items.Add(oo.ToString()); } }
private void DrawingChoroplethmap(IFeatureLayer pFLayer, string strRenderField, decimal NClasses) { IFeatureClass pFClass = pFLayer.FeatureClass; //Create Rendering of Mean Value at Target Layer int intGCBreakeCount = Convert.ToInt32(NClasses); IGeoFeatureLayer pGeofeatureLayer; IFeatureLayer pflOutput = new FeatureLayerClass(); pflOutput.FeatureClass = pFClass; pflOutput.Name = strRenderField; pflOutput.Visible = true; pGeofeatureLayer = (IGeoFeatureLayer)pflOutput; ITable pTable = (ITable)pFClass; IClassifyGEN pClassifyGEN; switch (cboGCClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } ITableHistogram pTableHistogram = new TableHistogramClass(); pTableHistogram.Field = strRenderField; pTableHistogram.Table = pTable; IHistogram pHistogram = (IHistogram)pTableHistogram; object xVals, frqs; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intGCBreakeCount); ClassBreaksRenderer pRender = new ClassBreaksRenderer(); double[] cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strRenderField; pRender.BreakCount = intGCBreakeCount; pRender.MinimumBreak = cb[0]; string strColorRamp = cboColorRamp.Text; IEnumColors pEnumColors = MultiPartColorRamp(strColorRamp, intGCBreakeCount); pEnumColors.Reset(); IRgbColor pColorOutline = new RgbColor(); //Can Change the color in here! pColorOutline.Red = picGCLineColor.BackColor.R; pColorOutline.Green = picGCLineColor.BackColor.G; pColorOutline.Blue = picGCLineColor.BackColor.B; double dblGCOutlineSize = Convert.ToDouble(nudGCLinewidth.Value); ICartographicLineSymbol pOutLines = new CartographicLineSymbol(); pOutLines.Width = dblGCOutlineSize; pOutLines.Color = (IColor)pColorOutline; //' use this interface to set dialog properties IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender; pUIProperties.ColorRamp = "Custom"; ISimpleFillSymbol pSimpleFillSym; //' be careful, indices are different for the diff lists for (int j = 0; j < intGCBreakeCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString(); pUIProperties.LowBreak[j] = cb[j]; pSimpleFillSym = new SimpleFillSymbolClass(); pSimpleFillSym.Color = pEnumColors.Next(); pSimpleFillSym.Outline = pOutLines; pRender.Symbol[j] = (ISymbol)pSimpleFillSym; } pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer); }
/// <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 }
private void btnClassiFy_Click(object sender, EventArgs e) { ITable pTable = this.pLayer as ITable; object dataValues; object dataFrequency; //以下代码用TableHistogram和BasicHistogram统计出Table某一字段的值和值的频率 ITableHistogram pTableHistogram; pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Table = pTable;//需传入一个ITable pTableHistogram.Field = this.cbbClassBreakField.Text;//统计的字段 IBasicHistogram pBasicHistogram; pBasicHistogram = pTableHistogram as IBasicHistogram; pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);//关键 //以下代码用IClassifyGEN和EqualInterval对象,基于分段数目,生成各段的临界值,并放在一个数组当中 IClassifyGEN pClassifyGEN; switch (this.cbbClassBreaksMethod.SelectedIndex) { case 0: pClassifyGEN = new EqualIntervalClass(); break; case 1: pClassifyGEN = new GeometricalIntervalClass(); break; case 2: pClassifyGEN = new NaturalBreaksClass(); break; case 3: pClassifyGEN = new QuantileClass(); break; default: pClassifyGEN = new EqualIntervalClass(); break; } //double[] classes; int classCount = int.Parse(this.cbbClassBreaksCount.Text); pClassifyGEN.Classify(dataValues, dataFrequency, ref classCount);//用到了上面ITableHistogram生成的值和值频率数组,关键!!!!!! this.classBreaks = pClassifyGEN.ClassBreaks as double[];//注意,此对象下标从1开始(我觉得0为最开头,所以临界值从1开始有意义),关键!!!!!! this.lsvClassBreaksSymbol.Items.Clear(); string currentRange; for (int i = 0; i < classCount; i++) { currentRange = this.classBreaks[i].ToString() + " ~ " + this.classBreaks[i + 1].ToString(); this.lsvClassBreaksSymbol.Items.Add(currentRange); this.lsvClassBreaksSymbol.Items[i].SubItems.Add(currentRange); } }
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; }
private void btnApply_Click(object sender, EventArgs e) { //Choropleth mapping : Exactly same with the function in frmChoroplethwithOverlay HK102915 string strLayerName = cboSourceLayer.Text; if (cboSourceLayer.Text == "" || cboValueField.Text == "" || cboUField.Text == "") { MessageBox.Show("Assign proper layer and field"); return; } int intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName); ILayer pLayer = mForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; //Create Rendering of Mean Value at Target Layer int intGCBreakeCount = Convert.ToInt32(nudGCNClasses.Value); string strGCRenderField = cboValueField.Text; IGeoFeatureLayer pGeofeatureLayer; pGeofeatureLayer = (IGeoFeatureLayer)pFLayer; ITable pTable = (ITable)pFClass; IClassifyGEN pClassifyGEN; switch (cboGCClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 ITableHistogram pTableHistogram = new TableHistogramClass(); pTableHistogram.Field = strGCRenderField; pTableHistogram.Table = pTable; IHistogram pHistogram = (IHistogram)pTableHistogram; object xVals, frqs; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intGCBreakeCount); ClassBreaksRenderer pRender = new ClassBreaksRenderer(); double[] cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strGCRenderField; pRender.BreakCount = intGCBreakeCount; pRender.MinimumBreak = cb[0]; //' create our color ramp IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass(); pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; IRgbColor pColor1 = new RgbColor(); IRgbColor pColor2 = new RgbColor(); //Can Change the color in here! pColor1.Red = picSymolfrom.BackColor.R; pColor1.Green = picSymolfrom.BackColor.G; pColor1.Blue = picSymolfrom.BackColor.B; Boolean blnOK = true; pColor2.Red = picSymbolTo.BackColor.R; pColor2.Green = picSymbolTo.BackColor.G; pColor2.Blue = picSymbolTo.BackColor.B; pColorRamp.FromColor = pColor1; pColorRamp.ToColor = pColor2; pColorRamp.Size = intGCBreakeCount; pColorRamp.CreateRamp(out blnOK); IEnumColors pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); IRgbColor pColorOutline = new RgbColor(); //Can Change the color in here! pColorOutline.Red = picGCLineColor.BackColor.R; pColorOutline.Green = picGCLineColor.BackColor.G; pColorOutline.Blue = picGCLineColor.BackColor.B; double dblGCOutlineSize = Convert.ToDouble(nudGCLinewidth.Value); ICartographicLineSymbol pOutLines = new CartographicLineSymbol(); pOutLines.Width = dblGCOutlineSize; pOutLines.Color = (IColor)pColorOutline; //' use this interface to set dialog properties IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender; pUIProperties.ColorRamp = "Custom"; ISimpleFillSymbol pSimpleFillSym; //' be careful, indices are different for the diff lists for (int j = 0; j < intGCBreakeCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString(); pUIProperties.LowBreak[j] = cb[j]; pSimpleFillSym = new SimpleFillSymbolClass(); pSimpleFillSym.Color = pEnumColors.Next(); pSimpleFillSym.Outline = pOutLines; pRender.Symbol[j] = (ISymbol)pSimpleFillSym; } pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender; //////////////////The Robustness int intRoundingDigits = 2; int intUncernBreakCount = Convert.ToInt32(nudTeNClasses.Value); string strUncerFieldName = cboUField.Text; int intUncernIdx = pFClass.FindField(strUncerFieldName); int intValueIdx = pFClass.FindField(strGCRenderField); //Calculate Robustness //Add fld int intTempfldIdx = 0; string strTempfldName = txtFldName.Text; if (chkRobustness.Checked) { if (pFClass.FindField(strTempfldName) == -1) { AddField(pFClass, strTempfldName); } intTempfldIdx = pFClass.FindField(strTempfldName); } Chart pChart = new Chart(); IFeature pFeat = null; //IFeatureCursor pFCursor = pFClass.Search(null, false); IFeatureCursor pFCursor = null; if (chkRobustness.Checked) { pFCursor = pFClass.Update(null, false); } else { pFCursor = pFClass.Search(null, false); } pFeat = pFCursor.NextFeature(); double[] arrRobustness = new double[pFClass.FeatureCount(null)]; int i = 0; while (pFeat != null) { for (int j = 0; j < (cb.Length - 1); j++) { double dblValue = Convert.ToDouble(pFeat.get_Value(intValueIdx)); double dblStd = Convert.ToDouble(pFeat.get_Value(intUncernIdx)); if (j == 0) { if (dblValue >= cb[j] && dblValue <= cb[j + 1]) { double dblUpperZvalue = (cb[j + 1] - dblValue) / dblStd; double dblUpperConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblUpperZvalue); double dblLowerZvalue = (cb[j] - dblValue) / dblStd; double dblLowerConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblLowerZvalue); arrRobustness[i] = dblUpperConfLev - dblLowerConfLev; if (chkRobustness.Checked) { pFeat.set_Value(intTempfldIdx, arrRobustness[i]); } } } else { if (dblValue > cb[j] && dblValue <= cb[j + 1]) { double dblUpperZvalue = (cb[j + 1] - dblValue) / dblStd; double dblUpperConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblUpperZvalue); double dblLowerZvalue = (cb[j] - dblValue) / dblStd; double dblLowerConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblLowerZvalue); arrRobustness[i] = dblUpperConfLev - dblLowerConfLev; if (chkRobustness.Checked) { pFeat.set_Value(intTempfldIdx, arrRobustness[i]); } } } } if (chkRobustness.Checked) { pFCursor.UpdateFeature(pFeat); } i++; pFeat = pFCursor.NextFeature(); } //Define the intervals (the last class is fixed to 1) if (intUncernBreakCount == 1) { return; } double[] arrRobustBrks = new double[intUncernBreakCount + 1]; double dblRBrksIntervals = Math.Round(1 / Convert.ToDouble(intUncernBreakCount - 1), intRoundingDigits); arrRobustBrks[0] = 0; for (int j = 1; j < intUncernBreakCount; j++) { arrRobustBrks[j] = dblRBrksIntervals * j; } arrRobustBrks[intUncernBreakCount] = 1; IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = "Robustness"; pflUncern.Visible = true; IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; pFCursor = pGFLUncern.Search(null, true); RobustnessRenderer pRobustnessRenderer = new RobustnessRenderer(); pRobustnessRenderer.arrRobustBrks = arrRobustBrks; pRobustnessRenderer.arrRobustness = arrRobustness; pRobustnessRenderer.dblAngle = Convert.ToDouble(nudAngleFrom.Value); pRobustnessRenderer.dblFromSep = Convert.ToDouble(nudSeperationFrom.Value); pRobustnessRenderer.dblLinewidth = Convert.ToDouble(nudTeLinewidth.Value); pRobustnessRenderer.dblToSep = Convert.ToDouble(nudSeperationTo.Value); pRobustnessRenderer.intUncernBreakCount = intUncernBreakCount; pRobustnessRenderer.pLineColor = pSnippet.getRGB(picTeLineColor.BackColor.R, picTeLineColor.BackColor.G, picTeLineColor.BackColor.B); IQueryFilter pQFilter = new QueryFilterClass(); pRobustnessRenderer.PrepareFilter(pFClass, pQFilter); pRobustnessRenderer.Draw(pFCursor, esriDrawPhase.esriDPSelection, pActiveView.ScreenDisplay, null); pRobustnessRenderer.CreateLegend(); pGFLUncern.Renderer = pRobustnessRenderer; pActiveView.FocusMap.AddLayer(pGFLUncern as ILayer); mForm.axMapControl1.ActiveView.Refresh(); mForm.axTOCControl1.Update(); }
private void classify() { if (layer2Symbolize == null) return; IFeatureClass featureClass = layer2Symbolize.FeatureClass; ITable pTable = (ITable)featureClass; 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 = new NaturalBreaksClass(); switch (strClassifyMethod) { case "等间隔分类": pClassify = new EqualIntervalClass(); break; //case "预定义间隔分类": // pClassify = new DefinedIntervalClass(); // break; case "分位数分类": pClassify = new QuantileClass(); break; case "自然裂点分类": pClassify = new NaturalBreaksClass(); break; //case "标准差分类": // pClassify = new StandardDeviationClass(); // break; case "几何间隔分类": pClassify = new GeometricalIntervalClass(); break; default: break; } int numDesiredClasses = gClassCount; pClassify.Classify(dataValues, dataFrequency, ref numDesiredClasses); gClassbreaks = (double[])pClassify.ClassBreaks; }
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); }
private static void MapUsingClassbreaksRenderer() { string layerName = CboLayers.GetSelectedLayer(); ILayer layer = GetLayerByName(layerName); IFeatureLayer2 fLayer = layer as IFeatureLayer2; string fieldName = CboFields.GetSelectedField(); // Get the number of classes string selectedClass = CboClasses.GetSelectedClass(); int numberOfClasses = Convert.ToInt32(selectedClass); ITableHistogram tableHistogram = new TableHistogramClass(); tableHistogram.Table = fLayer.FeatureClass as ITable; tableHistogram.Field = fieldName; IHistogram histo = tableHistogram as IHistogram; object datavalues, datafrequencies; histo.GetHistogram(out datavalues, out datafrequencies); IClassify classify = new QuantileClass(); classify.SetHistogramData(datavalues, datafrequencies); classify.Classify(ref numberOfClasses); if (numberOfClasses <= 1) { return; } double[] classBreaks = (double[])classify.ClassBreaks; IClassBreaksRenderer render = new ClassBreaksRenderer(); render.Field = fieldName; render.BreakCount = numberOfClasses; render.MinimumBreak = classBreaks[0]; // Get the colors ICmykColor[] colors = ColorbrewerExtension.GetCmykColors(); IFillSymbol fill = null; // Iterate through the colors for (int i = 0; i < numberOfClasses; i++) { fill = new SimpleFillSymbol(); fill.Color = colors[i]; fill.Outline.Width = 0.5; render.Symbol[i] = fill as ISymbol; render.Break[i] = classBreaks[i + 1]; render.Label[i] = string.Format("{0} to {1}", classBreaks[i] , classBreaks[i + 1]); } IGeoFeatureLayer gFLayer = layer as IGeoFeatureLayer; gFLayer.Renderer = render as IFeatureRenderer; IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument; mxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, gFLayer , mxDoc.ActiveView.Extent); mxDoc.UpdateContents(); }
private void DrawCCMaps() { m_intClassNumber = Convert.ToInt32(nudGCNClasses.Value); IFeatureClass pFClass = pFLayer.FeatureClass; //Determine Class Breaks for variable int intValueFldIdx = pFClass.FindField(strVarFldName); ITable pTable = (ITable)pFClass; IClassifyGEN pClassifyGEN = null; switch (cboGCClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } ITableHistogram pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strVarFldName; pTableHistogram.Table = pTable; //IHistogram pHistogram = (IHistogram)pTableHistogram2; IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; ////Not working in ArcGIS 10.5 022417 HK //ITableHistogram pTableHistogram = new TableHistogramClass(); //pTableHistogram.Field = strVarFldName; //pTableHistogram.Table = pTable; //IHistogram pHistogram = (IHistogram)pTableHistogram; object xVals, frqs; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, m_intClassNumber); double[] cb = (double[])pClassifyGEN.ClassBreaks; //Class Determinations for vertical and horizontal axis if (m_VerticalBreaks == null) { pClassifyGEN = new QuantileClass(); //Using Quatile pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strVerConFldName; pTableHistogram.Table = pTable; pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intVerCnt); m_VerticalBreaks = (double[])pClassifyGEN.ClassBreaks; } if (m_HorizontalBreaks == null) { pClassifyGEN = new QuantileClass(); //Using Quatile pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strHorConFldName; pTableHistogram.Table = pTable; pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intHorCnt); m_HorizontalBreaks = (double[])pClassifyGEN.ClassBreaks; } //Create Renderer IClassBreaksRenderer pRender = new ClassBreaksRenderer(); pRender.Field = strVarFldName; pRender.BreakCount = m_intClassNumber; pRender.MinimumBreak = cb[0]; string strColorRamp = cboColorRamp.Text; IEnumColors pEnumColors = MultiPartColorRamp(strColorRamp, "CIE Lab", m_intClassNumber); pEnumColors.Reset(); int[,] arrColors = new int[m_intClassNumber, 3]; for (int k = 0; k < m_intClassNumber; 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(); IRgbColor pColorOutline = new RgbColor(); //Can Change the color in here! pColorOutline = m_pSnippet.getRGB(picOutlineColor.BackColor.R, picOutlineColor.BackColor.G, picOutlineColor.BackColor.B); double dblGCOutlineSize = Convert.ToDouble(nudOutlinewidth.Value); ICartographicLineSymbol pOutLines = new CartographicLineSymbol(); pOutLines.Width = dblGCOutlineSize; pOutLines.Color = (IColor)pColorOutline; //' use this interface to set dialog properties IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender; pUIProperties.ColorRamp = "Custom"; ISimpleFillSymbol pSimpleFillSym; pEnumColors.Reset(); double dblAdding = Math.Pow(0.1, m_intRounding); for (int j = 0; j < m_intClassNumber; j++) { pRender.Break[j] = cb[j + 1]; if (j == 0) { pRender.Label[j] = Math.Round(cb[j], m_intRounding).ToString("N" + m_intRounding.ToString()) + " - " + Math.Round(cb[j + 1], 2).ToString("N" + m_intRounding.ToString()); } else { pRender.Label[j] = Math.Round(cb[j] + dblAdding, m_intRounding).ToString("N" + m_intRounding.ToString()) + " - " + Math.Round(cb[j + 1], 2).ToString("N" + m_intRounding.ToString()); } pUIProperties.LowBreak[j] = cb[j]; pSimpleFillSym = new SimpleFillSymbolClass(); IRgbColor pRGBColor = m_pSnippet.getRGB(arrColors[j, 0], arrColors[j, 1], arrColors[j, 2]); pSimpleFillSym.Color = (IColor)pRGBColor; pSimpleFillSym.Outline = pOutLines; pRender.Symbol[j] = (ISymbol)pSimpleFillSym; } //Background Layer ISimpleRenderer pSimpleRender = new SimpleRendererClass(); ISimpleFillSymbol pBGSymbol = new SimpleFillSymbolClass(); pBGSymbol.Color = (IColor)m_pSnippet.getRGB(picBGColor.BackColor.R, picBGColor.BackColor.G, picBGColor.BackColor.B); ICartographicLineSymbol pBGOutLines = new CartographicLineSymbol(); pBGOutLines.Width = 0; pBGOutLines.Color = m_pSnippet.getRGB(255, 255, 255); pBGSymbol.Outline = pBGOutLines; pSimpleRender.Symbol = (ISymbol)pBGSymbol; IFeatureLayer pflBG = new FeatureLayerClass(); pflBG.FeatureClass = pFClass; IGeoFeatureLayer pGeoBG = (IGeoFeatureLayer)pflBG; pGeoBG.Renderer = (IFeatureRenderer)pSimpleRender; pGeoBG.Selectable = false; //Feature Count for each map m_intsFeatureCnts = new int[intVerCnt * intHorCnt]; int l = 0; for (int i = 0; i < intVerCnt; i++) { for (int j = 0; j < intHorCnt; j++) { IFeatureLayer pflOutput = new FeatureLayerClass(); pflOutput.FeatureClass = pFClass; IGeoFeatureLayer pGeofeatureLayer = (IGeoFeatureLayer)pflOutput; pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender; IFeatureLayerDefinition2 pFDefinition = (IFeatureLayerDefinition2)pGeofeatureLayer; string strWhereClause = null; if (i == 0 && j == 0) { strWhereClause = strVerConFldName + " >= " + m_VerticalBreaks[i].ToString() + " AND " + strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " + strHorConFldName + " >= " + m_HorizontalBreaks[j].ToString() + " AND " + strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString(); } else if (i != 0 && j == 0) { strWhereClause = strVerConFldName + " > " + m_VerticalBreaks[i].ToString() + " AND " + strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " + strHorConFldName + " >= " + m_HorizontalBreaks[j].ToString() + " AND " + strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString(); } else if (i == 0 && j != 0) { strWhereClause = strVerConFldName + " >= " + m_VerticalBreaks[i].ToString() + " AND " + strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " + strHorConFldName + " > " + m_HorizontalBreaks[j].ToString() + " AND " + strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString(); } else { strWhereClause = strVerConFldName + " > " + m_VerticalBreaks[i].ToString() + " AND " + strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " + strHorConFldName + " > " + m_HorizontalBreaks[j].ToString() + " AND " + strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString(); } pFDefinition.DefinitionExpression = strWhereClause; IQueryFilter pQfilter = new QueryFilterClass(); pQfilter.WhereClause = strWhereClause; m_intsFeatureCnts[l] = pGeofeatureLayer.FeatureClass.FeatureCount(pQfilter); m_axMapControls[l].ActiveView.FocusMap.ClearLayers(); m_axMapControls[l].ActiveView.FocusMap.AddLayer(pGeoBG); m_axMapControls[l].ActiveView.FocusMap.AddLayer(pGeofeatureLayer); m_axMapControls[l].ActiveView.Extent = m_axMapControls[l].ActiveView.FullExtent; m_axMapControls[l].ActiveView.Refresh(); l++; } } lblVariable.Text = "Selected Variable: " + strVarFldName; UpdateRange(lvSymbol, m_intClassNumber, cb, arrColors, m_intRounding); if (m_blnAddBoxes) { UpdateTextBoxes(); } else { AddTextBoxes(); } UpdateLabels(); UpdateHorVerLabels(); }
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 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(); }