AE 遍历栅格实现栅格重分类(C#实现)

来源:互联网 发布:软件无线电原理 编辑:程序博客网 时间:2024/06/05 00:23

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

        private void reclass(IRaster pRaster, float weight)        {            IRasterProps rasterProps = (IRasterProps)pRaster;            //设置栅格数据起始点            IPnt pBlockSize = new Pnt();            pBlockSize.SetCoords(rasterProps.Width, rasterProps.Height);            //选取整个范围            IPixelBlock pPixelBlock = pRaster.CreatePixelBlock(pBlockSize);            //左上点坐标            IPnt tlp = new Pnt();            tlp.SetCoords(0, 0);            //读入栅格              IRasterBandCollection pRasterBands = pRaster as  IRasterBandCollection;            IRasterBand pRasterBand = pRasterBands.Item(0);            IRawPixels pRawRixels = pRasterBands.Item(0) as IRawPixels;            pRawRixels.Read(tlp, pPixelBlock);            //将PixBlock的值组成数组            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)                    {                        pSafeArray.SetValue((Byte)(value * weight), x, y);                    }                }            }            pPixelBlock.set_SafeArray(0, pSafeArray);            //编辑raster,将更新的值写入raster中            IRasterEdit rasterEdit = pRaster as IRasterEdit;            rasterEdit.Write(tlp, pPixelBlock);            rasterEdit.Refresh();        }


原创粉丝点击