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; }
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); }
private void ChartRenderer(IFeatureLayer pFeatLyr, Dictionary <string, IRgbColor> dicFieldAndColor) { IChartRenderer chartRenderer = new ChartRendererClass(); IDataStatistics dataSta = new DataStatisticsClass(); dataSta.Field = m_pTarField.Name; dataSta.Cursor = m_pTarFeatureClass.Search(null, false) as ICursor; double max = Double.MinValue; foreach (string fieldName in dicFieldAndColor.Keys) { (chartRenderer as IRendererFields).AddField(fieldName, fieldName); max = max > dataSta.Statistics.Maximum ? max : dataSta.Statistics.Maximum; } IBarChartSymbol barSyb = null; barSyb = new BarChartSymbolClass(); (barSyb as IChartSymbol).MaxValue = max; barSyb.Width = 6; (barSyb as IMarkerSymbol).Size = 30; IFillSymbol barSymbol = new SimpleFillSymbolClass(); barSymbol.Color = m_pFillColor; (barSyb as ISymbolArray).AddSymbol(barSymbol as ISymbol); IFillSymbol baseSymbol = new SimpleFillSymbolClass(); baseSymbol.Color = m_pOutlineColor; chartRenderer.ChartSymbol = barSyb as IChartSymbol; chartRenderer.BaseSymbol = baseSymbol as ISymbol; m_pTarGeoFeatureLayer.Renderer = chartRenderer as IFeatureRenderer; chartRenderer.CreateLegend(); frmMainOper(OperationType.RefreshMapCtrl); frmMainOper(OperationType.UpdateTOCCtrl); }
public override void OnClick() { IGeoFeatureLayer pGeoFeatureL; IFeatureLayer pFeatureLayer; ITable pTable; ICursor pCursor; IQueryFilter pQueryFilter; IRowBuffer pRowBuffer; int numFields = 2; int[] fieldIndecies = new int[numFields]; int lfieldIndex; double dmaxValue; bool firstValue; double dfieldValue; IChartRenderer pChartRenderer; IRendererFields pRendererFields; IFillSymbol pFillSymbol; IMarkerSymbol pMarkerSymbol; ISymbolArray pSymbolArray; IChartSymbol pChartSymbol; string strPopField1 = "population"; string strPopField2 = "jingji"; //pActiveView = m_hookHelper.ActiveView; //pMap = m_hookHelper.FocusMap; //pMap.ReferenceScale = pMap.MapScale ; // pFeatureLayer = (IGeoFeatureLayer) pMap.get_Layer(1);//Parameter!!! pGeoFeatureL = (IGeoFeatureLayer)m_pLayer; pTable = (ITable)pGeoFeatureL; pGeoFeatureL.ScaleSymbols = true; pChartRenderer = new ChartRendererClass(); pRendererFields = (IRendererFields)pChartRenderer; pRendererFields.AddField(strPopField1, strPopField1); pRendererFields.AddField(strPopField2, strPopField2); pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(strPopField1); pQueryFilter.AddField(strPopField2); pCursor = pTable.Search(pQueryFilter, true); fieldIndecies[0] = pTable.FindField(strPopField1); fieldIndecies[1] = pTable.FindField(strPopField2); firstValue = true; dmaxValue = 0; pRowBuffer = pCursor.NextRow(); while (pRowBuffer != null) { for (lfieldIndex = 0; lfieldIndex <= numFields - 1; lfieldIndex++) { dfieldValue = (double)Convert.ToInt32(pRowBuffer.get_Value(fieldIndecies[lfieldIndex])); if (firstValue) { dmaxValue = dfieldValue; firstValue = false; } else { if (dfieldValue > dmaxValue) { dmaxValue = dfieldValue; } //Set up the fields to draw charts of //Make an array of the field numbers to iterate accross, this is to keep the code generic in the number of bars to draw. //Iterate across each feature // iterate through each data field and update the maxVal if needed // Special case for the first value in a feature class // we've got a new biggest value } } pRowBuffer = pCursor.NextRow(); } if (dmaxValue <= 0) { MessageBox.Show("Failed to gather stats on the feature class"); Application.Exit(); } IBarChartSymbol pBarChartSymbol; pBarChartSymbol = new BarChartSymbolClass(); pChartSymbol = (IChartSymbol)pBarChartSymbol; pBarChartSymbol.Width = 12; pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol; pChartSymbol.MaxValue = dmaxValue; pMarkerSymbol.Size = 80; pSymbolArray = (ISymbolArray)pBarChartSymbol; pFillSymbol = new SimpleFillSymbolClass(); IRgbColor pRGB = new RgbColorClass(); pRGB.Red = 213; pRGB.Green = 212; pRGB.Blue = 252; pFillSymbol.Color = pRGB; pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pFillSymbol = new SimpleFillSymbolClass(); pRGB.Red = 193; pRGB.Green = 252; pRGB.Blue = 179; pFillSymbol.Color = pRGB; pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pChartRenderer.ChartSymbol = (IChartSymbol)pBarChartSymbol; pChartRenderer.Label = "Population"; pFillSymbol = new SimpleFillSymbolClass(); pRGB.Red = 293; pRGB.Green = 228; pRGB.Blue = 190; pFillSymbol.Color = pRGB; pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; // Set up the chart marker symbol to use with the renderer //Finally we've got the biggest value, set this into the symbol //This is the maximum height of the bars //Now set up symbols for each bar // Add some colours in for each bar //This is a pastel green //Now set the barchart symbol into the renderer //set up the background symbol to use tan color //Disable overpoaster so that charts appear in the centre of polygons pChartRenderer.UseOverposter = false; pChartRenderer.CreateLegend(); pGeoFeatureL.Renderer = (IFeatureRenderer)pChartRenderer; //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public BarRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, String pFieldName1, string pFieldName2) { //IGeoFeatureLayer pGeoFeatureLayer = pFtLayer as IGeoFeatureLayer; //IFeatureClass pFeatureClass = pFtLayer.FeatureClass; ////定义柱状图渲染组建对象 //IChartRenderer pChartRenderer = new ChartRendererClass(); ////定义渲染字段对象并给字段对象实例化为pChartRenderer //IRendererFields pRendererFields; //pRendererFields = (IRendererFields)pChartRenderer; ////向渲染字段对象中添加字段--- 待补充自定义添加 //pRendererFields.AddField(pFieldName1, pFieldName1); //pRendererFields.AddField(pFieldName2, pFieldName2); //ITable pTable; //pTable = pGeoFeatureLayer as ITable; //int[] pFieldIndecies = new int[2]; //pFieldIndecies[0] = pTable.FindField(pFieldName1); //pFieldIndecies[1] = pTable.FindField(pFieldName2); //IDataStatistics pDataStat = new DataStatisticsClass(); //IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false); //pDataStat.Cursor = pFtCursor as ICursor; //pDataStat.Field = pFieldName2; //double pMax = pDataStat.Statistics.Maximum; //// 定义并设置渲染时用的chart marker symbol //IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass(); //pBarChartSymbol.Width = 6; //IChartSymbol pChartSymbol; //pChartSymbol = pBarChartSymbol as IChartSymbol; //IMarkerSymbol pMarkerSymbol; //pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol; //IFillSymbol pFillSymbol; ////设置pChartSymbol的最大值 //pChartSymbol.MaxValue = pMax; //// 设置bars的最大高度 //pMarkerSymbol.Size = 80; ////下面给每一个bar设置符号 ////定义符号数组 //ISymbolArray pSymbolArray = (ISymbolArray)pBarChartSymbol; ////添加第一个符号 //pFillSymbol = new SimpleFillSymbolClass(); //pFillSymbol.Color = GetRGBColor(193, 252, 179) as IColor; //pSymbolArray.AddSymbol(pFillSymbol as ISymbol); ////添加第二个符号 //pFillSymbol = new SimpleFillSymbolClass(); // pFillSymbol.Color = GetRGBColor(145, 55, 251) as IColor; //pSymbolArray.AddSymbol(pFillSymbol as ISymbol); //pChartRenderer.ChartSymbol = pChartSymbol as IChartSymbol; ////pChartRenderer.Label = "AREA"; //pChartRenderer.CreateLegend(); //pChartRenderer.UseOverposter = false; ////将柱状图渲染对象与渲染图层挂钩 //pGeoFeatureLayer.Renderer = (IFeatureRenderer)pChartRenderer; ////刷新地图和TOOCotrol //IActiveView pActiveView = pMapcontrol .ActiveView as IActiveView; //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); //获取当前图层 ,并把它设置成IGeoFeatureLayer的实例 IMap pMap = pMapcontrol.Map; ILayer pLayer = pMap.get_Layer(0) as IFeatureLayer; IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer; //获取图层上的feature IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; //定义柱状图渲染组建对象 IChartRenderer pChartRenderer = new ChartRendererClass(); //定义渲染字段对象并给字段对象实例化为pChartRenderer IRendererFields pRendererFields; pRendererFields = (IRendererFields)pChartRenderer; //向渲染字段对象中添加字段--- 待补充自定义添加 pRendererFields.AddField(pFieldName1, pFieldName1); pRendererFields.AddField(pFieldName2, pFieldName2); // 通过查找features的所用字段的值,计算出数据字段的最大值,作为设置柱状图的比例大小的依据 ITable pTable; int fieldNumber; pTable = pGeoFeatureLayer as ITable; // 查找出geoFeatureLayer的属性表中的字段个数 fieldNumber = pTable.FindField(pFieldName1); if (fieldNumber == -1) { MessageBox.Show("Can't find field called ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } const int numFields = 2;// 设置bars的个数 int[] fieldIndecies = new int[2]; //long fieldIndex; double maxValue; bool firstValue; //double[] fieldValue=new double[5]; double fieldValue; fieldIndecies[0] = pTable.FindField(pFieldName1); fieldIndecies[1] = pTable.FindField(pFieldName2); firstValue = true; maxValue = 0; int n = pFeatureClass.FeatureCount(null); for (int i = 0; i < numFields; i++) { IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); for (int j = 0; j < n; j++) { IFeature pFeature = pFeatureCursor.NextFeature(); fieldValue = Convert.ToDouble(pFeature.get_Value(fieldIndecies[i])); if (firstValue) { //给maxValue赋初值 maxValue = fieldValue; firstValue = false; } else if (fieldValue > maxValue) { maxValue = fieldValue; } } } if (maxValue <= 0) { MessageBox.Show("Failed to calculate the maximum value or maxvalue is 0.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } // 定义并设置渲染时用的chart marker symbol IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass(); pBarChartSymbol.Width = 6; IChartSymbol pChartSymbol; pChartSymbol = pBarChartSymbol as IChartSymbol; IMarkerSymbol pMarkerSymbol; pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol; IFillSymbol pFillSymbol; //设置pChartSymbol的最大值 pChartSymbol.MaxValue = maxValue; // 设置bars的最大高度 pMarkerSymbol.Size = 16; //下面给每一个bar设置符号 //定义符号数组 ISymbolArray pSymbolArray = (ISymbolArray)pBarChartSymbol; //克隆pFillSymbol用于符号操作 //IClone pSourceClone = pFillSymbol as IClone; //ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol; // 向符号数组中添加设置后的符号 //pSimpleFillSymbol.Color = GetRGBColor(193, 252, 179); //pSymbolArray.AddSymbol(pSimpleFillSymbol as ISymbol); //pSimpleFillSymbol.Color = GetRGBColor(145, 55, 200); //pSymbolArray.AddSymbol(pSimpleFillSymbol as ISymbol); //添加第一个符号 pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = GetRGBColor(193, 252, 179) as IColor; pSymbolArray.AddSymbol(pFillSymbol as ISymbol); //添加第二个符号 pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = GetRGBColor(145, 55, 251) as IColor; pSymbolArray.AddSymbol(pFillSymbol as ISymbol); // 设置背景符号 //pSimpleFillSymbol.Color = GetRGBColor(239, 150, 190); //pChartRenderer.BaseSymbol = pSimpleFillSymbol as ISymbol; // Disable overpoaster 让符号处于图形中央 pChartRenderer.UseOverposter = false; //pChartRenderer.ChartSymbol = pSymbolArray as IChartSymbol; pChartRenderer.ChartSymbol = pChartSymbol as IChartSymbol; //pChartRenderer.Label = "AREA"; pChartRenderer.CreateLegend(); //将柱状图渲染对象与渲染图层挂钩 pGeoFeatureLayer.Renderer = (IFeatureRenderer)pChartRenderer; pGeoFeatureLayer.DisplayField = pFieldName1; //刷新地图和TOOCotrol IActiveView pActiveView = pMapcontrol.Map as IActiveView; pActiveView.Refresh(); }
/// <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 polygonQualityDye(ILayer pLayer) { IGeoFeatureLayer pGeoFeatureL; IFeatureLayer pFeatureLayer; ITable pTable; ICursor pCursor; IQueryFilter pQueryFilter; IRowBuffer pRowBuffer; int numFields = 2; int[] fieldIndecies = new int[numFields]; int iFieldIndex; double dMaxValue; bool isFirstValue; double dFieldValue; IChartRenderer pChartRenderer; IRendererFields pRenderFields; IFillSymbol pFillSymbol; IMarkerSymbol pMarkerSymbol; ISymbolArray pSymbolArray; IChartSymbol pCharSymbol; //设置需要的字段信息 string strPopField1 = cbField1.Text; string strPopField2 = cbField2.Text; IMap pMap = axMapControl1.Map; pMap.ReferenceScale = pMap.MapScale; pFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureL = (IGeoFeatureLayer)pFeatureLayer; pTable = (ITable)pGeoFeatureL; pGeoFeatureL.ScaleSymbols = true; pChartRenderer = new ChartRendererClass(); //设置柱状图中所需要绘制的属性 pRenderFields = (IRendererFields)pChartRenderer; pRenderFields.AddField(strPopField1, strPopField1); pRenderFields.AddField(strPopField2, strPopField2); pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(strPopField1); pQueryFilter.AddField(strPopField2); pCursor = pTable.Search(pQueryFilter, true); fieldIndecies[0] = pTable.FindField(strPopField1); fieldIndecies[1] = pTable.FindField(strPopField2); isFirstValue = true; dMaxValue = 0; //迭代坊问每一个要素 pRowBuffer = pCursor.NextRow(); try { while (pRowBuffer != null) { for (iFieldIndex = 0; iFieldIndex <= numFields - 1; iFieldIndex++) { //迭代访问要素的字段值并对最大值进行更新和标记 dFieldValue = double.Parse(pRowBuffer.get_Value(fieldIndecies[iFieldIndex]).ToString()); if (isFirstValue) { //将最大值dmax初始化为第一个值 dMaxValue = dFieldValue; isFirstValue = false; } else { if (dFieldValue > dMaxValue) { //获取最大值时候进行更新 dMaxValue = dFieldValue; } } } pRowBuffer = pCursor.NextRow(); } } catch (Exception ex) { MessageBox.Show("该字段中有不合法的值,请重新选择字段"); } if (dMaxValue <= 0) { MessageBox.Show("获取要素失败"); return; } //设置需要渲染的柱状图符号 IBarChartSymbol pBarChartSymbol; pBarChartSymbol = new BarChartSymbolClass(); pCharSymbol = (IChartSymbol)pBarChartSymbol; pBarChartSymbol.Width = 12; pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol; //设置柱状图的最大值 pCharSymbol.MaxValue = dMaxValue; //设置柱状图的最大渲染高度 pMarkerSymbol.Size = 80; //为每个柱状图设置符号 pSymbolArray = (ISymbolArray)pBarChartSymbol; //为每个柱状图添加颜色 pFillSymbol = new SimpleFillSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 213; color.Green = 212; color.Blue = 252; pFillSymbol.Color = color; pSymbolArray.AddSymbol((ISymbol)pFillSymbol); pFillSymbol = new SimpleFillSymbolClass(); color.Red = 193; color.Green = 252; color.Blue = 179; pFillSymbol.Color = color; pSymbolArray.AddSymbol((ISymbol)pFillSymbol); //设置渲染符号为柱状图 pChartRenderer.ChartSymbol = (IChartSymbol)pBarChartSymbol; pChartRenderer.Label = cbField1.Text; //设置柱状图的背景颜色 pFillSymbol = new SimpleFillSymbolClass(); color.Red = 239; color.Green = 228; color.Blue = 190; pFillSymbol.Color = color; pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; //设置overpoaster属性为false,使柱状图显示在polygon多边形要素的中间 pChartRenderer.UseOverposter = false; pChartRenderer.CreateLegend(); //更新柱状图和刷新显示 pGeoFeatureL.Renderer = (IFeatureRenderer)pChartRenderer; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
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 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(); }
//此专题图制作跟StackedChart差不多 private void btnBarChartRender_Click(object sender, EventArgs e) { IGeoFeatureLayer pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer; //用DataStatistics对象,得到两个字段最大值的较大值(最最大) double p1, p2, max; ICursor pCursor = (ICursor)pGeoFeatLyr.Search(null, true); IDataStatistics pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pCursor; pDataStatistics.Field = "GDP_1999("; p1 = pDataStatistics.Statistics.Maximum; pCursor = (ICursor)pGeoFeatLyr.Search(null, true); pDataStatistics.Cursor = pCursor; pDataStatistics.Field = "GDP_1994("; p2 = pDataStatistics.Statistics.Maximum; max = p1 > p2 ? p1 : p2; //以下生成好三个SimpleFillSymbol,留作后用 ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = getRGBColor(255, 0, 0); pSimpleFillSymbol.Outline = null; ISimpleFillSymbol pSimpleFillSymbol2 = new SimpleFillSymbolClass(); pSimpleFillSymbol2.Color = getRGBColor(0, 0, 255); pSimpleFillSymbol2.Outline = null; ISimpleFillSymbol pSimpleFillSymbol3 = new SimpleFillSymbolClass(); pSimpleFillSymbol3.Color = getRGBColor(0, 255, 0); //创建并设置BarChartSymbol,以及设置好BarChartSymbol里的各自Symbol IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass(); pBarChartSymbol.Width = 6;//宽度 pBarChartSymbol.Spacing = 1;//Bar之间的间隔 IChartSymbol pChartSymbol = pBarChartSymbol as IChartSymbol; pChartSymbol.MaxValue = max;//用到了上面求出的最大值 ISymbolArray pSymbolArray = pBarChartSymbol as ISymbolArray;//用于在BarChartSymbol里添加Symbol,关键 pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol); pSymbolArray.AddSymbol((ISymbol)pSimpleFillSymbol2); IMarkerSymbol pMarkerSymbol = pBarChartSymbol as IMarkerSymbol; pMarkerSymbol.Size = 60;//BarChartSymbol符号大小 //以下创建并设置着色对象 IChartRenderer pChartRenderer = new ChartRendererClass(); IRendererFields pRendererFields = pChartRenderer as IRendererFields;//添加用于着色的字段,关键 pRendererFields.AddField("GDP_1994(", "GDP_1994("); pRendererFields.AddField("GDP_1999(", "GDP_1999("); pChartRenderer.ChartSymbol = pChartSymbol;//赋给上面创建的BarChartSymbol pChartRenderer.BaseSymbol = pSimpleFillSymbol3 as ISymbol; pChartRenderer.Label = "GDP"; pChartRenderer.UseOverposter = true; pChartRenderer.CreateLegend();//创建图例,关键 pGeoFeatLyr.Renderer = pChartRenderer as IFeatureRenderer; this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); this.axTOCControl.Update(); }
//BarChartSymbol private void button5_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(); 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(); }
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; } } } }