注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

快乐小屋

 
 
 

日志

 
 

地图符号化-柱状图  

2013-04-28 11:54:08|  分类: ArcGIS Engine开 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

class BarRender
    {


        public BarRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, String pFieldName1, string pFieldName2)
        {

 

            IGeoFeatureLayer pGeoFeatureLayer = pFtLayer as IGeoFeatureLayer;

            pGeoFeatureLayer.ScaleSymbols = true;


            IFeatureClass pFeatureClass = pFtLayer.FeatureClass;

            //定义柱状图渲染组建对象
            IChartRenderer pChartRenderer = new ChartRendererClass();
            //定义渲染字段对象并给字段对象实例化为pChartRenderer
            IRendererFields pRendererFields;
            pRendererFields = (IRendererFields)pChartRenderer;
            //向渲染字段对象中添加字段--- 待补充自定义添加
            pRendererFields.AddField(pFieldName1, pFieldName1);
            pRendererFields.AddField(pFieldName2, pFieldName2);

            ITable pTable= pGeoFeatureLayer as ITable;

            int[] pFieldIndecies = new int[2];

            pFieldIndecies[0] = pTable.FindField(pFieldName1);
            pFieldIndecies[1] = pTable.FindField(pFieldName2);

 

            IDataStatistics pDataStat = new DataStatisticsClass();

            IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false);

            pDataStat.Cursor = pFtCursor as ICursor;

            pDataStat.Field = pFieldName2;

            double pMax = pDataStat.Statistics.Maximum;

            // 定义并设置渲染时用的chart marker symbol
            IBarChartSymbol pBarChartSymbol = new BarChartSymbolClass();

            pBarChartSymbol.Width = 6;

            IChartSymbol pChartSymbol;
            pChartSymbol = pBarChartSymbol as IChartSymbol;

            IMarkerSymbol pMarkerSymbol;
            pMarkerSymbol = (IMarkerSymbol)pBarChartSymbol;

 

            IFillSymbol pFillSymbol;
            //设置pChartSymbol的最大值
            pChartSymbol.MaxValue = pMax;
            // 设置bars的最大高度
            pMarkerSymbol.Size = 80;
            //下面给每一个bar设置符号

            //定义符号数组
            ISymbolArray pSymbolArray = (ISymbolArray)pBarChartSymbol;

 

            //添加第一个符号
            pFillSymbol = new SimpleFillSymbolClass();
            pFillSymbol.Color = GetRGBColor(193, 252, 179) as IColor;
            pSymbolArray.AddSymbol(pFillSymbol as ISymbol);
            //添加第二个符号
            pFillSymbol = new SimpleFillSymbolClass();
            pFillSymbol.Color = GetRGBColor(145, 55, 251) as IColor;
            pSymbolArray.AddSymbol(pFillSymbol as ISymbol);

 


            pChartRenderer.ChartSymbol = pChartSymbol as IChartSymbol;
            //pChartRenderer.Label = "AREA";

          如果没有这四句,就看不到地图

  pFillSymbol = new SimpleFillSymbolClass();
            pFillSymbol.Color = GetRGBColor(239, 228, 190);
            pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol;
            pChartRenderer.CreateLegend();

            pChartRenderer.UseOverposter = false;
            //将柱状图渲染对象与渲染图层挂钩
            pGeoFeatureLayer.Renderer = (IFeatureRenderer)pChartRenderer;


            //刷新地图和TOOCotrol
            IActiveView pActiveView = pMapcontrol.ActiveView as IActiveView;
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

 


        
         

}

        public IRgbColor GetRGBColor(int r, int g, int b)
        {
            IRgbColor pRGB;

            pRGB = new RgbColorClass();

            pRGB.Red = r;

            pRGB.Green = g;

            pRGB.Blue = b;

            return pRGB;


        }
    }

 


  评论这张
 
阅读(380)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018