圖中:A、Value表示符號大小對應的字段,Normalization(歸一化)表示將Value字段進行歸一化處理。B、Classification表示根據Value字段進行分級,包含分級方式(圖中爲NaturalBreaks)Classes爲分級數量,點擊右側Classify可對Classification進行更改設置。C、Symbol Size表示符號分級的最大最小值,右方,Template點擊,可對點要素的表示符號進行設置,可設置樣式、顏色、大小、初始角度。D、下方的Advanced點擊可選擇旋轉(Rotation),設置旋轉的參照字段和旋轉方式(Geographic爲Y向起順時針旋轉,Arithmetic爲X向起逆時針旋轉)。渲染示例圖以下:
- 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;
- }
- }
其中,分級採用等間距分級的代碼以下:post
- 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;
- }
最終的渲染效果以下:spa