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

时间:2024-05-05 11:07:14
  protected override void OnClick()
{
//
// TODO: Sample code showing how to access button host
//
ArcMap.Application.CurrentTool = null; IMap pMap = ArcMap.Document.FocusMap;
for (int i = ; i < pMap.LayerCount; i++)
{
ILayer pLayer = pMap.get_Layer(i);
if (pLayer is IRasterLayer)
{
IRasterLayer pRstLyr = pLayer as IRasterLayer;
IRasterStretchColorRampRenderer pRasterStretchColorRampRenderer;
IRasterStretch2 prstStretch= pRstLyr.Renderer as IRasterStretch2;
// Setup the stretch
prstStretch.Background = true;
// Apply the renderer
pRstLyr.Renderer = (IRasterRenderer)prstStretch;
// Collapse the legends on each raster
ILegendInfo legendInfo = (ILegendInfo)pRstLyr.Renderer;
ILegendGroup legendGroup = (ILegendGroup)legendInfo.get_LegendGroup();
legendGroup.Visible = false;
}
}
}

核心实现代码如上

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

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

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

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

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