柵格重分類方法很多,在AE中有多種方式可以實現,使用地圖代數(在RasterModel中實現),或者IReclassOp,或者Geoprocessor的方式都可以,甚至可以遍歷柵格來實現,這是最原始的方式,不過也可能是最實用的。這裡使用的是最原始的遍歷柵格的方式。 [csharp] 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(); }