IWorkspace操作
1、创建工作空间
public static IWorkspace CreateWorkspace(string pName, string pPath) { IWorkspaceFactory workspaceFactory = null; Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory"); workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); Directory.CreateDirectory(pPath); IWorkspaceName workspaceName = workspaceFactory.Create(pPath, pName,null, 0); IName Name = (IName)workspaceName; _workSpaceInstance = (IWorkspace)(Name.Open()); return _workSpaceInstance; }
2、创建要素集
<span style="white-space:pre"> </span> public static IFeatureDataset CreateFeatureDataSet(/*string name,ISpatialReference srf*/) { IFeatureDatasetDialog fdlg = new FeatureDatasetDefDialog(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)_workSpaceInstance; return fdlg.DoModalCreate(featureWorkspace, 0); }
3、删除要素集
<span style="white-space:pre"> </span>public static void DeleteFeatureDataSet(string name) { IFeatureDataset fds = GetFeatureDataSet(name); if (fds != null) fds.Delete(); }
4、获取数据库中的IFeatureDataset
<span style="white-space:pre"> </span>public static IFeatureDataset GetFeatureDataSet(string name) { if (_workSpaceInstance == null) return null; IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)_workSpaceInstance; IFeatureDataset tmp = featureWorkspace.OpenFeatureDataset(name); return tmp; }
5、重命名DataSet
<span style="white-space:pre"> </span>public static void RenameFeatureDataSet(IFeatureDataset fds,string newname) { if (fds.CanRename()) { fds.Rename(newname); } }6、
/// <summary> /// 获取FeatureClass从IFeatureDataset /// </summary> /// <param name="featDs"></param> /// <param name="className"></param> /// <returns></returns> public static IFeatureClass GetFeatureClassFromFeatureDataset(IFeatureDataset featDs, string className) { IFeatureClass featClass; IFeatureClassContainer fcContainer = featDs as IFeatureClassContainer; for (int i = 0; i < fcContainer.ClassCount; i++) { featClass = fcContainer.get_Class(i); if (RuleDBCreater.GetFeatureClassName(featClass) == className) { return featClass; } } return null; }7、重命名Dataset
public static void RenameFeatureClass(IFeatureClass fc,string newname) { IDataset ds = fc as IDataset; if (ds.CanRename()) { ds.Rename(newname); } }
参考地址:http://www.cnblogs.com/sxw_cug/archive/2010/08/19/1803971.html