呃呃呃 还是稍微说一下吧 不然全是代码的话一丁点看下去的欲望都没有。本文主要是介绍如何将配置好的图层文件(*.lyr)的渲染效果赋给新添加的栅格数据,直接加在栅格数据的话,没有进行符号化,不是很美观。根据配置好的图层文件的话,效果还是不错滴 。
string filePath = "..\\..\\lyr\\**\\**.lyr";
string filePath1 = "..\\..\\lyr\\**";
this.mapControl.AddLayerFromFile(filePath, 0);
ILayer pLayer = mapControl.Map.get_Layer(0);
//获取render
IRasterLayer pRlayer = (IRasterLayer)pLayer;
IRasterRenderer renderer = null;
renderer = pRlayer.Renderer;
IWorkspaceFactory pWsF = new RasterWorkspaceFactory();
IRasterWorkspace pFtWs = pWsF.OpenFromFile(filePath1, 0) as IRasterWorkspace;
IRasterDataset pRDataset = pFtWs.OpenRasterDataset("**.tif");
IRaster pRaster;
pRaster = pRDataset.CreateDefaultRaster();//
IRasterLayer pRasterLayer;
pRasterLayer = new RasterLayer();
pRasterLayer.CreateFromRaster(pRaster);//
pRasterLayer.Renderer = renderer;
mainMapcontrol.AddLayer(pRasterLayer);