这里要注意的是单波段的栅格数据,比如dem一般是不能修改像素值的。而dem的像元值一般代表它的高程。这里的把我研究的高程数据的像元值全部改成了0和1。它要注意的是由于修改像素是直接在原数据上直接修改,所以完成后原数据就会没有了,所以大家可以先复制一下原数据再做。

一。改变栅格数据像素值

 public void ChangeRasterValue(IRasterDataset2 pRasterDatset){IRaster2 pRaster2 = pRasterDatset.CreateFullRaster() as IRaster2;IPnt pPntBlock = new PntClass();pPntBlock.X = 128;pPntBlock.Y = 128;IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(pPntBlock);IRasterEdit pRasterEdit = pRaster2 as IRasterEdit;if (pRasterEdit.CanEdit()){IRasterBandCollection pBands = pRasterDatset as IRasterBandCollection;IPixelBlock3 pPixelblock3 = null;int pBlockwidth = 0;int pBlockheight = 0;System.Array pixels;IPnt pPnt = null;object pValue;long pBandCount = pBands.Count;//获取Nodata//IRasterProps pRasterPro = pRaster2 as IRasterProps;//object pNodata = pRasterPro.NoDataValue;do{pPixelblock3 = pRasterCursor.PixelBlock as IPixelBlock3;pBlockwidth = pPixelblock3.Width;pBlockheight = pPixelblock3.Height;for (int k = 0; k < pBandCount; k++){pixels = (System.Array)pPixelblock3.get_PixelData(k);for (int i = 0; i < pBlockwidth; i++){for (int j = 0; j < pBlockheight; j++){pValue = pixels.GetValue(i, j);if (Convert.ToInt32(pValue) == 0 && isFlood[j, i] == true){pixels.SetValue(Convert.ToByte(50), i, j);}}}pPixelblock3.set_PixelData(k, pixels);}pPnt = pRasterCursor.TopLeft;pRasterEdit.Write(pPnt, (IPixelBlock)pPixelblock3);}while (pRasterCursor.Next());System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);MessageBox.Show("done");}}

还有就是根据IRaster2修改像素值

                IRasterBandCollection rasterbands = (IRasterBandCollection)pRasterDataset;IRasterBand rasterband = rasterbands.Item(0);IRawPixels rawpixels = (IRawPixels)rasterbands.Item(0);IRasterProps rasterpro = (IRasterProps)rasterband;IRasterDataset2 rasterDataset2 = (IRasterDataset2)pRasterDataset;IRaster raster = rasterDataset2.CreateFullRaster();IRaster2 raster2 = (IRaster2)raster;IPnt pBlockSize1 = new PntClass();IEnvelope envelope = rasterpro.Extent;pBlockSize1.SetCoords(envelope.Width, envelope.Height);IPixelBlock pixelBlock = raster2.CreateCursorEx(pBlockSize1).PixelBlock;int w = pixelBlock.Width;int h = pixelBlock.Height;//read the first pixel blockIPnt topleftCorner = new PntClass();topleftCorner.SetCoords(0, 0);raster.Read(topleftCorner, pixelBlock);//modify one pixel value at location (assume the raster has a pixel type of uchar)IPixelBlock3 pixelBlock3 = (IPixelBlock3)pixelBlock;System.Array pixels = (System.Array)pixelBlock3.get_PixelData(0);for (int finalX = 0; finalX < pRows; finalX++){for (int finalY = 0; finalY < pColumns; finalY++){if (isFlood[finalX, finalY] == true){pixels.SetValue(Convert.ToByte(100), finalY, finalX);}//else//{//    pPixelData.SetValue(0, finalY, finalX);//}}}pixelBlock3.set_PixelData(0, (System.Object)pixels);//write the modified pixel block to the raster datasetIRasterEdit rasterEdit = (IRasterEdit)raster;rasterEdit.Write(topleftCorner, pixelBlock);

二,栅格数据重分类,即修改栅格值

public void reclass(IRaster pRaster, double weight){//int trueCount = 0;//int falseCount = 0;IRasterProps rasterProps = (IRasterProps)pRaster;//设置栅格数据起始点IPnt pBlockSize = new Pnt();pBlockSize.SetCoords(rasterProps.Width, rasterProps.Height);//获取整个范围IPixelBlock pPixelBlock = pRaster.CreatePixelBlock(pBlockSize);// IPixelBlock3 pPixelBlock = (IPixelBlock3)pRaster.CreatePixelBlock(pBlockSize);//左上点坐标IPnt tlp = new Pnt();tlp.SetCoords(0, 0);//读入栅格IRasterBandCollection pRasterBands = pRaster as IRasterBandCollection;IRasterBand pRasterBand = pRasterBands.Item(0);IRawPixels pRawPixels = pRasterBands.Item(0) as IRawPixels;pRawPixels.Read(tlp, pPixelBlock);//将pixel的值组成数组System.Array pSafeArray = pPixelBlock.get_SafeArray(0) as System.Array;for (int y = 0; y < rasterProps.Height; y++){for (int x = 0; x < rasterProps.Width; x++){//int value = Convert.ToInt32(pSafeArray.GetValue(x, y));//Byte value = Convert.ToByte(pSafeArray.GetValue(x, y));//if (value != 0 && isFlood[y, x] == false)//{//    pSafeArray.SetValue((Byte)(value * weight), x, y);//}if (isFlood[y, x] == true){pSafeArray.SetValue(1, x, y);//trueCount++;}else{pSafeArray.SetValue(0, x, y);//falseCount++;}}}pPixelBlock.set_SafeArray(0, pSafeArray);//编辑raster,将更新的值写入raster中IRasterEdit rasterEdit = pRaster as IRasterEdit;rasterEdit.Write(tlp, pPixelBlock);rasterEdit.Refresh();int Fcount=0;//m_map.AddLayer//MessageBox.Show("ok");//double result = Convert.ToDouble(pSafeArray.GetValue(100, 99));}

ArcEngine修改像素值与像元值相关推荐

  1. OpenCV 读写图像、读写像素、修改像素值(案例:图像反处理)

    文章目录 读写图像 1. `imread` 可以指定加载为灰度或者RGB图像. 2. `imwrite` 保存图像文件,类型由扩展名决定. 读写像素 读一个GRAY像素点的像素值(CV_8UC1) 读 ...

  2. OpenCV4---像素操作(读写像素、修改像素值)

    四.像素操作(读写像素.修改像素值) 1.遍历图像像素 int height = gray_src.rows;//获取图像行数 int width = gray_src.cols;//获取图像列数 f ...

  3. 【C++ Opencv】读写灰度图像,RGB图像的某个像素、修改像素值、图像取反(源码+API)

    1. 读写像素 (1)读一个灰度图像的某点像素值 Scalar intensity=img.at<uchar>(y,x); 或者Scalar intensity =img.at<uc ...

  4. OpenCV中确定像素位置及获取、修改像素BGR值讲解及演示(Python实现 附源码)

    需要源码和图片集请点赞关注收藏后评论区留言~~~ 像素是图像的最小单位.每一幅图像都是由M行N列的像素组成的,其中每一个像素都存储一个像素值.以灰度图像为例,计算机通常把灰度图像的像素处理为256个灰 ...

  5. python+gda输出影像每个像元的像元值+坐标值

    读取每个像元的坐标值 from osgeo import gdal import numpy as npgdal.AllRegister()filePath = r'D:\20200309\shuju ...

  6. Intel Realsense D435 通过识别目标的像素坐标和深度值(使用内参intrinsics)获取目标点的真实坐标

    Intel Realsense D435 通过识别目标的像素坐标和深度值(使用内参intrinsics)获取目标点的真实坐标 图原理 基本获取内参`intrinsics`代码 实操代码1(在`tens ...

  7. B09_NumPy迭代数组(控制遍历顺序,修改数组中元素的值,使用外部循环,广播迭代)

    NumPy迭代数组 NumPy 迭代器对象 numpy.nditer 提供了一种灵活访问一个或者多个数组元素的方式. 迭代器最基本的任务的可以完成对数组元素的访问. 接下来我们使用arange()函数 ...

  8. unity3D 5中如何修改及显示Text的值

    分步阅读 unity3D 5中如何修改及显示Text的值 百度经验:jingyan.baidu.com 因为unit5.0的版本的原因,现在的text控件与之前版本的有了一些差异,接下来我们就来介绍如 ...

  9. EF里查看/修改实体的当前值、原始值和数据库值以及重写SaveChanges方法记录实体状态...

    EF里查看/修改实体的当前值.原始值和数据库值以及重写SaveChanges方法记录实体状态 原文:EF里查看/修改实体的当前值.原始值和数据库值以及重写SaveChanges方法记录实体状态 本文目 ...

  10. 【转】DICOM图像像素值(灰度值)转换为CT值

    转自:https://www.cnblogs.com/xuhui24/p/6193032.html            https://zhuanlan.zhihu.com/p/358770379 ...

最新文章

  1. Java关键字this、super使用总结
  2. 白领丽人减肥四大注意 - 生活至上,美容至尚!
  3. php中register_global,PHP安全之register_globals的on和off的区别
  4. 启动Memcached报错:/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-2.1
  5. 【工具使用系列】关于 MATLAB 有限元分析,你需要知道的事
  6. iptables (2) 基本配置
  7. NotifyMyFrontEnd 函数背后的数据缓冲区(一)
  8. Android静态代码扫描效率优化与实践
  9. C++ auto_ptr存在的问题
  10. Java并发编程实战——volatile
  11. 从 Flink 应用场景出发,了解它的设计思路
  12. getpriority java_Java Thread类的最终int getPriority()方法(带示例)
  13. 三维旋转矩阵_线性代数的本质(4)--矩阵乘法与复合变换
  14. 重磅!阿里推出国产开源的 JDK!
  15. SylixOS arm64 异常向量表
  16. c# timer 销毁_C# System.Timers.Timer定时器的使用和定时自动清理内存应用
  17. POJ 2112 Optimal Milking 最优挤奶方案 Floyd算法+二分查找+最大流
  18. a 标签 downLoad属性兼容,wav音频文件浏览器直接打开
  19. 理解单隐层ReLU神经网络的全局损失
  20. 以太坊性能优化:分片技术、雷电网络、Casper-下一代以太坊共识协议

热门文章

  1. word||标题序号和标题内容间隔很大
  2. Java 阴阳历转换
  3. 成功背后(敬所有IT人)
  4. java验证用户名和密码_Java验证用户名和密码
  5. linux解压tar文件夹
  6. 嵌入式实操----基于RT1170 首板硬件之CAN BUS TJA1043显示调试(十八)
  7. 一份Slide两张表格带你快速了解目标检测
  8. 电脑开机加速,一下子就提升了20几秒
  9. Android之Dex动态加载机制解析
  10. Linux weget (文件 下载)安装方法