///
/// 栅格分类专题图
///
/// 栅格图层
public static void funColorForRaster_Classify(IRasterLayer pRasterLayer)
{
IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer;
IRasterRenderer pRRend = pRClassRend as IRasterRenderer;
IRaster pRaster = pRasterLayer.Raster;
IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
IRasterBand pRBand = pRBandCol.Item(0);
if (pRBand.Histogram == null)
{
pRBand.ComputeStatsAndHist();
}
pRRend.Raster = pRaster;
pRClassRend.ClassCount = 10;
pRRend.Update();
IRgbColor pFromColor = new RgbColor() as IRgbColor;
pFromColor.Red = 255;
pFromColor.Green = 0;
pFromColor.Blue = 0;
IRgbColor pToColor = new RgbColor() as IRgbColor;
pToColor.Red = 0;
pToColor.Green = 0;
pToColor.Blue = 255;
IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp;
colorRamp.Size = 10;
colorRamp.FromColor = pFromColor;
colorRamp.ToColor = pToColor;
bool createColorRamp;
colorRamp.CreateRamp(out createColorRamp);
IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol;
for (int i = 0; i < pRClassRend.ClassCount; i++)
{
fillSymbol.Color = colorRamp.get_Color(i);
pRClassRend.set_Symbol(i, fillSymbol as ISymbol);
pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00"));
}
pRasterLayer.Renderer = pRRend;
}
///
/// 打开遥感图像
///
/// 图像的地址
/// IRasterLayer
private IRasterLayer OpenImage(string imagePath)
{
string ws = Path.GetDirectoryName(imagePath);
string fbs = Path.GetFileName(imagePath);
IWorkspaceFactory pWork = new RasterWorkspaceFactory();
IRasterWorkspace pRasterWs = pWork.OpenFromFile(ws,0) as IRasterWorkspace;
IRasterDataset pRasterDataset = pRasterWs.OpenRasterDataset(fbs);
IRasterLayer pRasterLayer = new RasterLayer() as IRasterLayer;
pRasterLayer.CreateFromDataset(pRasterDataset);
return pRasterLayer;
}
funColorForRaster_Classify(axMapControl1.get_layer(0) as IRasterLayer);//only one RasterLayer