//获得Shape文件 by gisoracle public static IFeatureClass GetFeatureClassByFileName(string fileName) { IWorkspace shapeWorkspace = GetWorkSpaceByPath(fileName); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)shapeWorkspace; string extfileName = System.IO.Path.GetFileNameWithoutExtension(fileName); //文件名 IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(extfileName); return featureClass; } //by gisoracle public static void DelFeatureFile(string sDir, string sName) { IFeatureClass pFeatCls = GetFeatureClassByFileName(sDir + sName); if (pFeatCls != null) { IDataset dataset = pFeatCls as IDataset; dataset.Delete(); } } //保存一个FeatureClass为文件 by gisoracle public void saveFeatureClass(IFeatureClass pFeatureClass, string fileName) { try { string sFileName = System.IO.Path.GetFileName(fileName); string sFilePath = System.IO.Path.GetDirectoryName(fileName); IDataset pDataset = pFeatureClass as IDataset; IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0) as IFeatureWorkspace; IWorkspace pWorkspace = pFeatureWorkspace as IWorkspace; if (pWorkspace.Exists() == true) { DelFeatureFile(sFilePath, sFileName); } pDataset.Copy(sFileName, pFeatureWorkspace as IWorkspace); } catch { MessageBox.Show("错误"); } }