private void cbxSymbolizeMethds_SelectedIndexChanged(object sender, EventArgs e) { if (cbxSymbolizeMethds.SelectedItem != null) { strSymbolizeMethod = cbxSymbolizeMethds.SelectedItem.ToString(); switch (strSymbolizeMethod) { case "饼状图": chartSymbol = new PieChartSymbolClass(); pictureBox1.BackgroundImage = backImageList.Images[0]; break; case "柱状图": chartSymbol = new BarChartSymbolClass(); pictureBox1.BackgroundImage = backImageList.Images[1]; break; case "堆积柱状图": chartSymbol = new StackedChartSymbolClass(); pictureBox1.BackgroundImage = backImageList.Images[2]; break; default: break; } } }
public ChartRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, string pFieldName) { IGeoFeatureLayer pGeoFeaturelayer = pFtLayer as IGeoFeatureLayer; IChartRenderer pChart = new ChartRendererClass(); IDataStatistics pDataStat = new DataStatisticsClass(); IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false); pDataStat.Cursor = pFtCursor as ICursor; pDataStat.Field = pFieldName; double pMax = pDataStat.Statistics.Maximum; IRendererFields pRenderFields = pChart as IRendererFields; pRenderFields.AddField(pFieldName, pFieldName); IBarChartSymbol pBarChart = new BarChartSymbolClass(); pBarChart.Width = 5; IMarkerSymbol pMarkerSymbol = pBarChart as IMarkerSymbol; pMarkerSymbol.Size = 12; IChartSymbol pChartSym = pBarChart as IChartSymbol; pChartSym.MaxValue = pMax; ISymbolArray pSymbolArr = pBarChart as ISymbolArray; IFillSymbol pFillSy = new SimpleFillSymbolClass(); pFillSy.Color = GetRgb(220, 0, 0); pSymbolArr.AddSymbol(pFillSy as ISymbol); pGeoFeaturelayer.Renderer = pChart as IFeatureRenderer; pMapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
/// <summary> /// BarChartRenderer柱状图渲染:根据一个或多个数字字段的值配置柱状图渲染图层 /// </summary> /// <param name="geoFeatureLayer"></param> /// <param name="fieldNameColorDict"></param> public static void SetBarCharRenderer(this IGeoFeatureLayer geoFeatureLayer, Dictionary <string, IColor> fieldNameColorDict) { //创建柱状符号 IBarChartSymbol barChartSymbol = new BarChartSymbolClass { Width = 12 }; //获取两个字段的最大值,设置柱状图各柱状符号 double maxValue = 0; ISymbolArray symbolArray = (ISymbolArray)barChartSymbol; foreach (var pair in fieldNameColorDict) { var value = geoFeatureLayer.FeatureClass.Statistics(pair.Key, null, EStatisticsType.Maximum); if (value > maxValue) { maxValue = value; } IFillSymbol fillSymbol = new SimpleFillSymbol { Color = pair.Value }; symbolArray.AddSymbol((ISymbol)fillSymbol); } //设置ChartSymbol的最大值,以及符号尺寸最大值(像素单位) IChartSymbol chartSymbol = (IChartSymbol)barChartSymbol; IMarkerSymbol markerSymbol = (IMarkerSymbol)barChartSymbol; chartSymbol.MaxValue = maxValue; markerSymbol.Size = 60; //设置字段,依据字段的数据值,创建柱状图 IChartRenderer chartRenderer = new ChartRendererClass(); IRendererFields rendererFields = (IRendererFields)chartRenderer; foreach (var pair in fieldNameColorDict) { rendererFields.AddField(pair.Key, pair.Key); } //设置图层的背景颜色 chartRenderer.ChartSymbol = (IChartSymbol)barChartSymbol; chartRenderer.BaseSymbol = new SimpleFillSymbolClass { Color = ColorCreate.GetIColor(239, 228, 190) }; //设置其他属性 chartRenderer.UseOverposter = false; chartRenderer.CreateLegend();//创建符号图例 chartRenderer.Label = ""; geoFeatureLayer.Renderer = chartRenderer as IFeatureRenderer; }
private void InitRendererUI(List <FieldInfo> pFields) { IRendererUI pRendererUI = null; if (m_FeatureRenderer is ESRI.ArcGIS.Carto.ISimpleRenderer) { pRendererUI = new frmSimpleRenderer(); } else if (m_FeatureRenderer is ESRI.ArcGIS.Carto.IUniqueValueRenderer) { pRendererUI = new frmMFUVRenderer(); } else if (m_FeatureRenderer is ESRI.ArcGIS.Carto.IClassBreaksRenderer) { ESRI.ArcGIS.Carto.IClassBreaksUIProperties pUIProp = m_FeatureRenderer as ESRI.ArcGIS.Carto.IClassBreaksUIProperties; if (pUIProp.ColorRamp != "") { pRendererUI = new frmBreakColorRenderer(); } else { pRendererUI = new frmBreakSizeRenderer(); } } else if (m_FeatureRenderer is ESRI.ArcGIS.Carto.IChartRenderer) { IChartRenderer pChartRenderer = m_FeatureRenderer as IChartRenderer; IChartSymbol pChartSymbol = pChartRenderer.ChartSymbol; if (pChartSymbol is IPieChartSymbol) { pRendererUI = new frmPieChartRenderer();//yjl20110906 add } else if (pChartSymbol is IBarChartSymbol) { pRendererUI = new frmBarChartRenderer(); } else { pRendererUI = new frmStackedChartRenderer(); } } if (m_FeatureLayer == null) { pRendererUI.InitRendererObject(pFields, m_FeatureRenderer, m_StyleClass); } else { pRendererUI.InitRendererObject(m_FeatureLayer, m_FeatureRenderer, m_StyleClass); } m_RendererObject.Add(pRendererUI.GetType().FullName, pRendererUI); treeCatelog.SelectedNode = treeCatelog.FindNodeByName(pRendererUI.GetType().FullName); }
//Create Legend public void CreateLegend() { clsSnippet pSnippet = new clsSnippet(); //Create Legend Group m_pLegendGroup = new LegendGroup(); m_pLegendGroup.Heading = m_strOriRenderField; m_pLegendGroup.Editable = true; m_pLegendGroup.Visible = true; ILegendClass legendClass = new LegendClass(); legendClass.Label = Math.Round(dblMaxValue, 0).ToString(); IStackedChartSymbol stackedChartSymbol = new StackedChartSymbolClass(); //IBarChartSymbol barChartSymbol = new BarChartSymbolClass(); stackedChartSymbol.Width = 10; if (bln3Dfeature) { I3DChartSymbol p3DChartSymbol = stackedChartSymbol as I3DChartSymbol; p3DChartSymbol.Display3D = true; p3DChartSymbol.Thickness = 3; } //IMarkerSymbol markerSymbol = stackedChartSymbol as IMarkerSymbol; //markerSymbol.Size = 50; IChartSymbol chartSymbol = stackedChartSymbol as IChartSymbol; chartSymbol.MaxValue = dblMaxValue; ISymbolArray symbolArray = stackedChartSymbol as ISymbolArray; //Stacked Symbol IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = pSnippet.getRGB(255, 0, 0); fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0); symbolArray.AddSymbol(fillSymbol as ISymbol); chartSymbol.set_Value(0, dblMaxUncern); //fillSymbol = new SimpleFillSymbolClass(); //fillSymbol.Color = pSnippet.getRGB(255, 0, 0); //fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0); //symbolArray.AddSymbol(fillSymbol as ISymbol); //chartSymbol.set_Value(1, dblMaxUncern); fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = pSnippet.getRGB(255, 255, 255); fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0); symbolArray.AddSymbol(fillSymbol as ISymbol); chartSymbol.set_Value(1, dblMaxEstimate - dblMaxUncern); legendClass.Symbol = (ISymbol)chartSymbol; m_pLegendGroup.AddClass(legendClass); //Bounds legendClass = new LegendClass(); legendClass.Label = "Upper Bound"; ISimpleFillSymbol pLegendUncerSymbol = new SimpleFillSymbol(); pLegendUncerSymbol.Color = pSnippet.getRGB(0, 0, 255); pLegendUncerSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0); legendClass.Symbol = (ISymbol)pLegendUncerSymbol; m_pLegendGroup.AddClass(legendClass); legendClass = new LegendClass(); legendClass.Label = "Lower Bound"; pLegendUncerSymbol = new SimpleFillSymbol(); pLegendUncerSymbol.Color = pSnippet.getRGB(255, 0, 0); pLegendUncerSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0); legendClass.Symbol = (ISymbol)pLegendUncerSymbol; m_pLegendGroup.AddClass(legendClass); }
/// <summary> /// Pie Chart Render /// </summary> /// <param name="currentLayer"></param> /// <param name="breakCount"></param> /// <author>Shen Yongyuan</author> /// <date>20091114</date> public static void PieChartRender(ILayer currentLayer) { //Scale Symbol IGeoFeatureLayer pGeoFeatureL = currentLayer as IGeoFeatureLayer; pGeoFeatureL.ScaleSymbols = true; //Chart Render IChartRenderer pChartRenderer = new ChartRendererClass(); IRendererFields pRendererFields = (IRendererFields)pChartRenderer; pRendererFields.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Ecology", "生态"); pRendererFields.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Social", "社会"); pRendererFields.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Economic", "经济"); //Search Max IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Ecology"); pQueryFilter.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Social"); pQueryFilter.AddField(Town.Constant.Constant.TmpTableIndex + "." + "Economic"); IFeatureCursor pCursor = pGeoFeatureL.DisplayFeatureClass.Search(pQueryFilter, true); int fldFiledEcology = pCursor.Fields.FindField(Town.Constant.Constant.TmpTableIndex + "." + "Ecology"); int fldFiledSocial = pCursor.Fields.FindField(Town.Constant.Constant.TmpTableIndex + "." + "Social"); int fldFiledEconomic = pCursor.Fields.FindField(Town.Constant.Constant.TmpTableIndex + "." + "Economic"); List <double> valueList = new List <double>(); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { valueList.Add(Convert.ToDouble(pFeature.get_Value(fldFiledEcology))); valueList.Add(Convert.ToDouble(pFeature.get_Value(fldFiledSocial))); valueList.Add(Convert.ToDouble(pFeature.get_Value(fldFiledEconomic))); pFeature = pCursor.NextFeature(); } //Pie Chart IPieChartSymbol pPieChartSymbol; pPieChartSymbol = new PieChartSymbolClass(); IChartSymbol pChartSymbol = (IChartSymbol)pPieChartSymbol; //Pie Chart Attribute pPieChartSymbol.Clockwise = true; pPieChartSymbol.UseOutline = true; ILineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(100, 205, 30)); pOutline.Width = 1; pPieChartSymbol.Outline = pOutline; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)pPieChartSymbol; pChartSymbol.MaxValue = valueList.Max(); pMarkerSymbol.Size = 60; //Symbol Array ISymbolArray pSymbolArray = (ISymbolArray)pPieChartSymbol; ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.Green); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.Red); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.Blue); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pChartRenderer.ChartSymbol = (IChartSymbol)pPieChartSymbol; pChartRenderer.Label = "指标"; //Back Ground pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(239, 228, 190)); pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; //Render Label pGeoFeatureL.Renderer = pChartRenderer as IFeatureRenderer; }
/// <summary> /// Bar Chart Render for Enviroment /// </summary> /// <param name="currentLayer"></param> /// <param name="breakCount"></param> /// <author>Shen Yongyuan</author> /// <date>20091114</date> public static void BarChartRenderSingle(ILayer currentLayer) { //Scale Symbol IGeoFeatureLayer pGeoFeatureL = currentLayer as IGeoFeatureLayer; pGeoFeatureL.ScaleSymbols = true; //Chart Render IChartRenderer pChartRenderer = new ChartRendererClass(); IRendererFields pRendererFields = (IRendererFields)pChartRenderer; pRendererFields.AddField(Town.Constant.Constant.TmpTableIndex + "." + Town.Constant.Constant.TmpFieldName, "指标"); //Search Max IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(Town.Constant.Constant.TmpTableIndex + "." + Town.Constant.Constant.TmpFieldName); IFeatureCursor pCursor = pGeoFeatureL.DisplayFeatureClass.Search(pQueryFilter, true); int fldFiledEcology = pCursor.Fields.FindField(Town.Constant.Constant.TmpTableIndex + "." + Town.Constant.Constant.TmpFieldName); List <double> valueList = new List <double>(); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { valueList.Add(Convert.ToDouble(pFeature.get_Value(fldFiledEcology))); pFeature = pCursor.NextFeature(); } //Bar Chart IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass(); IChartSymbol pChartSymbol = (IChartSymbol)pBarChartSymbol; pBarChartSymbol.Width = 12; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol; pChartSymbol.MaxValue = valueList.Max(); pMarkerSymbol.Size = 50; //Set Symbol ISymbolArray pSymbolArray = (ISymbolArray)pBarChartSymbol; ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.Green); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); //Render Attribute pChartRenderer.ChartSymbol = (IChartSymbol)pBarChartSymbol; pChartRenderer.Label = "指标"; pChartRenderer.UseOverposter = false; pChartRenderer.CreateLegend(); //Back Ground pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(239, 228, 190)); pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; //Render Label pGeoFeatureL.Renderer = pChartRenderer as IFeatureRenderer; }
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; } }
//创建柱状专题图 public void CreateBarRenderer(int layerID, string[] fields) { // 得到地图服务下的ArcObjects map对象 ESRI.ArcGIS.Server.IServerContext pServerContext = GetServerContext(); ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)pServerContext.ServerObject; ESRI.ArcGIS.Carto.IMapServerObjects2 mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerObjects2)mapServer; string mapName = mapServer.DefaultMapName; ESRI.ArcGIS.Carto.IMap aoMap = mapServerObjects.get_Map(mapName); ESRI.ArcGIS.Carto.ILayer pLayer = aoMap.get_Layer(layerID);//得到图层 ESRI.ArcGIS.Carto.IGeoFeatureLayer pGeoLayer = pLayer as IGeoFeatureLayer; //设置专题图元素的属性名称列表 IChartRenderer pChartRender = pServerContext.CreateObject("esriCarto.ChartRenderer") as IChartRenderer; IRendererFields pRenderFields = pChartRender as IRendererFields; foreach (string var in fields) { pRenderFields.AddField(var, var); } //实例化图表对象并取得元素指定属性的最大值 IBarChartSymbol pBarChartSymbol = pServerContext.CreateObject("esriDisplay.BarChartSymbol") as IBarChartSymbol; IChartSymbol pChartSymbol = pBarChartSymbol as IChartSymbol; pChartSymbol.MaxValue = GetStaMaxMin(fields, pGeoLayer)[0]; pBarChartSymbol.Width = 8; IMarkerSymbol pMarkerSymbol = pBarChartSymbol as IMarkerSymbol; pMarkerSymbol.Size = 50; //设置柱状图每列填充效果 ISymbolArray pSymbolArray = pBarChartSymbol as ISymbolArray; Random ranColor = new Random(); for (int i = 0; i < fields.Length; i++) { IFillSymbol pFillSymbol = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as IFillSymbol; pFillSymbol.Color = GetRGB(ranColor.Next(255), ranColor.Next(255), ranColor.Next(255), pServerContext); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); } //设置地图图层背景 ESRI.ArcGIS.Display.ISimpleFillSymbol pFSymbol = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as ESRI.ArcGIS.Display.SimpleFillSymbol; pFSymbol.Color = GetRGB(239, 228, 249, pServerContext); pChartRender.BaseSymbol = pFSymbol as ISymbol; //应用柱状专题到指定图层 pChartRender.ChartSymbol = pBarChartSymbol as IChartSymbol; pChartRender.Label = "Test"; pChartRender.UseOverposter = false; pChartRender.CreateLegend(); pGeoLayer.Renderer = pChartRender as IFeatureRenderer; //刷新地图显示图表及图例 mapServerObjects.RefreshServerObjects(); Map1.RefreshResource("MapResourceItem0"); Toc1.BuddyControl = "Map1"; //Toc1.Refresh(); Map1.Refresh(); pServerContext.ReleaseContext(); }
public PieRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, string pFieldName1, string pFieldName2) { IGeoFeatureLayer pGeoFeaLayer = (IGeoFeatureLayer)pFtLayer; IChartRenderer pChartRenderer = new ChartRendererClass(); // Set up the field to draw charts IRendererFields pRenderFields = (IRendererFields)pChartRenderer; pRenderFields.AddField(pFieldName1, pFieldName1); pRenderFields.AddField(pFieldName2, pFieldName2); IPieChartRenderer pPieChartRender = (IPieChartRenderer)pChartRenderer; //计算最大值部分有待补充//////////////////////////////////// //Calculate the max value of the data field to scale the chart //ICursor pCursor = new CursorClass(); IQueryFilter pQueryFilter = new QueryFilterClass(); //IRowBuffer pRow = new RowBufferClass(); ITable pTable = (ITable)pGeoFeaLayer; pQueryFilter.AddField(pFieldName1); ICursor pCursor = pTable.Search(pQueryFilter, true); IDataStatistics pDataStat = new DataStatisticsClass(); IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false); pDataStat.Cursor = pFtCursor as ICursor; pDataStat.Field = pFieldName1; double pMax = pDataStat.Statistics.Maximum; IPieChartSymbol pPiechartSymbol = new PieChartSymbolClass(); IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); IChartSymbol pChartSymbol = (IChartSymbol)pPiechartSymbol; pPiechartSymbol.Clockwise = true; pPiechartSymbol.UseOutline = true; ILineSymbol pOutLine = new SimpleLineSymbolClass(); pOutLine.Color = GetRGBColor(255, 0, 255); pOutLine.Width = 1; pPiechartSymbol.Outline = pOutLine; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)pPiechartSymbol; //finally pChartSymbol.MaxValue = pMax; pMarkerSymbol.Size = 16; //像符号数组中添加 添加符号 ISymbolArray pSymbolArray = (ISymbolArray)pPiechartSymbol; pFillSymbol.Color = GetRGBColor(213, 212, 252); pFillSymbol.Outline = pOutLine; pSymbolArray.AddSymbol((ISymbol)pFillSymbol); ////////////////////////// pFillSymbol.Color = GetRGBColor(183, 242, 122); pFillSymbol.Outline = pOutLine; pSymbolArray.AddSymbol((ISymbol)pFillSymbol); //set up the background pFillSymbol.Color = GetRGBColor(239, 228, 190); pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; pChartRenderer.UseOverposter = false; pPieChartRender.MinSize = 1; pPieChartRender.MinValue = pDataStat.Statistics.Minimum; pPieChartRender.FlanneryCompensation = false; pPieChartRender.ProportionalBySum = true; pChartRenderer.ChartSymbol = (IChartSymbol)pPiechartSymbol; pChartRenderer.CreateLegend(); pGeoFeaLayer.Renderer = (IFeatureRenderer)pChartRenderer; pMapcontrol.ActiveView.Refresh(); }
public void ApplyBarChartValue(IGeoFeatureLayer geoLayer, string aFieldName) { //IChartRender is engaged with feature data IChartRenderer chartRender = new ChartRenderer(); IRendererFields renderFields = chartRender as IRendererFields; renderFields.AddField(aFieldName); //Search Max IQueryFilter queryFilter = new QueryFilter(); //Content in Cursor queryFilter.AddField(aFieldName); //Search all features without WhereClause IFeatureCursor fCursor = geoLayer.FeatureClass.Search(queryFilter, true); //the index of Field int indexField = fCursor.FindField(aFieldName); List <double> valueList = new List <double>(); IFeature aFeature = fCursor.NextFeature(); while (aFeature != null) { valueList.Add(Convert.ToDouble(aFeature.get_Value(indexField))); aFeature = fCursor.NextFeature(); } //BarChartSymbol IBarChartSymbol barSymbol = new BarChartSymbol() as IBarChartSymbol; barSymbol.Width = 12; IChartSymbol chartSym = barSymbol as IChartSymbol; // chartSym.MaxValue = valueList.Max(); IMarkerSymbol markerSymbol = (IMarkerSymbol)chartSym; markerSymbol.Size = 50; //Set Symbol ISymbolArray pSymbolArray = (ISymbolArray)barSymbol; IRgbColor aColor = new RgbColor(); aColor.Red = Convert.ToInt32(255); aColor.Green = Convert.ToInt32(255); aColor.Blue = Convert.ToInt32(0); ISimpleFillSymbol pFillSymbol = new SimpleFillSymbol(); pFillSymbol.Color = aColor; pSymbolArray.AddSymbol((ISymbol)pFillSymbol); //Render Attribute chartRender.ChartSymbol = (IChartSymbol)barSymbol; chartRender.Label = "指标"; chartRender.UseOverposter = false; chartRender.CreateLegend(); //Back Ground ISimpleFillSymbol bgSym = new SimpleFillSymbol(); IRgbColor bgColor = new RgbColor(); bgColor.Red = Convert.ToInt32(239); bgColor.Green = Convert.ToInt32(228); bgColor.Blue = Convert.ToInt32(190); bgSym.Color = bgColor; //bgSym.Color = Convert.ToInt32(System.Drawing.Color.FromArgb(239, 228, 190)); chartRender.BaseSymbol = (ISymbol)bgSym; //Render Label geoLayer.ScaleSymbols = true; //Scale Symbol geoLayer.Renderer = chartRender as IFeatureRenderer; axMapControl1.ActiveView.Refresh(); axTOCControl1.Update(); }
//PieChartRenderer private void button7_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; ITable table; ICursor cursor; IRowBuffer rowBuffer; //设置饼图的要素 string field1 = "sqmi"; string field2 = "sqkm"; //获取渲染图层 geoFeatureLayer = getGeoLayer("Continents"); featureLayer = geoFeatureLayer as IFeatureLayer; table = featureLayer as ITable; geoFeatureLayer.ScaleSymbols = true; IChartRenderer chartRenderer = new ChartRendererClass(); IPieChartRenderer pieChartRenderer = chartRenderer as IPieChartRenderer; IRendererFields rendererFields = chartRenderer as IRendererFields; rendererFields.AddField(field1, field1); rendererFields.AddField(field2, field2); int[] fieldIndexs = new int[2]; fieldIndexs[0] = table.FindField(field1); fieldIndexs[1] = table.FindField(field2); //获取渲染要素的最大值 double fieldValue = 0.0, maxValue = 0.0; cursor = table.Search(null, true); rowBuffer = cursor.NextRow(); while (rowBuffer != null) { for (int i = 0; i < 2; i++) { fieldValue = double.Parse(rowBuffer.get_Value(fieldIndexs[i]).ToString()); if (fieldValue > maxValue) { maxValue = fieldValue; } } rowBuffer = cursor.NextRow(); } //设置饼图符号 IPieChartSymbol pieChartSymbol = new PieChartSymbolClass(); pieChartSymbol.Clockwise = true; pieChartSymbol.UseOutline = true; IChartSymbol chartSymbol = pieChartSymbol as IChartSymbol; chartSymbol.MaxValue = maxValue; ILineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = getRGB(255, 0, 0); lineSymbol.Width = 2; pieChartSymbol.Outline = lineSymbol; IMarkerSymbol markerSymbol = pieChartSymbol as IMarkerSymbol; markerSymbol.Size = 30; //添加渲染符号 ISymbolArray symbolArray = pieChartSymbol as ISymbolArray; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 255, 0); symbolArray.AddSymbol(fillSymbol as ISymbol); fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 0, 255); symbolArray.AddSymbol(fillSymbol as ISymbol); chartRenderer.ChartSymbol = pieChartSymbol as IChartSymbol; fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(100, 100, 100); chartRenderer.BaseSymbol = fillSymbol as ISymbol; chartRenderer.UseOverposter = false; //创建图例 chartRenderer.CreateLegend(); geoFeatureLayer.Renderer = chartRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }
private void method_4() { if (this.igeoFeatureLayer_0 == null) { this.ichartRenderer_0 = null; } else { IChartRenderer pInObject = this.igeoFeatureLayer_0.Renderer as IChartRenderer; if (pInObject == null) { if (this.ichartRenderer_0 == null) { this.ichartRenderer_0 = new ChartRendererClass(); if (this.int_0 == 0) { this.ichartRenderer_0.ChartSymbol = new PieChartSymbolClass(); } else if (this.int_0 == 1) { this.ichartRenderer_0.ChartSymbol = new BarChartSymbolClass(); } else { this.ichartRenderer_0.ChartSymbol = new StackedChartSymbolClass(); } (this.ichartRenderer_0.ChartSymbol as IMarkerSymbol).Size = 32.0; } } else { IObjectCopy copy = new ObjectCopyClass(); this.ichartRenderer_0 = copy.Copy(pInObject) as IChartRenderer; IChartSymbol chartSymbol = this.ichartRenderer_0.ChartSymbol; IChartSymbol symbol2 = null; if (this.int_0 == 0) { if (!(chartSymbol is IPieChartSymbol)) { symbol2 = new PieChartSymbolClass(); } } else if (this.int_0 == 1) { if (!(chartSymbol is IBarChartSymbol)) { symbol2 = new BarChartSymbolClass(); } } else if ((this.int_0 == 2) && !(chartSymbol is IStackedChartSymbol)) { symbol2 = new StackedChartSymbolClass(); } if (symbol2 != null) { ISymbolArray array = chartSymbol as ISymbolArray; for (int i = 0; i < array.SymbolCount; i++) { (symbol2 as ISymbolArray).AddSymbol(array.get_Symbol(i)); } this.ichartRenderer_0.ChartSymbol = symbol2; } } } }
private void btn_OK_Click(object sender, EventArgs e) { string LayerName = cbx_Layer.SelectedItem.ToString(); IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; ITable pTable = (ITable)pGeoFeatureLayer; ICursor pCursor = pTable.Search(null, true); int numFields = lstbx_RightFields.Items.Count; string[] fildName = new string[numFields]; int[] fieldIndecies = new int[numFields]; for (int i = 0; i < numFields; i++) { if (lstbx_RightFields.Items[i].ToString() != "None") { fildName[i] = lstbx_RightFields.Items[i].ToString(); fieldIndecies[i] = pTable.FindField(fildName[i]); } else { MessageBox.Show("不可用的字段,请选择其它图层"); return; } } //fieldIndecies[0] = pTable.FindField(strPopField1); //fieldIndecies[1] = pTable.FindField(strPopField2); bool firstValue = true; double dmaxValue = 0.0; //Iterate across each feature IRowBuffer pRowBuffer = pCursor.NextRow(); double dfieldValue; while (pRowBuffer != null) { // iterate through each data field and update the maxVal if needed for (int lfieldIndex = 0; lfieldIndex <= numFields - 1; lfieldIndex++) { dfieldValue = (double)pRowBuffer.get_Value(fieldIndecies[lfieldIndex]); if (firstValue) { // Special case for the first value in a feature class dmaxValue = dfieldValue; firstValue = false; } else { if (dfieldValue > dmaxValue) { // we've got a new biggest value dmaxValue = dfieldValue; } } } pRowBuffer = pCursor.NextRow(); } if (dmaxValue <= 0) { MessageBox.Show("Failed to gather stats on the feature class"); return; } IChartRenderer pChartRenderer = new ChartRendererClass(); //Set up the fields to draw charts of IRendererFields pRendererFields = (IRendererFields)pChartRenderer; for (int i = 0; i < numFields; i++) { pRendererFields.AddField(fildName[i], fildName[i]); } // Set up the chart marker symbol to use with the renderer IPieChartSymbol pPieChartSymbol; pPieChartSymbol = new PieChartSymbolClass(); //饼图使用顺时针方法 pPieChartSymbol.Clockwise = true; //饼图有外轮廓线 pPieChartSymbol.UseOutline = true; IChartSymbol pChartSymbol = (IChartSymbol)pPieChartSymbol; pChartSymbol.MaxValue = dmaxValue; ILineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = getRGB(213, 212, 252); pOutline.Width = 1; //设置外轮廓线的样式 pPieChartSymbol.Outline = pOutline; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)pPieChartSymbol; pMarkerSymbol.Size = 8; IColorRamp pColorRamp = (IColorRamp)m_StyleGallertItem.Item; pColorRamp.Size = pTable.RowCount(null); bool ok = true; pColorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = pColorRamp.Colors; IFillSymbol pFillSymbol; ISymbolArray pSymbolArray = (ISymbolArray)pPieChartSymbol; for (int i = 0; i < numFields; i++) { pFillSymbol = new SimpleFillSymbolClass(); for (int j = 0; j < 8; j++) { pEnumRamp.Next(); } pFillSymbol.Color = pEnumRamp.Next(); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); } //Now set the barchart symbol into the renderer pChartRenderer.ChartSymbol = (IChartSymbol)pPieChartSymbol; // pChartRenderer.Label = "Population"; //set up the background symbol to use tan color pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = m_BackGroundColor; pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; pChartRenderer.UseOverposter = false; IPieChartRenderer pPieChartRenderer = pChartRenderer as IPieChartRenderer; pPieChartRenderer.MinSize = 3; //设置最小值,用于尺寸比例 pPieChartRenderer.MinValue = 453588; pPieChartRenderer.FlanneryCompensation = false; pPieChartRenderer.ProportionalBySum = true; //pChartRenderer.Label = "Population"; //产生图例对象 pChartRenderer.CreateLegend(); //pdate the renderer and refresh the screen pGeoFeatureLayer.Renderer = (IFeatureRenderer)pChartRenderer; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
//柱状表图 private void button5_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; ITable table; ICursor cursor; IRowBuffer rowBuffer; //设置渲染要素 string field1 = "SHAPE_Area"; string field2 = "SHAPE_Leng"; //获取渲染图层 geoFeatureLayer = getGeoLayer("东丰县行政区域"); featureLayer = geoFeatureLayer as IFeatureLayer; table = featureLayer as ITable; geoFeatureLayer.ScaleSymbols = true; IChartRenderer chartRenderer = new ChartRendererClass(); IRendererFields rendererFields = chartRenderer as IRendererFields; rendererFields.AddField(field1, field1); rendererFields.AddField(field2, field2); int[] fieldIndexs = new int[2]; fieldIndexs[0] = table.FindField(field1); fieldIndexs[1] = table.FindField(field2); //获取要素最大值 double fieldValue = 0.0, maxValue = 0.0; cursor = table.Search(null, true); rowBuffer = cursor.NextRow(); while (rowBuffer != null) { for (int i = 0; i < 2; i++) { fieldValue = double.Parse(rowBuffer.get_Value(fieldIndexs[i]).ToString()); if (fieldValue > maxValue) { maxValue = fieldValue; } } rowBuffer = cursor.NextRow(); } //创建水平排列符号 IBarChartSymbol barChartSymbol = new BarChartSymbolClass(); barChartSymbol.Width = 10; IMarkerSymbol markerSymbol = barChartSymbol as IMarkerSymbol; markerSymbol.Size = 50; IChartSymbol chartSymbol = barChartSymbol as IChartSymbol; chartSymbol.MaxValue = maxValue; //添加渲染符号 ISymbolArray symbolArray = barChartSymbol as ISymbolArray; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(255, 0, 0); symbolArray.AddSymbol(fillSymbol as ISymbol); fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 255, 0); symbolArray.AddSymbol(fillSymbol as ISymbol); //设置柱状图符号 chartRenderer.ChartSymbol = barChartSymbol as IChartSymbol; fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 0, 255); chartRenderer.BaseSymbol = fillSymbol as ISymbol; chartRenderer.UseOverposter = false; //创建图例 chartRenderer.CreateLegend(); geoFeatureLayer.Renderer = chartRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }