ArcEngine开发总结-(2)矢量数据渲染
包括分级渲染、简单渲染、唯一值渲染、柱状图渲染、饼状图渲染
/// <summary> /// 生成分级渲染符号图 /// </summary> /// <param name="pFiledName">分级字段</param> ///<param name="ClassifyItems">分级信息数组</param> ///<param name="minBreak">分类起始值</param> /// <returns>FeatureRenderer</returns> public IFeatureRenderer SetClassBreaksRenderer(string pFiledName, List<ClassifyItemClient> ClassifyItems, double minBreak) { IClassBreaksRenderer pClassBreaksRenderer; IFeatureRenderer pFeatureRenderer; pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = pFiledName; if (minBreak != 0) pClassBreaksRenderer.MinimumBreak = minBreak; pClassBreaksRenderer.BreakCount = ClassifyItems.Count; for (int i = 0; i < ClassifyItems.Count; i++) { pClassBreaksRenderer.set_Symbol(i, ClassifyItems[i].ClassifySymbol); pClassBreaksRenderer.set_Break(i, Convert.ToDouble(ClassifyItems[i].Break)); pClassBreaksRenderer.set_Label(i, ClassifyItems[i].Label); pClassBreaksRenderer.set_Description(i, ClassifyItems[i].Description); } pFeatureRenderer = pClassBreaksRenderer as IFeatureRenderer; //ReleaseAE.ReleaseAEObject(pClassBreaksRenderer); return pFeatureRenderer; } /// <summary> /// 生成唯一值渲染 /// </summary> /// <param name="pFiledName">渲染字段</param> ///<param name="ClassifyItems">唯一值信息数组</param> /// <returns></returns> public IFeatureRenderer SetUniqueValueRenderer(string pFiledName, List<ClassifyItemClient> ClassifyItems) { IUniqueValueRenderer pUniqueValueRender; IFeatureRenderer pFeatureRenderer; pUniqueValueRender = new UniqueValueRendererClass(); pUniqueValueRender.FieldCount = 1; pUniqueValueRender.set_Field(0,pFiledName); for (int i = 0; i < ClassifyItems.Count; i++) { if (ClassifyItems[i].ReferenceValue==null) pUniqueValueRender.AddValue(ClassifyItems[i].Break, pFiledName, ClassifyItems[i].ClassifySymbol); else pUniqueValueRender.AddReferenceValue(ClassifyItems[i].Break, ClassifyItems[i].ReferenceValue); pUniqueValueRender.set_Label(ClassifyItems[i].Break, ClassifyItems[i].Label); pUniqueValueRender.set_Description(ClassifyItems[i].Break, ClassifyItems[i].Description); } pFeatureRenderer = pUniqueValueRender as IFeatureRenderer; //ReleaseAE.ReleaseAEObject(pUniqueValueRender); return pFeatureRenderer; } /// <summary> /// 生成简单渲染 /// </summary> /// <param name="symbol">渲染符号</param> /// <param name="label">渲染标注</param> /// <param name="description">渲染描述</param> /// <returns>FeatureRenderer</returns> public IFeatureRenderer SetSimpleRenderer(ISymbol symbol, string label, string description) { ISimpleRenderer simpleRenderer; simpleRenderer = new SimpleRendererClass(); simpleRenderer.Symbol = symbol; simpleRenderer.Label = label; simpleRenderer.Description = description; return simpleRenderer as IFeatureRenderer; } /// <summary> /// 柱状图渲染 /// </summary> /// <param name="chartStyle">柱状图样式</param> /// <param name="fields">展示字段数组</param> /// <param name="maxValue">柱子最大高度对应的数值</param> /// <returns></returns> public IFeatureRenderer SetBarChartRenderer(ChartStyleClient chartStyle, string[] fields, double maxValue) { string[] tempFields; string[] temp; IChartSymbol chartSymbol; IMarkerSymbol markerSymbol; tempFields = new string[fields.Length]; temp = new string[fields.Length]; IChartRenderer chartRenderer = new ChartRendererClass(); IRendererFields rendererFields = chartRenderer as IRendererFields; IBarChartSymbol barChartSymbol = new BarChartSymbolClass(); if (chartStyle.BarWidth != 0) barChartSymbol.Width = chartStyle.BarWidth; else barChartSymbol.Width = 5; if (chartStyle.BarSpacing != 0) barChartSymbol.Spacing = chartStyle.BarSpacing; else barChartSymbol.Spacing = 0; barChartSymbol.ShowAxes = chartStyle.HasAxes; I3DChartSymbol chartSymbol3D = barChartSymbol as I3DChartSymbol; chartSymbol3D.Display3D = chartStyle.Display3D; chartSymbol3D.Thickness = chartStyle.Thickness; chartSymbol = chartSymbol3D as IChartSymbol; chartSymbol.MaxValue = maxValue; markerSymbol = chartSymbol as IMarkerSymbol; if (chartStyle.BarMaxLength != 0) markerSymbol.Size = chartStyle.BarMaxLength; else markerSymbol.Size = 50; ISymbolArray symbolArray = barChartSymbol as ISymbolArray; for (int i = 0; i < fields.Length; i++) { if (fields[i].Contains('.')) tempFields[i] = fields[i].Split('.')[1]; else tempFields[i] = fields[i]; for (int j = 0; j < chartStyle.Items.Count; j++) { if (chartStyle.Items[j].Field.Contains('.')) temp[j] = chartStyle.Items[j].Field.Split('.')[1]; else temp[j] = chartStyle.Items[j].Field; if (temp[j] == tempFields[i]) { rendererFields.AddField(fields[i], fields[i]); rendererFields.set_FieldAlias(i, chartStyle.Items[j].Description); symbolArray.AddSymbol(chartStyle.Items[j].Symbol); } } } chartRenderer.UseOverposter = true; chartRenderer.ChartSymbol = chartSymbol3D as IChartSymbol; chartRenderer.CreateLegend(); //ReleaseAE.ReleaseAEObject(chartSymbol); //ReleaseAE.ReleaseAEObject(markerSymbol); //ReleaseAE.ReleaseAEObject(rendererFields); //ReleaseAE.ReleaseAEObject(barChartSymbol); //ReleaseAE.ReleaseAEObject(chartSymbol3D); //ReleaseAE.ReleaseAEObject(symbolArray); return chartRenderer as IFeatureRenderer; } /// <summary> /// 饼状图渲染 /// </summary> /// <param name="chartStyle">饼状图样式</param> /// <param name="fields">展示字段数组</param> /// <param name="minValue">饼状图饼最小时对应的数值</param> /// <returns></returns> public IFeatureRenderer SetPieChartRenderer(ChartStyleClient chartStyle, string[] fields, double minValue) { string[] tempFields; string[] temp; tempFields = new string[fields.Length]; temp = new string[fields.Length]; IMarkerSymbol markSymbol; IPieChartRenderer pieChartRenderer = new ChartRendererClass(); IRendererFields rendererFields = pieChartRenderer as IRendererFields; IPieChartSymbol pieChartSymbol = new PieChartSymbolClass(); I3DChartSymbol chartSymbol = pieChartSymbol as I3DChartSymbol; markSymbol = pieChartSymbol as IMarkerSymbol; if (chartStyle.PieByFixedSize) { pieChartRenderer.ProportionalBySum = false; if (chartStyle.PieFixedSize != 0) markSymbol.Size = chartStyle.PieFixedSize; else markSymbol.Size = 30; } else { pieChartRenderer.ProportionalBySum = true; if (chartStyle.PieMinSize != 0) pieChartRenderer.MinSize = chartStyle.PieMinSize; else pieChartRenderer.MinSize = 30; } chartSymbol.Display3D = chartStyle.Display3D; chartSymbol.Thickness = chartStyle.Thickness; chartSymbol.Tilt = chartStyle.PieTilt; ISymbolArray symbolArray = pieChartSymbol as ISymbolArray; for (int i = 0; i < fields.Length; i++) { if (fields[i].Contains('.')) tempFields[i] = fields[i].Split('.')[1]; else tempFields[i] = fields[i]; for (int j = 0; j < chartStyle.Items.Count; j++) { if (chartStyle.Items[j].Field.Contains('.')) temp[j] = chartStyle.Items[j].Field.Split('.')[1]; else temp[j] = chartStyle.Items[j].Field; if (temp[j] == tempFields[i]) { rendererFields.AddField(fields[i], fields[i]); rendererFields.set_FieldAlias(i, chartStyle.Items[j].Description); symbolArray.AddSymbol(chartStyle.Items[j].Symbol); } } } //pieChartRenderer.ProportionalBySum = true; //pieChartRenderer.MinSize =30; pieChartRenderer.MinValue = minValue; (pieChartRenderer as IChartRenderer).UseOverposter = false; (pieChartRenderer as IChartRenderer).ChartSymbol = chartSymbol as IChartSymbol; (pieChartRenderer as IChartRenderer).CreateLegend(); //ReleaseAE.ReleaseAEObject(markSymbol); //ReleaseAE.ReleaseAEObject(rendererFields); //ReleaseAE.ReleaseAEObject(chartSymbol); //ReleaseAE.ReleaseAEObject(pieChartSymbol); //ReleaseAE.ReleaseAEObject(symbolArray); return pieChartRenderer as IFeatureRenderer; } } }