ArcObjects 波段合成

可以用地理处理

Class CompositeBands Creates a single raster dataset from multiple bands and can also create a raster dataset using only a subset of bands.

也可以不用,贴代码了

public static IRaster toColor(IRaster raster, ITable redTable, ITable greenTable, ITable blueTable)
{
IReclassOp reclassOp
= new RasterReclassOpClass();
IGeoDataset red
= reclassOp.Reclass(raster as IGeoDataset, redTable, "FromField",
"ToField", "OutField", true);
IGeoDataset green
= reclassOp.Reclass(raster as IGeoDataset, redTable, "FromField",
"ToField", "OutField", true);
IGeoDataset blue
= reclassOp.Reclass(raster as IGeoDataset, redTable, "FromField",
"ToField", "OutField", true);

IRasterBandCollection rasterBandCollection;
IRaster newRaster
= new RasterClass();
rasterBandCollection
= newRaster as IRasterBandCollection;

IRasterBandCollection tempRasterBandCollection;
IRasterBand tempRasterBand;

tempRasterBandCollection
= red as IRasterBandCollection;
tempRasterBand
= tempRasterBandCollection.Item(0);
rasterBandCollection.AppendBand(tempRasterBand);

tempRasterBandCollection
= green as IRasterBandCollection;
tempRasterBand
= tempRasterBandCollection.Item(0);
rasterBandCollection.AppendBand(tempRasterBand);

tempRasterBandCollection
= blue as IRasterBandCollection;
tempRasterBand
= tempRasterBandCollection.Item(0);
rasterBandCollection.AppendBand(tempRasterBand);

return newRaster;
}

  保存的时候一定要注意,保存成TIFF格式,保存成GRID格式,会报错Stack name *** is too long,是GRID不支持多波段吧

            ISaveAs2 save = MyRasterTools.toColor(raster, rTable, gTable, bTable) as  ISaveAs2;
IDataset outRasterDS
= save.SaveAs("multibands.tif", rasterWorkspace as IWorkspace, "TIFF");
System.Runtime.InteropServices.Marshal.ReleaseComObject(outRasterDS);

  最后一句释放保存的结果,要不然之后从Workspace打开,会报错

posted on 2011-07-23 19:14  更好的人  阅读(406)  评论(0编辑  收藏  举报

导航