ArcGIS AddIn 批量设置栅格图层背景色为透明

 1  protected override void OnClick()
 2         {
 3             //
 4             //  TODO: Sample code showing how to access button host
 5             //
 6             ArcMap.Application.CurrentTool = null;
 7 
 8             IMap pMap = ArcMap.Document.FocusMap;
 9             for (int i = 0; i < pMap.LayerCount; i++)
10             {
11                 ILayer pLayer = pMap.get_Layer(i);
12                 if (pLayer is IRasterLayer)
13                 {
14                     IRasterLayer pRstLyr = pLayer as IRasterLayer;
15                     IRasterStretchColorRampRenderer pRasterStretchColorRampRenderer;
16                     IRasterStretch2 prstStretch= pRstLyr.Renderer as IRasterStretch2;
17                     // Setup the stretch
18                     prstStretch.Background = true;
19                     // Apply the renderer
20                     pRstLyr.Renderer = (IRasterRenderer)prstStretch;
21                     // Collapse the legends on each raster
22                     ILegendInfo legendInfo = (ILegendInfo)pRstLyr.Renderer;
23                     ILegendGroup legendGroup = (ILegendGroup)legendInfo.get_LegendGroup(0);
24                     legendGroup.Visible = false;
25                 }
26             }
27         }

核心实现代码如上

上述代码实现了对TOC中所有栅格图层批量设置其背景色为透明,可以避免在工作中加载大量分幅图时,部分分幅图背景显示为黑色导致的黑边问题.

相当于批量将TOC中所有栅格图层勾选了 Display background Value as 选项.

 

上述代码只是简单实现了功能,没有考虑图层组的情况,如果图层放入图层组中,会检索不到,从而不对图层组中的图层做任何处理

编译插件文件下载地址: 链接: https://pan.baidu.com/s/1GUBJRe_dLV7657ozgTqVhw 密码: djq2

 

posted @ 2018-05-22 21:00  DayDreamInGIS  阅读(3364)  评论(0编辑  收藏  举报