AE中波段通道组合的实现

效果如下图所示:
这里写图片描述

不论是使用ICommand加载数据还是用自己创建IWorkspaceFactory进行加载数据,需要注意的是:
默认情况下创建的Raster是默认属性(超过3个波段的话,只含有3个波段)。
这里涉及到两个函数:

  • CreateDefaultRaster():Creates a raster object with the default properties for this dataset
  • CreateFullRaster():Creates a raster containing all bands in this raster dataset.

我们需要用CreateFullRaster()函数,因为有的栅格数据是多于3个波段的,如果使用CreateDefaultRaster函数,只能获得三个波段,而不能获得所有的波段。

加载栅格数据的代码就不多说了,其中一段代码需要注意:

            IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pFileName);
            IRasterDataset3 pRasterDataset3 = pRasterDataset as IRasterDataset3;//需要用到IRasterDataset3 
            IRaster pRaster;
            pRaster = pRasterDataset3.CreateFullRaster();//使用CreateFullRaster()函数。
            IRasterLayer pRasterLayer;
            pRasterLayer = new RasterLayerClass();

下面就是获取数据集中的波段以及添加到界面中。

pRasterLayer.CreateFromRaster(pRaster);//或者pRasterLayer.CreateFromDataset(pRasterDataset);
IRasterBandCollection pRasterBC = (IRasterBandCollection)pRaster;
for (int i = 0; i < pRasterLayer.BandCount; i++)
{
    IRasterBand pRasterBand = pRasterBC.Item(i);
    comboBoxBlue.Items.Add(pRasterBC.Item(i).Bandname);
    comboBoxGreen.Items.Add(pRasterBC.Item(i).Bandname);
    comboBoxRed.Items.Add(pRasterBC.Item(i).Bandname);
}

下面代码是进行波段组合:

private void btnApply_Click(object sender, EventArgs e)
{
    if (radioButtonGray.Checked)//灰度图
    {
        if (this.comboBoxRed.Text == "")
            return;
        IRasterLayer pRasterLayer = new RasterLayerClass();
        IRasterBand pRasterBand = pRasterBC.get_BandByName(this.comboBoxRed.Text);
        IRasterDataset pRasterDataset = pRasterBand as IRasterDataset;

        pRasterLayer.CreateFromDataset(pRasterDataset);
        pMapControl.AddLayer(pRasterLayer);
        pMapControl.Refresh();
    }
    else if (radioButtonColor.Checked)//彩色图
    {
        if (this.comboBoxRed.Text == "" || this.comboBoxGreen.Text == ""
            || this.comboBoxBlue.Text == "")
            return;
        IRaster pTempRaster = new RasterClass();
        IRasterBandCollection pRasterBandcollection = (IRasterBandCollection)pTempRaster;
        pRasterBandcollection.AppendBand(pRasterBC.get_BandByName(this.comboBoxRed.Text));
        pRasterBandcollection.AppendBand(pRasterBC.get_BandByName(this.comboBoxGreen.Text));
        pRasterBandcollection.AppendBand(pRasterBC.get_BandByName(this.comboBoxBlue.Text));

        IRasterLayer pRasterLayer = new RasterLayerClass();
        pRasterLayer.CreateFromRaster(pTempRaster);
        pMapControl.AddLayer(pRasterLayer);
        pMapControl.Refresh();

    }
}
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页