private void btnMoveDown_Click(object sender, EventArgs e) { int index = this.SelectFieldslistView.SelectedIndices[0]; ListViewItemEx ex = this.SelectFieldslistView.Items[index] as ListViewItemEx; this.SelectFieldslistView.Items.RemoveAt(index); if ((index + 1) == this.SelectFieldslistView.Items.Count) { this.SelectFieldslistView.Items.Add(ex); } else { this.SelectFieldslistView.Items.Insert(index + 1, ex); } ISymbolArray dotDensitySymbol = this.idotDensityRenderer_0.DotDensitySymbol as ISymbolArray; dotDensitySymbol.MoveSymbol(dotDensitySymbol.get_Symbol(index), index + 1); IRendererFields fields = this.idotDensityRenderer_0 as IRendererFields; fields.ClearFields(); for (int i = 0; i < this.SelectFieldslistView.Items.Count; i++) { ex = this.SelectFieldslistView.Items[i] as ListViewItemEx; FieldWrap tag = ex.Tag as FieldWrap; fields.AddField(tag.Name, tag.ToString()); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add DotDensityRender.OnClick implementation string strPopField = "value"; IActiveView pActiveView = m_HookHelper.ActiveView; IMap pMap = m_HookHelper.FocusMap; IGeoFeatureLayer pGeoFeatureLayer = pMap.get_Layer(0) as IGeoFeatureLayer; IDotDensityRenderer pDotDensityRenderer = new DotDensityRendererClass(); IRendererFields pRendererFields = (IRendererFields)pDotDensityRenderer; pRendererFields.AddField(strPopField, strPopField); IDotDensityFillSymbol pDotDensityFillSymbol = new DotDensityFillSymbolClass(); pDotDensityFillSymbol.DotSize = 5; pDotDensityFillSymbol.Color = GetRGB(0, 0, 0); pDotDensityFillSymbol.BackgroundColor = GetRGB(239, 228, 190); ISymbolArray pSymbolArray = (ISymbolArray)pDotDensityFillSymbol; ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerSymbol.Size = 5; pSimpleMarkerSymbol.Color = GetRGB(128, 128, 255); pSymbolArray.AddSymbol((ISymbol)pSimpleMarkerSymbol); pDotDensityRenderer.DotDensitySymbol = pDotDensityFillSymbol; pDotDensityRenderer.DotValue = 0.5; pDotDensityRenderer.CreateLegend(); pGeoFeatureLayer.Renderer = (IFeatureRenderer)pDotDensityRenderer; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
private void DotDensity(IFeatureLayer pFeatLyr, string sFieldName, int intRendererDensity) { IGeoFeatureLayer pGeoFeatureLayer = pFeatLyr as IGeoFeatureLayer; IDotDensityRenderer pDotDensityRenderer = new DotDensityRendererClass(); IRendererFields pRendererFields = pDotDensityRenderer as IRendererFields; //设置渲染字段 pRendererFields.AddField(sFieldName); //设置填充背景色 IDotDensityFillSymbol pDotDensityFillSymbol = new DotDensityFillSymbolClass(); pDotDensityFillSymbol.DotSize = 3; pDotDensityFillSymbol.BackgroundColor = GetRgbColor(0, 255, 0); //设置渲染符号 ISymbolArray pSymbolArray = pDotDensityFillSymbol as ISymbolArray; ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerSymbol.Color = GetRgbColor(0, 0, 255); pSymbolArray.AddSymbol(pSimpleMarkerSymbol as ISymbol); pDotDensityRenderer.DotDensitySymbol = pDotDensityFillSymbol; //设置渲染密度,即每个点符号所代表的数值大小 pDotDensityRenderer.DotValue = intRendererDensity; //创建图例 pDotDensityRenderer.CreateLegend(); pGeoFeatureLayer.Renderer = pDotDensityRenderer as IFeatureRenderer; axMapControl1.Refresh(); axMapControl1.Update(); Close(); }
/// <summary> /// Dot Density Render /// </summary> /// <param name="currentLayer"></param> /// <param name="breakCount"></param> /// <author>Shen Yongyuan</author> /// <date>20091114</date> public static void DotDensityRender(ILayer currentLayer, string fieldName) { IGeoFeatureLayer pGeoFeatureL = currentLayer as IGeoFeatureLayer; pGeoFeatureL.ScaleSymbols = true; //Dot Density Render IDotDensityRenderer pDotDensityRenderer = new DotDensityRendererClass(); IRendererFields pRendererFields = (IRendererFields)pDotDensityRenderer; pRendererFields.AddField(fieldName, "生态"); //Dot Style IDotDensityFillSymbol pDotDensityFillS = new DotDensityFillSymbolClass(); pDotDensityFillS.DotSize = 4; pDotDensityFillS.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(0, 0, 0)); pDotDensityFillS.BackgroundColor = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(239, 228, 190)); //Symbol Array ISymbolArray pSymbolArray = (ISymbolArray)pDotDensityFillS; ISimpleMarkerSymbol pSimpleMarkerS = new SimpleMarkerSymbolClass(); pSimpleMarkerS.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerS.Size = 4; pSimpleMarkerS.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(128, 128, 255)); pSymbolArray.AddSymbol((ISymbol)pSimpleMarkerS); pDotDensityRenderer.DotDensitySymbol = pDotDensityFillS; pDotDensityRenderer.DotValue = 0.05; pDotDensityRenderer.CreateLegend(); pGeoFeatureL.Renderer = (IFeatureRenderer)pDotDensityRenderer; }
//DotDensityFillSymbol private void button8_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IDotDensityFillSymbol dotDensityFillSymbol; IDotDensityRenderer dotDensityRenderer; //获取渲染图层 geoFeatureLayer = getGeoLayer("Continents"); dotDensityRenderer = new DotDensityRendererClass(); IRendererFields rendererFields = dotDensityRenderer as IRendererFields; //设置渲染字段 string field1 = "sqmi"; rendererFields.AddField(field1, field1); //设置填充颜色和背景色 dotDensityFillSymbol = new DotDensityFillSymbolClass(); dotDensityFillSymbol.DotSize = 3; dotDensityFillSymbol.Color = getRGB(255, 0, 0); dotDensityFillSymbol.BackgroundColor = getRGB(0, 255, 0); //设置渲染符号 ISymbolArray symbolArray = dotDensityFillSymbol as ISymbolArray; ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; simpleMarkerSymbol.Size = 2; simpleMarkerSymbol.Color = getRGB(0, 0, 255); symbolArray.AddSymbol(simpleMarkerSymbol as ISymbol); dotDensityRenderer.DotDensitySymbol = dotDensityFillSymbol; //设置渲染密度 dotDensityRenderer.DotValue = 50000; //创建图例 dotDensityRenderer.CreateLegend(); geoFeatureLayer.Renderer = dotDensityRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }
private IDotDensityRenderer CreateRenderer() { IDotDensityRenderer pDotDensityRenderer = new DotDensityRendererClass(); IRendererFields pRendererFields = (IRendererFields)pDotDensityRenderer; IDotDensityFillSymbol pDotDensityFillS = new DotDensityFillSymbolClass(); //pDotDensityFillS.DotSize = 2 * dotSize; //pDotDensityFillS.Color = getRGB(0, 0, 0); if (gColor != null) { pDotDensityFillS.BackgroundColor = gColor; } ISymbolArray pSymbolArray = (ISymbolArray)pDotDensityFillS; string strField = string.Empty; foreach (System.Collections.DictionaryEntry de in fieldSymbolHashTable) { strField = de.Key.ToString();; ISymbol symbol = de.Value as ISymbol; pRendererFields.AddField(strField, strField); IMarkerSymbol pMarkerSymbol = symbol as IMarkerSymbol; pMarkerSymbol.Size = dotSize; pSymbolArray.AddSymbol(symbol); } pDotDensityRenderer.DotDensitySymbol = pDotDensityFillS; pDotDensityRenderer.DotValue = dotValue; pDotDensityRenderer.CreateLegend(); return(pDotDensityRenderer); }
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 mnuDotDensity_Click(object sender, EventArgs e) { ILayer pLayer = MainMap.get_Layer(0); ITable pTable = pLayer as ITable; IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer; IDotDensityRenderer pDotDensityRender = new DotDensityRendererClass(); IRendererFields pRendererFields = pDotDensityRender as IRendererFields; pRendererFields.AddField("AREA"); // 建立一个用于填充的点符号 IDotDensityFillSymbol pDotDensityFillSymbol = new DotDensityFillSymbolClass(); pDotDensityFillSymbol.DotSize = 3; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 0; pRgbColor.Green = 0; pRgbColor.Blue = 0; IColor pColor = pRgbColor as IColor; pDotDensityFillSymbol.Color = pColor; pRgbColor = new RgbColorClass(); pRgbColor.Red = 239; pRgbColor.Green = 228; pRgbColor.Blue = 190; pColor = pRgbColor as IColor; pDotDensityFillSymbol.BackgroundColor = pColor; ISymbolArray pSymbolArray = pDotDensityFillSymbol as ISymbolArray; ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass(); pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare; pRgbColor = new RgbColorClass(); pRgbColor.Red = 0; pRgbColor.Green = 0; pRgbColor.Blue = 0; pColor = pRgbColor as IColor; pMarkerSymbol.Color = pColor; pSymbolArray.AddSymbol(pMarkerSymbol as ISymbol); // 开始着色 pDotDensityRender.DotDensitySymbol = pDotDensityFillSymbol; pDotDensityRender.DotValue = 2; pGeoFeatureLayer.Renderer = pDotDensityRender as IFeatureRenderer; MainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
/// <summary> /// 点状密度法渲染器(DotDensityRenderer)——在多边形特征中绘制不同密度的点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 点状密度法渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //声明IGeoFeatureLayer变量, 提供一个要素图层对成员控制地理特征的入口 IGeoFeatureLayer geoFeatureLayer; //定义点密度填充符号变量, 控制点符号的属性 IDotDensityFillSymbol dotDensityFillSymbol; //定义点密度渲染对象 IDotDensityRenderer dotDensityRenderer; //获取渲染图层 geoFeatureLayer = getGeoLayer("北部湾"); //实例化点密度渲染对象 dotDensityRenderer = new DotDensityRendererClass(); //强转点密度渲染对象并强转成渲染字段对象 IRendererFields rendererFields = dotDensityRenderer as IRendererFields; //设置渲染字段 string field1 = "年"; //向渲染器添加字段(字段名、别名) rendererFields.AddField(field1, field1); //实例化点密度填充符号 dotDensityFillSymbol = new DotDensityFillSymbolClass(); dotDensityFillSymbol.DotSize = 4; //设置点的大小 dotDensityFillSymbol.Color = getRGB(0, 255, 0); //设置点的颜色 //将点密度填充符号强转为符号数组成员 ISymbolArray symbolArray = dotDensityFillSymbol as ISymbolArray; //实例化简单标记符号 ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); //设置点的符号为圆圈 simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; simpleMarkerSymbol.Size = 4; //设置大小 simpleMarkerSymbol.Color = getRGB(0, 255, 0); //设置颜色 //点符号的外边不填充颜色 simpleMarkerSymbol.OutlineColor = getNoRGB(); //将简单标记符号样式增加到符号数组成员中 symbolArray.AddSymbol(simpleMarkerSymbol as ISymbol); //赋值点密度渲染(dotDensityRenderer)的点密度符号(DotDensitySymbol)属性 dotDensityRenderer.DotDensitySymbol = dotDensityFillSymbol; //设置渲染密度 dotDensityRenderer.DotValue = 0.003; //设置点密度填充符号的背景色 dotDensityFillSymbol.BackgroundColor = getRGB(255, 255, 255); //创建图例 dotDensityRenderer.CreateLegend(); //赋值目标图层的渲染器属性 geoFeatureLayer.Renderer = dotDensityRenderer as IFeatureRenderer; axMapControl1.Refresh(); //刷新axMapControl1 axTOCControl1.Update(); //更新axTOCControl1 }
private IChartRenderer CreateRenderer(IFeatureClass featureClass) { if (chartSymbol == null) { return(null); } double dmaxValue = 0.0; dmaxValue = FindMaxValueInRendererFields(featureClass); chartSymbol.MaxValue = dmaxValue; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)chartSymbol; pMarkerSymbol.Size = symbolSize; //Now set up symbols for each bar ISymbolArray pSymbolArray = (ISymbolArray)chartSymbol; pSymbolArray.ClearSymbols(); IChartRenderer pChartRenderer = new ChartRendererClass(); IRendererFields pRendererFields = (IRendererFields)pChartRenderer; foreach (System.Collections.DictionaryEntry de in fieldSymbolHashTable) { string strField = de.Key.ToString();; ISymbol symbol = de.Value as ISymbol; pRendererFields.AddField(strField, strField); pSymbolArray.AddSymbol(symbol); } pChartRenderer.ChartSymbol = chartSymbol; pChartRenderer.Label = "统计符号化"; pChartRenderer.UseOverposter = false; if (gBaseSymbol != nudDotSize) { pChartRenderer.BaseSymbol = gBaseSymbol; } pChartRenderer.CreateLegend(); return(pChartRenderer); }
private void btnMoveUp_Click(object sender, EventArgs e) { int index = this.SelectFieldslistView.SelectedIndices[0]; ListViewItemEx item = this.SelectFieldslistView.Items[index] as ListViewItemEx; this.SelectFieldslistView.Items.RemoveAt(index); this.SelectFieldslistView.Items.Insert(index - 1, item); ISymbolArray chartSymbol = this.ichartRenderer_0.ChartSymbol as ISymbolArray; chartSymbol.MoveSymbol(chartSymbol.get_Symbol(index), index - 1); IRendererFields fields = this.ichartRenderer_0 as IRendererFields; fields.ClearFields(); for (int i = 0; i < this.SelectFieldslistView.Items.Count; i++) { item = this.SelectFieldslistView.Items[i] as ListViewItemEx; FieldWrap tag = item.Tag as FieldWrap; fields.AddField(tag.Name, tag.ToString()); } }
//柱状表图 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(); }
/// <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 DotRender(AxMapControl pMapControl, IFeatureLayer pFtLayer, double pValue, string pFieldName) { //IActiveView pActiveView; //this.pGeoLayer = pFtLayer as IGeoFeatureLayer; //pActiveView = pMapControl.ActiveView; //pDotDensityRenderer = new DotDensityRendererClass(); //pRendFields = pDotDensityRenderer as IRendererFields; //pRendFields.AddField(pFieldName, pFieldName); //同一个对象的接口的切换,很方便的。 //this.pDotDensityFill = new DotDensityFillSymbolClass(); //pDotDensityFill.DotSize = 8; //pDotDensityFill.Color = GetRGBColor(10, 20, 0); //pDotDensityFill.BackgroundColor = GetRGBColor(100, 108, 190); //pSymbolArry = pDotDensityFill as ISymbolArray;//难道是密度。 //ISimpleMarkerSymbol pSimpleMark; //pSimpleMark = new SimpleMarkerSymbolClass(); //pSimpleMark.Style = esriSimpleMarkerStyle.esriSMSDiamond; //pSimpleMark.Size = 8; //pSimpleMark.Color = GetRGBColor(128, 128, 255); //pSymbolArry.AddSymbol(pSimpleMark as ISymbol); //pDotDensityRenderer.DotDensitySymbol = pDotDensityFill; //pDotDensityRenderer.DotValue = pValue; //pDotDensityRenderer.CreateLegend(); //pGeoLayer.Renderer = (IFeatureRenderer)pDotDensityRenderer; //pActiveView.Refresh(); //获取当前图层 ,并把它设置成IGeoFeatureLayer的实例 IMap pMap = pMapControl.Map; // ILayer pFtLayer = pMap.get_Layer(0) as IFeatureLayer; IFeatureLayer pFeatureLayer = pFtLayer as IFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer = pFtLayer as IGeoFeatureLayer; //获取图层上的feature IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); IFeature pFeature = pFeatureCursor.NextFeature(); /////////////////////// /////////////////////////////////////////////////////////////////// //定义点密度图渲染组件 IDotDensityRenderer DotDensityRenderer = new DotDensityRendererClass(); //定义点密度图渲染组件对象的渲染字段对象 IRendererFields flds = (IRendererFields)DotDensityRenderer; flds.AddField(pFieldName, pFieldName); //flds.AddField("Shape", "Shape"); //定义点密度图渲染得符号对象 IDotDensityFillSymbol ddSym = new DotDensityFillSymbolClass(); IRgbColor BackColor = new RgbColorClass(); BackColor.Red = 234; BackColor.Blue = 128; BackColor.Green = 220; IRgbColor SymbolColor = new RgbColorClass(); SymbolColor.Red = 234; SymbolColor.Blue = 128; SymbolColor.Green = 220; ////点密度图渲染背景颜色 //ddSym.BackgroundColor = BackColor; ddSym.DotSize = 8; ddSym.FixedPlacement = true; //ddSym.Color = SymbolColor; ILineSymbol pLineSymbol = new CartographicLineSymbolClass(); ddSym.Outline = pLineSymbol; //定义符号数组 ISymbolArray symArray = (ISymbolArray)ddSym; //添加点密度图渲染的点符号到符号数组中去 ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass(); pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pMarkerSymbol.Size = 0.2; pMarkerSymbol.Color = SymbolColor;; symArray.AddSymbol(pMarkerSymbol as ISymbol); //设置点密度图渲染的点符号 //DotDensityRenderer.DotDensitySymbol =symArray; DotDensityRenderer.DotDensitySymbol = ddSym; //确定一个点代表多少值 DotDensityRenderer.DotValue = pValue; //点密度渲染采用的颜色模式 DotDensityRenderer.ColorScheme = "Custom"; //创建点密度图渲染图例 DotDensityRenderer.CreateLegend(); //设置符号大小是否固定 DotDensityRenderer.MaintainSize = true; //将点密度图渲染对象与渲染图层挂钩 pGeoFeatureLayer.Renderer = (IFeatureRenderer)DotDensityRenderer; //刷新地图和TOOCotrol IActiveView pActiveView = pMap as IActiveView; pActiveView.Refresh(); }
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); }
//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(); }
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(); }