zoukankan      html  css  js  c++  java
  • ArcGIS Desktop和Engine中对点要素图层Graduated Symbols渲染的实现 Rotation Symbol (转)

    摘要

            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)人工设定分级进行渲染的代码如下:
    [csharp] view plain copy
     
    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.   
    7.     try  
    8.     {  
    9.         //声明分级渲染对象  
    10.         IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();  
    11.         pClassBreaksRenderer.Field = SizeField;  
    12.         pClassBreaksRenderer.BreakCount = classCountNum;  
    13.   
    14.         for (int breakIndex = 0; breakIndex < classCountNum; breakIndex++)  
    15.         {  
    16.             IRgbColor pColor = GetRGB(225, 80, 10);  
    17.             ISymbol SetSymbol = SetArrowMarkSymbol(breakIndex, pColor);  
    18.             pClassBreaksRenderer.set_Symbol(breakIndex, SetSymbol);  
    19.             pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);  
    20.         }  
    21.         //设置符号旋转的渲染方式  
    22.         IRotationRenderer pRotationRenderer = (IRotationRenderer)pClassBreaksRenderer;  
    23.         pRotationRenderer.RotationField = RotationField;//设置旋转基准字段  
    24.         //pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;//以x轴为旋转起点  
    25.         pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;//以y轴为旋转起点  
    26.   
    27.         //设置图层的渲染方式  
    28.         pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;  
    29.   
    30.     }  
    31.     catch (Exception e)  
    32.     {  
    33.         //MessageBox.Show(e.Message);  
    34.         return;  
    35.     }  
    36. }  

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

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

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

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

    [csharp] view plain copy
     
    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.               
    8.             object dataValues;  
    9.             object dataFrequency;  
    10.             //从pTable的字段中得到信息给dataValues和dataFrequency两个数组  
    11.             ITableHistogram pTableHistogram = new BasicTableHistogramClass();  
    12.             pTableHistogram.Field = FieldName;  
    13.             pTableHistogram.Table = pTable;  
    14.             IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram;  
    15.             pHistogram.GetHistogram(out dataValues, out dataFrequency);  
    16.   
    17.             //下面是分级方法,用于根据获得的值计算得出符合要求的数据  
    18.             IClassifyGEN pClassify;  
    19.             //根据条件计算出IClassifyGEN  
    20.             pClassify = new EqualIntervalClass();  
    21.             int tt = ClassesCount;  
    22.             pClassify.Classify(dataValues, dataFrequency, ref tt);  
    23.             //返回数组  
    24.             breakPointClasses = (double[])pClassify.ClassBreaks;  
    25.             return breakPointClasses;  
    26.         }  

    最终的渲染效果如下:

     
     from: http://blog.csdn.net/u012223164/article/details/39207369
  • 相关阅读:
    hdu 5170 GTY's math problem(水,,数学,,)
    hdu 5178 pairs(BC第一题,,方法不止一种,,我用lower_bound那种。。。)
    hdu 5179 beautiful number(构造,,,,)
    cf12E Start of the season(构造,,,)
    cf12D Ball(MAP,排序,贪心思想)
    cf 12C Fruits(贪心【简单数学】)
    cf 12B Correct Solution?(贪心)
    hdu 5171 GTY's birthday gift(数学,矩阵快速幂)
    hdu 5172 GTY's gay friends(线段树最值)
    cf 11D A Simple Task(状压DP)
  • 原文地址:https://www.cnblogs.com/yuxuetaoxp/p/7298267.html
Copyright © 2011-2022 走看看