欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Arcgis Engine 自定义栅格分类渲染(排除不想要的值)

程序员文章站 2022-05-22 10:36:15
...

      在做栅格分类渲染的时候,大家有可能想排除一些不想要的值,如背景值或异常值,在ArcMap中对应的功能就是Exclusion,如下图。

Arcgis Engine 自定义栅格分类渲染(排除不想要的值)

      那么,二次开发的时候怎么写呢?,其实,只要利用IRasterDataExclusion这个接口就可以实现,根据官方开发文档查了下分级的类RasterClassifyColorRampRendererClass所对应的接口就一目了然了。

Arcgis Engine 自定义栅格分类渲染(排除不想要的值)

      实现代码如下:

if (pLayer != null && pLayer is IRasterLayer)
            {
                IRasterLayer pRasterLayer = pLayer as IRasterLayer; 
                IRasterBandCollection bands = null;
                bands = (pRasterLayer.Raster as IRaster2).RasterDataset as IRasterBandCollection;
                
                IRasterBand pRasterBand = bands.Item(0);
                //如果没有统计数据,则计算
                if (pRasterBand.Histogram == null)
                {
                    pRasterBand.ComputeStatsAndHist();
                }

                IRasterClassifyColorRampRenderer ClassifyColor = new RasterClassifyColorRampRendererClass();
                IRasterRenderer pRasterRenderer = ClassifyColor as IRasterRenderer;
                pRasterRenderer.Raster = pRasterLayer.Raster;
                
                //设置分级 (我这里set_break的index从1开始)
                ClassifyColor.ClassCount = 3;
                ClassifyColor.set_Break(1, 0.27099);
                ClassifyColor.set_Break(2, 1.77287);
                ClassifyColor.set_Break(3, 2.77287);

                //排除数值(大家可以根据需要自行设置,我这张图-999是背景值)
                double[] ignoredValue = new double[1] { -999 };
                IRasterDataExclusion pRasterDataExclusion = ClassifyColor as IRasterDataExclusion;
                pRasterDataExclusion.ExcludeValues = ignoredValue;

                //颜色设置  
                IFillSymbol Symbol = new SimpleFillSymbolClass() as IFillSymbol;
                Symbol.Color = SetRGB(0, 255, 102);
                ClassifyColor.set_Symbol(0, Symbol as ISymbol);
                Symbol.Color = SetRGB(255, 255, 100);
                ClassifyColor.set_Symbol(1, Symbol as ISymbol);
                Symbol.Color = SetRGB(255, 153, 0);
                ClassifyColor.set_Symbol(2, Symbol as ISymbol);

                pRasterLayer.Renderer = pRasterRenderer;

                //设置标签(必须在设置分级之后才能设置标签)
                ClassifyColor.set_Label(0, "低聚区");
                ClassifyColor.set_Label(1, "中聚区");
                ClassifyColor.set_Label(2, "高聚区");

                pRasterRenderer.Update();

                m_mapControl.ActiveView.Refresh();
                m_TOCControl.Update();
            }
        private IColor SetRGB(int R,int G,int B)
        {
            IRgbColor pRgbColor=new RgbColorClass();
            pRgbColor.Red = R;
            pRgbColor.Green = G;
            pRgbColor.Blue = B;
            return (IColor)pRgbColor;
        }


相关标签: GIS二次开发