• AE IRasterCursor 改变栅格图层像素值


    刚刚说的是获取像素值。如果要进一步改变像素值的话,需要用到IRasterEdit接口的Write方法。Write方法的参数有两个,一个是在栅格图像中的左上角位置(行列值不是坐标值),另一个就是获取像素值时提到的PixelBlock. 执行完Write方法后要对实现IRasterEdit接口的对象进行释放。

     1 public void ChangePixelValue(double xMax, double xMin, double yMax, double yMin,double[,] PixelChanged)
     2 {
     3     IRaster pRaster = thisRasterLayer.Raster;
     4     IRaster2 pRaster2 = pRaster as IRaster2;       
     5       
     6     //地图坐标转换为图中行列值
     7     rowMax = pRaster2.ToPixelRow(yMin);
     8     rowMin = pRaster2.ToPixelRow(yMax);
     9     columnMin = pRaster2.ToPixelColumn(xMin);
    10     columnMax = pRaster2.ToPixelColumn(xMax);
    11       
    12     int Height = rowMax - rowMin + 1;
    13     int Width = columnMax - columnMin + 1;
    14       
    15     //按照需要的大小建立一个空的PixelBlock3
    16     IPnt blocksize = new PntClass();
    17     blocksize.SetCoords(Width, Height);
    18       
    19     IPixelBlock3 pPixelBlock3 = pRaster.CreatePixelBlock(blocksize) as IPixelBlock3;
    20       
    21     System.Array pixels = (System.Array)pPixelBlock3.get_PixelData(0);
    22       
    23     //为新建的PixelBlock赋值
    24     try
    25     {
    26         for (int i = 0; i < Height; i++)
    27         {
    28             for (int j = 0; j < Width; j++)
    29             {
    30                 pixels.SetValue(Convert.ToByte(PixelChanged[i,j]), j, i);
    31             }
    32         }
    33     }
    34     catch (Exception ex)
    35     {
    36         MessageBox.Show(ex.Message);
    37     }
    38       
    39     //把像素值赋予新建的PixelBlock3
    40     pPixelBlock3.set_PixelData(0, pixels);
    41       
    42     //PixelBlock3应在的位置
    43     blocksize.SetCoords(columnMin, rowMin);
    44       
    45     //改变的像素值写入图层
    46     IRasterEdit pRasterEdit = pRaster as IRasterEdit;
    47     pRasterEdit.Write(blocksize, (IPixelBlock)pPixelBlock3);
    48     pRasterEdit.Refresh();
    49       
    50     System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);    
    51 }

    修改过的图层需要保存:

    1 //要保存的图层;
    2 IRasterLayer pRasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;  
    3 IRaster pRaster = pRasterLayer.Raster;
    4 IRaster2 pRaster2 = pRaster as IRaster2;
    5     
    6 ISaveAs pSaveAs = pRaster2 as ISaveAs;
    7 pSaveAs.SaveAs(@"F:\Work\DEM高程矩阵\DEM高程矩阵\bin\Debug\渲染图层2.tif", null, "TIFF");
  • 相关阅读:
    iOS实时查看App运行日志
    Jmeter-使用Ultimate Thread Group插件来设置负载场景
    Flask使用Flask-SQLAlchemy操作MySQL数据库
    使用requests库提交multipart/form-data 格式的请求
    spark 性能调优(一) 性能调优的本质、spark资源使用原理、调优要点分析
    一、spark错误
    sqoop 补充
    Hbase—— rowkey 过滤器(rowfilter)
    spark 调优——基础篇
    scala 的安装 与 IDEA安装使用
  • 原文地址:https://www.cnblogs.com/GISRS/p/3700896.html
Copyright © 2020-2023  润新知