ArcGIS Engine 10 开发手册(8-8)示例:改变栅格数据像素的值

本文目录
  • 正文

本文通过代码演示如何改变栅格数据像素的值。

示例代码

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)

            {

              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);

  }

}

处理结果

原始影像图:

处理后的影像图:

ArcGIS Engine 10 开发手册全集

ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册

如果本文对你有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。
赞赏支持
微信捐助麻辣GIS 支付宝捐助麻辣GIS

麻辣GIS-Sailor
作者:
GIS爱好者,学GIS,更爱玩GIS。

如您有疑问,可在文末留言,或到QQ群提问。

本站QQ群(一):291616564 麻辣GIS

本站QQ群(二):166408035 麻辣GIS(二)

微信公众号:malagis,扫描右边二维码直接关注。

发表评论