C#+arcengine修改栅格数据的像元值

 c此文为修改栅格数据的像元值,本人未深入研究,具体可参照arcgis开发帮助文档或者http://blog.sina.com.cn/s/blog_84f7fbbb0101d49w.html,感谢博主


  ///

        /// 修改栅格数据像素值
        ///

        /// raster路径
        public void ChangePixelValue(string clipRasterPath)
        {
            //得到裁剪后的raster
            IRaster raster=GetRaster(clipRasterPath);
            IRaster2 raster2 =( IRaster2)raster;

            //   指定像素块大小
            IPnt pntBlock = new PntClass();
            pntBlock.X = 1280;
            pntBlock.Y = 1280;
            //创建一个光标以给定像素块大小
            IRasterCursor rasterCursor = raster2.CreateCursorEx(pntBlock);
            //控制像素块级别的编辑操作
            IRasterEdit rasterEdit = raster2 as IRasterEdit;
            if (rasterEdit.CanEdit())
            {
                //得到一段光栅带
                IRasterBandCollection bandCollection =( IRasterBandCollection)raster;
                System.Array pixels;
                IPnt pnt = null;
                object value;
                int bandCount = bandCollection.Count;
                //创建像素块
                IPixelBlock3 pixelBlock3 = null;
                int blockWidth = 0;
                int blockHeight = 0;
                do
                {
                    pixelBlock3 = rasterCursor.PixelBlock as IPixelBlock3;
                    blockWidth = pixelBlock3.Width;
                    blockHeight = pixelBlock3.Height;
                    for (int k = 0; k < bandCount; k++)
                    {
                        //指定平面的像素的数组
                        pixels = (System.Array)pixelBlock3.get_PixelData(k);

                        for (int i = 0; i < blockWidth; i++)
                        {
                            for (int j = 0; j < blockHeight; j++)
                            {
                                value = pixels.GetValue(i, j);

                                if (Convert.ToInt32(value) == 0)
                                {
                                    pixels.SetValue(Convert.ToByte(50), i, j);
                                }
                            }
                        }
                        pixelBlock3.set_PixelData(k, pixels);
                    }
                    pnt = rasterCursor.TopLeft;
                    rasterEdit.Write(pnt, (IPixelBlock)pixelBlock3);
                }
                while (rasterCursor.Next());
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
            }
        }

你可能感兴趣的:(C#+Arcengine,arcgis,c#,修改像元值,栅格数据)