ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现 Rotation Symbol (转)
Posted on 2017-08-07 11:26 yushff 阅读(990) 评论(0) 编辑 收藏 举报摘要
ArcGIS中,对于要素图层的渲染,支持按照要素字段的值渲染要素的大小,其中Graduated Symbols可以对大小进行分级渲染。在个人开发系统的过程中,也可以用来美化数据显示,加强表达。参考ArcMap中对于Graduated Symbols的实现,有助于理解和编写ArcGIS Engine的相关代码。
1、ArcMap中Graduated Symbols渲染的实现
首先,在左侧图层中找到要渲染的图层,右击打开图层属性(Properties),在上方选择样式(Symbology)选项卡,在数量(Quantities)下选择Graduated Symbols。界面如下:
图中:A、Value表示符号大小对应的字段,Normalization(归一化)表示将Value字段进行归一化处理。B、Classification表示根据Value字段进行分级,包含分级方式(图中为NaturalBreaks)Classes为分级数量,点击右侧Classify可对Classification进行更改设置。C、Symbol Size表示符号分级的最大最小值,右方,Template点击,可对点要素的表示符号进行设置,可设置样式、颜色、大小、初始角度。D、下方的Advanced点击可选择旋转(Rotation),设置旋转的参照字段和旋转方式(Geographic为Y向起顺时针旋转,Arithmetic为X向起逆时针旋转)。渲染示例图如下:
2、ArcEngine中Graduated Symbols渲染的实现
ArcGISEngine中,Graduated Symbols的实现依赖于IClassBreaksRenderer接口,首先需要设定分级的字段和级别数量,根据级别数量设定每一级的样式,设定该级的断点。级别数量对应于ArcMap中的Classes,断点为确定有两种方式,一是调用IClassifyGEN接口,同ArcMap中点击Classify选择相应方式,二是人工设定,同一中的manual。
将IClassBreaksRenderer接口对象转换为IRotationRenderer借口对象,可以实现ArcMap中的Advanced的Rotation功能,设置旋转字段和旋转方式。
(1)人工设定分级进行渲染的代码如下:
- public static void ArrowGraduatedRendererFlow2(IFeatureLayer pFeatureLayer, string SizeField, string RotationField)
- {
- IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
- int classCountNum=4;
- double[] Classes = {0.0,0.5,1.0,2.0,10.0};
- try
- {
- //声明分级渲染对象
- IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();
- pClassBreaksRenderer.Field = SizeField;
- pClassBreaksRenderer.BreakCount = classCountNum;
- for (int breakIndex = 0; breakIndex < classCountNum; breakIndex++)
- {
- IRgbColor pColor = GetRGB(225, 80, 10);
- ISymbol SetSymbol = SetArrowMarkSymbol(breakIndex, pColor);
- pClassBreaksRenderer.set_Symbol(breakIndex, SetSymbol);
- pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);
- }
- //设置符号旋转的渲染方式
- IRotationRenderer pRotationRenderer = (IRotationRenderer)pClassBreaksRenderer;
- pRotationRenderer.RotationField = RotationField;//设置旋转基准字段
- //pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;//以x轴为旋转起点
- pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;//以y轴为旋转起点
- //设置图层的渲染方式
- pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
- }
- catch (Exception e)
- {
- //MessageBox.Show(e.Message);
- return;
- }
- }
其中:SetArrowMarkSymbol(breakIndex, pColor)函数调用了IArrowMarkerSymbol接口,定义箭头标识。
(2)Classify分级并渲染的代码如下:
- public static void ArrowGraduatedRendererFlow(IFeatureLayer pFeatureLayer, string SizeField, string RotationField)
- {
- IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
- ITable pTable = (ITable)pGeoFeatureLayer;
- IQueryFilter pQueryFilter = new QueryFilterClass();
- pQueryFilter.AddField("");
- ICursor pCursor = pTable.Search(pQueryFilter, true);
- //使用统计类得到最大最小值
- IDataStatistics pDataStatistics = new DataStatisticsClass();
- pDataStatistics.Cursor = pCursor;
- //设置统计字段
- pDataStatistics.Field = SizeField;
- //得到统计结果
- IStatisticsResults pStatisticsResult = pDataStatistics.Statistics;
- if (pStatisticsResult == null)
- {
- MessageBox.Show("属性值统计失败!");
- return;
- }
- int classCountNum;
- classCountNum = (int)((pStatisticsResult.Maximum - pStatisticsResult.Minimum) / 0.5) + 1;//将(流速)值按0.5m/s分级,得到分级级数
- if (classCountNum <= 0)
- {
- classCountNum = 1;
- }
- if (classCountNum >= 32)
- {
- classCountNum = 32;
- }
- double[] Classes = GetClassBreakpoints(pGeoFeatureLayer, SizeField, classCountNum);//调用函数分级
- try
- {
- //声明分级渲染对象
- IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();
- pClassBreaksRenderer.Field = SizeField;
- pClassBreaksRenderer.BreakCount = classCountNum;
- for (int breakIndex = 0; breakIndex < classCountNum; breakIndex++)
- {
- IRgbColor pColor = GetRGB(225, 80, 10);
- ISymbol SetSymbol = SetArrowMarkSymbol(breakIndex, pColor);
- pClassBreaksRenderer.set_Symbol(breakIndex, SetSymbol);
- pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);
- }
- //设置符号旋转的渲染方式
- IRotationRenderer pRotationRenderer = (IRotationRenderer)pClassBreaksRenderer;
- pRotationRenderer.RotationField = RotationField;//设置旋转基准字段
- //pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;//以x轴为旋转起点
- pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;//以y轴为旋转起点
- //设置图层的渲染方式
- pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
- }
- catch (Exception e)
- {
- //MessageBox.Show(e.Message);
- return;
- }
- }
其中,分级采用等间距分级的代码如下:
- private static double[] GetClassBreakpoints(IGeoFeatureLayer pGeoFeatureLayer, string FieldName,int ClassesCount)
- {
- double[] breakPointClasses;
- if (pGeoFeatureLayer == null)
- return null;
- ITable pTable = (ITable)pGeoFeatureLayer;//ITable pTable = (ITable)pGeoFeatureLayer.FeatureClass;
- object dataValues;
- object dataFrequency;
- //从pTable的字段中得到信息给dataValues和dataFrequency两个数组
- ITableHistogram pTableHistogram = new BasicTableHistogramClass();
- pTableHistogram.Field = FieldName;
- pTableHistogram.Table = pTable;
- IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram;
- pHistogram.GetHistogram(out dataValues, out dataFrequency);
- //下面是分级方法,用于根据获得的值计算得出符合要求的数据
- IClassifyGEN pClassify;
- //根据条件计算出IClassifyGEN
- pClassify = new EqualIntervalClass();
- int tt = ClassesCount;
- pClassify.Classify(dataValues, dataFrequency, ref tt);
- //返回数组
- breakPointClasses = (double[])pClassify.ClassBreaks;
- return breakPointClasses;
- }
最终的渲染效果如下:
from: http://blog.csdn.net/u012223164/article/details/39207369