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

本文介绍了一段代码实现修改栅格数据像素值的方法,包括获取裁剪后的栅格、指定像素块大小、创建光标和编辑器进行块级别编辑等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


  /// <summary>

        /// 修改栅格数据像素值
        /// </summary>
        /// <param name="clipRasterPath">raster路径</param>
        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);
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值