//此处为矢量图层的加载方法,由于图层本身是已经制作好了的MXD类工程文件,所以直接采用MXD的加载方式 if (axMapControl1.CheckMxFile(shpFile))//判断是否为MXD文件 { IArray pArry; pArry = axMapControl1.ReadMxMaps(shpFile, Type.Missing); IMap pMap; for (int i = 0; i < pArry.Count; i++) { pMap = pArry.get_Element(i) as IMap; if (pMap.Name == "Layers") { axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass; axMapControl1.LoadMxFile(shpFile, 0, Type.Missing); axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; } }
//此处为栅格图层的加载方式,需要打开IWorkSpace string filePath = "文件路径"; string pathName = System.IO.Path.GetDirectoryName(filePath); string fileName = System.IO.Path.GetFileName(filePath); IWorkspaceFactory pWSF; pWSF = new RasterWorkspaceFactoryClass(); IWorkspace pWS; pWS = pWSF.OpenFromFile(pathName, 0); IRasterWorkspace pRWS; pRWS = pWS as IRasterWorkspace; IRasterDataset pRasterDataset; pRasterDataset = pRWS.OpenRasterDataset(fileName); IRasterPyramid pRasPyrmid; pRasPyrmid = pRasterDataset as IRasterPyramid; if (pRasPyrmid != null) { if (!(pRasPyrmid.Present)) { pRasPyrmid.Create(); } } IRaster pRaster; pRaster = pRasterDataset.CreateDefaultRaster(); IRasterLayer pRasterLayer; pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromRaster(pRaster); ILayer pLayer = pRasterLayer as ILayer; axMapControl1.AddLayer(pLayer, 2);//设置栅格图层的显示层次
时间: 2024-09-29 09:49:46