码迷,mamicode.com
首页 > 其他好文 > 详细

矢量图层渲染

时间:2016-08-05 00:52:18      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

 public void fenjiZS()
        {
            IMap pMap;
            IGeoFeatureLayer pGeoFeatureL;
            IFeatureClass pFeatureClass;
            IFeatureCursor pFeatureCursor;
            IQueryFilter pQueryFilter;
            IClassBreaksRenderer pClassBreaksRenderer;
            IEnumColors pEnumColors;
            IColor pColor;
            ISimpleMarkerSymbol  pMarkerFillS;
            int lbreakIndex;
            //定义要渲染的字段
            const string strField = "AQIType";
            //定义分类的数目为6
            const int numDesiredClasses = 6;
            pMap = axMapControl1.Map;
            //选定要渲染的图层
            pGeoFeatureL = pMap.get_Layer(0) as IGeoFeatureLayer;
            pFeatureClass = pGeoFeatureL.FeatureClass;
            pQueryFilter = new QueryFilterClass();
            pFeatureCursor = pFeatureClass.Search(pQueryFilter, true);
            IDataStatistics pDataStatistics;
            IStatisticsResults pStatisticsResult;
            pDataStatistics = new DataStatisticsClass();
            pDataStatistics.Cursor = pFeatureCursor as ICursor;
            pDataStatistics.Field = strField;
            pStatisticsResult = pDataStatistics.Statistics;
            if (pStatisticsResult == null)
            {
                MessageBox.Show("Failed to gather stats on the feature class");
            }
            pClassBreaksRenderer = new ClassBreaksRendererClass();
            pClassBreaksRenderer.Field = strField;
            pClassBreaksRenderer.BreakCount = numDesiredClasses;
            //获得颜色
            pEnumColors = CreateColor();
            string[] LabelAQI = {"","","轻度污染","中度污染","严重污染","重度污染"};
            for (lbreakIndex = 0; lbreakIndex < numDesiredClasses; lbreakIndex++)
            {
                pColor = pEnumColors.Next();
                pMarkerFillS = new SimpleMarkerSymbolClass ();//渲染点图层
                pMarkerFillS.Color = pColor;
                pMarkerFillS.Style = esriSimpleMarkerStyle .esriSMSCircle;
                //不同的类别设置不同的填充样式
                pClassBreaksRenderer.set_Symbol(lbreakIndex, pMarkerFillS as ISymbol);
                //分类渲染对象的断点
                pClassBreaksRenderer.set_Break(lbreakIndex, lbreakIndex + 1);
                pClassBreaksRenderer.set_Label(lbreakIndex, LabelAQI[lbreakIndex]);
            }
            //设置Renderer
            pGeoFeatureL.Renderer = pClassBreaksRenderer as IFeatureRenderer;
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            
        }
 public IEnumColors CreateColor()//生成颜色带方法
        {
            IRgbColor fromColor = new RgbColor();
            fromColor.Red = 0;
            fromColor.Green = 255;
            fromColor.Blue = 0;
            IRgbColor toColor = new RgbColor();
            toColor.Red = 255;
            toColor.Green = 0;
            toColor.Blue = 0;
            IAlgorithmicColorRamp pRampColor;
            pRampColor = new AlgorithmicColorRampClass();
            pRampColor.FromColor = fromColor;
            pRampColor.ToColor = toColor;
            pRampColor.Size = 6;//设置颜色带数量
            bool ok = true;
            pRampColor.CreateRamp(out ok);//创建颜色带
            return pRampColor.Colors;
        }

 

矢量图层渲染

标签:

原文地址:http://www.cnblogs.com/MansonsBlog/p/5738870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!