ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现 Rotation Symbol (转)

时间:2023-03-09 22:18:07
ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现  Rotation Symbol (转)

摘要

        ArcGIS中,对于要素图层的渲染,支持按照要素字段的值渲染要素的大小,其中Graduated Symbols可以对大小进行分级渲染。在个人开发系统的过程中,也可以用来美化数据显示,加强表达。参考ArcMap中对于Graduated Symbols的实现,有助于理解和编写ArcGIS Engine的相关代码。

1、ArcMap中Graduated Symbols渲染的实现

        首先,在左侧图层中找到要渲染的图层,右击打开图层属性(Properties),在上方选择样式(Symbology)选项卡,在数量(Quantities)下选择Graduated Symbols。界面如下:
ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现  Rotation Symbol (转)ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现  Rotation Symbol (转)

图中:A、Value表示符号大小对应的字段,Normalization(归一化)表示将Value字段进行归一化处理。B、Classification表示根据Value字段进行分级,包含分级方式(图中为NaturalBreaks)Classes为分级数量,点击右侧Classify可对Classification进行更改设置。C、Symbol Size表示符号分级的最大最小值,右方,Template点击,可对点要素的表示符号进行设置,可设置样式、颜色、大小、初始角度。D、下方的Advanced点击可选择旋转(Rotation),设置旋转的参照字段和旋转方式(Geographic为Y向起顺时针旋转,Arithmetic为X向起逆时针旋转)。渲染示例图如下:

ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现  Rotation Symbol (转)

2、ArcEngine中Graduated Symbols渲染的实现

        ArcGISEngine中,Graduated Symbols的实现依赖于IClassBreaksRenderer接口,首先需要设定分级的字段和级别数量,根据级别数量设定每一级的样式,设定该级的断点。级别数量对应于ArcMap中的Classes,断点为确定有两种方式,一是调用IClassifyGEN接口,同ArcMap中点击Classify选择相应方式,二是人工设定,同一中的manual。
        将IClassBreaksRenderer接口对象转换为IRotationRenderer借口对象,可以实现ArcMap中的Advanced的Rotation功能,设置旋转字段和旋转方式。
        (1)人工设定分级进行渲染的代码如下:
  1. public static void ArrowGraduatedRendererFlow2(IFeatureLayer pFeatureLayer, string SizeField, string RotationField)
  2. {
  3. IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
  4. int classCountNum=4;
  5. double[] Classes = {0.0,0.5,1.0,2.0,10.0};
  6. try
  7. {
  8. //声明分级渲染对象
  9. IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();
  10. pClassBreaksRenderer.Field = SizeField;
  11. pClassBreaksRenderer.BreakCount = classCountNum;
  12. for (int breakIndex = 0; breakIndex < classCountNum; breakIndex++)
  13. {
  14. IRgbColor pColor = GetRGB(225, 80, 10);
  15. ISymbol SetSymbol = SetArrowMarkSymbol(breakIndex, pColor);
  16. pClassBreaksRenderer.set_Symbol(breakIndex, SetSymbol);
  17. pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);
  18. }
  19. //设置符号旋转的渲染方式
  20. IRotationRenderer pRotationRenderer = (IRotationRenderer)pClassBreaksRenderer;
  21. pRotationRenderer.RotationField = RotationField;//设置旋转基准字段
  22. //pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;//以x轴为旋转起点
  23. pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;//以y轴为旋转起点
  24. //设置图层的渲染方式
  25. pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
  26. }
  27. catch (Exception e)
  28. {
  29. //MessageBox.Show(e.Message);
  30. return;
  31. }
  32. }

其中:SetArrowMarkSymbol(breakIndex, pColor)函数调用了IArrowMarkerSymbol接口,定义箭头标识。

(2)Classify分级并渲染的代码如下:

  1. public static void ArrowGraduatedRendererFlow(IFeatureLayer pFeatureLayer, string SizeField, string RotationField)
  2. {
  3. IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
  4. ITable pTable = (ITable)pGeoFeatureLayer;
  5. IQueryFilter pQueryFilter = new QueryFilterClass();
  6. pQueryFilter.AddField("");
  7. ICursor pCursor = pTable.Search(pQueryFilter, true);
  8. //使用统计类得到最大最小值
  9. IDataStatistics pDataStatistics = new DataStatisticsClass();
  10. pDataStatistics.Cursor = pCursor;
  11. //设置统计字段
  12. pDataStatistics.Field = SizeField;
  13. //得到统计结果
  14. IStatisticsResults pStatisticsResult = pDataStatistics.Statistics;
  15. if (pStatisticsResult == null)
  16. {
  17. MessageBox.Show("属性值统计失败!");
  18. return;
  19. }
  20. int classCountNum;
  21. classCountNum = (int)((pStatisticsResult.Maximum - pStatisticsResult.Minimum) / 0.5) + 1;//将(流速)值按0.5m/s分级,得到分级级数
  22. if (classCountNum <= 0)
  23. {
  24. classCountNum = 1;
  25. }
  26. if (classCountNum >= 32)
  27. {
  28. classCountNum = 32;
  29. }
  30. double[] Classes = GetClassBreakpoints(pGeoFeatureLayer, SizeField, classCountNum);//调用函数分级
  31. try
  32. {
  33. //声明分级渲染对象
  34. IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();
  35. pClassBreaksRenderer.Field = SizeField;
  36. pClassBreaksRenderer.BreakCount = classCountNum;
  37. for (int breakIndex = 0; breakIndex < classCountNum; breakIndex++)
  38. {
  39. IRgbColor pColor = GetRGB(225, 80, 10);
  40. ISymbol SetSymbol = SetArrowMarkSymbol(breakIndex, pColor);
  41. pClassBreaksRenderer.set_Symbol(breakIndex, SetSymbol);
  42. pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);
  43. }
  44. //设置符号旋转的渲染方式
  45. IRotationRenderer pRotationRenderer = (IRotationRenderer)pClassBreaksRenderer;
  46. pRotationRenderer.RotationField = RotationField;//设置旋转基准字段
  47. //pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;//以x轴为旋转起点
  48. pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;//以y轴为旋转起点
  49. //设置图层的渲染方式
  50. pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
  51. }
  52. catch (Exception e)
  53. {
  54. //MessageBox.Show(e.Message);
  55. return;
  56. }
  57. }

其中,分级采用等间距分级的代码如下:

  1. private static double[] GetClassBreakpoints(IGeoFeatureLayer pGeoFeatureLayer, string FieldName,int ClassesCount)
  2. {
  3. double[] breakPointClasses;
  4. if (pGeoFeatureLayer == null)
  5. return null;
  6. ITable pTable = (ITable)pGeoFeatureLayer;//ITable pTable = (ITable)pGeoFeatureLayer.FeatureClass;
  7. object dataValues;
  8. object dataFrequency;
  9. //从pTable的字段中得到信息给dataValues和dataFrequency两个数组
  10. ITableHistogram pTableHistogram = new BasicTableHistogramClass();
  11. pTableHistogram.Field = FieldName;
  12. pTableHistogram.Table = pTable;
  13. IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram;
  14. pHistogram.GetHistogram(out dataValues, out dataFrequency);
  15. //下面是分级方法,用于根据获得的值计算得出符合要求的数据
  16. IClassifyGEN pClassify;
  17. //根据条件计算出IClassifyGEN
  18. pClassify = new EqualIntervalClass();
  19. int tt = ClassesCount;
  20. pClassify.Classify(dataValues, dataFrequency, ref tt);
  21. //返回数组
  22. breakPointClasses = (double[])pClassify.ClassBreaks;
  23. return breakPointClasses;
  24. }

最终的渲染效果如下:

ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现  Rotation Symbol (转)

 from: http://blog.****.net/u012223164/article/details/39207369