加载Shapefile数据,加载栅格数据,加载CAD数据, 加载PersonGeodatabase数据,加载SDE数据库数据. 做项目整理出来的,用的时候,直接拷入即可,方便、快捷。 1 IWorkspaceFactory pWorkspaceFactory; 2 IFeatureWorkspace pFeatureWorkspace; 3 IFeatureLayer pFeatureLayer; 4 5 //获取当前路径和文件名 6 OpenFileDialog dlg = new OpenFileDialog(); 7 dlg.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*"; 8 dlg.Title = "Open Shapefile data"; 9 dlg.ShowDialog(); 10 string strFullPath = dlg.FileName; 11 if (strFullPath == "") return; 12 int Index = strFullPath.LastIndexOf("\\"); 13 string filePath = strFullPath.Substring(0, Index); 14 string fileName = strFullPath.Substring(Index + 1); 15 16 //打开工作空间并添加shp文件 17 pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); 18 pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0); 19 pFeatureLayer = new FeatureLayerClass(); 20 21 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName); 22 pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName; 23 axMapControl1.Map.AddLayer(pFeatureLayer); 24 axMapControl1.ActiveView.Refresh();