博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
遍历栅格的方式实现栅格重分类
阅读量:3898 次
发布时间:2019-05-23

本文共 2359 字,大约阅读时间需要 7 分钟。

栅格重分类方法很多,在AE中有多种方式可以实现,使用地图代数(在RasterModel中实现),或者IReclassOp,或者Geoprocessor的方式都可以,甚至可以遍历栅格来实现,这是最原始的方式,不过也可能是最实用的。这里使用的是最原始的遍历栅格的方式。

public static void StrechDN(IRasterLayer pRasterLayer, int OTSU,int minValue, int maxValue)//修改二值化后的像素值    {        //获取栅格像素块        IRaster pRaster = pRasterLayer.Raster;        IRasterProps pRasterProps = (IRasterProps)pRaster; //rasterband;        //设置像素块的大小        IPnt pBlockSize1 = new PntClass();              pBlockSize1.SetCoords(pRasterProps.Width, pRasterProps.Height);        IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pBlockSize1);// raster2.CreateCursorEx(pBlockSize1).PixelBlock;        int w = pixelBlock.Width;        int h = pixelBlock.Height;        //read the first pixel block,左上点坐标          IPnt topleftCorner = new PntClass();        topleftCorner.SetCoords(0, 0);//左上角第一个像素点        pRaster.Read(topleftCorner, pixelBlock);//从第一个点开始读pixelBlock大小的像素块        //modify one pixel value at location (assume the raster has a pixel type of uchar)        IPixelBlock3 pixelBlock3 = (IPixelBlock3)pixelBlock;        object pValue;        System.Array pixels = (System.Array)pixelBlock3.get_PixelData(0);        for (int finalX = 0; finalX < pRasterProps.Width; finalX++)        {            for (int finalY = 0; finalY < pRasterProps.Height; finalY++)            {                pValue = pixels.GetValue(finalX, finalY);                if (Convert.ToDouble(pValue) < OTSU)                {                    pixels.SetValue(minValue, finalX, finalY);                }                else                {                    pixels.SetValue(maxValue, finalX, finalY);                }            }        }                 pixelBlock3.set_PixelData(0, (System.Object)pixels);        //write the modified pixel block to the raster dataset        IRasterEdit rasterEdit = (IRasterEdit)pRaster;        rasterEdit.Write(topleftCorner, pixelBlock);        rasterEdit.Refresh();//刷新资源        System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);//停止编辑     }

将IRasterLayer存储起来的方法

public static void SaveRasterLayerTofile(IRasterLayer pRasterLayer, string fileName, string strFileExtension="TIFF") {        IRaster pRaster = pRasterLayer.Raster;        IRaster2 pRaster2 = pRaster as IRaster2;        ISaveAs pSaveAs = pRaster2 as ISaveAs;        pSaveAs.SaveAs(fileName, null, strFileExtension);}

转载地址:http://szden.baihongyu.com/

你可能感兴趣的文章
Emacs 中文学习手册-1
查看>>
Emacs学习笔记(1):初学者的学习计划
查看>>
Emacs学习笔记(13):在Emacs中打开pdf
查看>>
Emacs学习笔记(14):在Emacs中使用git
查看>>
Emacs for vim Users---from http://www.crazyshell.org/blog/
查看>>
静态库和动态库链接那些事--http://www.crazyshell.org/blog/?p=50
查看>>
一年成为Emacs高手(像神一样使用编辑器) .--http://blog.csdn.net/redguardtoo/article/details/7222501
查看>>
GNU make 指南
查看>>
配置 vim
查看>>
centos 安装emacs24
查看>>
【转】结构体中Char a[0]用法——柔性数组
查看>>
结构体最后定义一个char p[0];这样的成员有何意义(转)
查看>>
一步一学Linux与Windows 共享文件Samba (v0.2b)
查看>>
Linux 下忘记root密码怎么办
查看>>
Linux软件下载源码编程文章资料周立发--之调试
查看>>
GIT分支管理是一门艺术
查看>>
Cscope在emacs中的配置与使用
查看>>
emacs 2.4安装问题 ecb
查看>>
ecb里使用自定义快捷键切换窗口
查看>>
vim(gvim)支持对齐线
查看>>