利用IRawPixels接口遍历栅格数据

AO的版本为10.2,开发的语言是C#。栅格数据来源IRasterDataset接口。

 1  IRasterBandCollection pRasterBandCollection = pRasterDataset as IRasterBandCollection;
 2 IRasterBand pRasterBand = pRasterBandCollection.Item(0);
 3  IRaster pRaster = (pRasterDataset as IRasterDataset2).CreateFullRaster();
 4 IRawPixels pRawPixels = pRasterBand as IRawPixels;
 5 IRasterProps pRasterProps = pRasterBand as IRasterProps;
 6 int dHeight = pRasterProps.Height;
 7 int dWidth = pRasterProps.Width;  
 8 IPnt pntSize = new PntClass();
 9 pntSize.SetCoords(dHeight, dWidth);
10 IPnt pPixelBlockOrigin = new PntClass();
11 pPixelBlockOrigin.SetCoords(0, 0);
12 IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pntSize);
13 pRawPixels.Read(pPixelBlockOrigin, pixelBlock);
14 System.Array arr = (System.Array)(pixelBlock as IPixelBlock3).get_PixelData(0);
15 for (int i = 0; i < dHeight;i++ ) 
16 {
17     for (int j = 0; j < dWidth; j++) 
18     {
19            float number = 0;
20            float.TryParse(arr.GetValue(i,j).ToString(),out number);                   
21      }
22 }

第一次写,同时也做一个记录

posted @ 2017-02-10 10:35  杰桀  阅读(617)  评论(0编辑  收藏  举报