先打開柵格文件所在的工做空間(文件),而後獲取其全部的波段,訪問每個波段
有時候波段中已經有直方圖或統計信息,有時候沒有這些信息,可使用ComputeStatsAndHist()函數對其進行計算
(數據量較大時,可能耗時較長)
IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
IWorkspace workspace;
workspace = workspaceFactory.OpenFromFile(filePath, 0);
IRasterWorkspace rastWork = (IRasterWorkspace)workspace;
IRasterDataset rastDataset = rastWork.OpenRasterDataset(pathBox.Text.Substring(pathBox.Text.LastIndexOf("\\") + 1));
IRasterDataset2 rd2 = rastDataset as IRasterDataset2;
IRaster raster = rd2.CreateFullRaster();
IRasterBandCollection rbc = (IRasterBandCollection)raster;
for (int i = 0; i < rbc.Count; i++)
{
IRasterBand rb = rbc.Item(i);
bool tmpBool ;
rb.HasStatistics(out tmpBool);
if(!tmpBool)
rb.ComputeStatsAndHist();
IRasterHistogram rh = rb.Histogram;
IRasterStatistics rs = rb.Statistics;
}
from: http://blog.csdn.net/rrrrssss00/article/details/6585211