AE+C#通過名稱來刪除要素類
阿新 • • 發佈:2019-02-12
- //注: 在程式執行中往往有些要素類因為出錯而無法刪除,這時IDataset.Delete這個方法則無法成功,可以用輕量級的名稱物件來完成這個任務。以下為C#+AE10原始碼。
- 方法一:
- //刪除要素類
- publicstaticbool DeleteFeatureDataset(IWorkspace ws, string name)
- {
- if (ws == null || string.IsNullOrEmpty(name))
- {
-
ErrMsg = "工作空間或要素類名稱不能為空!"
- returnfalse;
- }
- IFeatureDataset pFeaDataSet;
- IEnumDatasetName pEnumDatasetName;
- IFeatureWorkspace pFeaWorkspace;
- IDatasetName pDatasetName;
- try
- {
-
pFeaWorkspace = ws as
- pEnumDatasetName = ws.get_DatasetNames(esriDatasetType.esriDTFeatureClass ^ esriDatasetType.esriDTFeatureDataset);
- pEnumDatasetName.Reset();
- pDatasetName = pEnumDatasetName.Next();
-
while (pDatasetName != null
- {
- if (pDatasetName.Type == esriDatasetType.esriDTFeatureDataset)
- {
- //如果是要素集,則對要素集內的要素類進行查詢
- IEnumDatasetName pEnumFcName = (pDatasetName as IFeatureDatasetName).FeatureClassNames;
- IDatasetName pFcName = pEnumFcName.Next();
- while (pFcName != null)
- {
- if (pFcName.Name.IndexOf(name) >= 0)
- {
- DeleteByName(pFeaWorkspace, pFcName);
- returntrue;
- }
- pFcName = pEnumFcName.Next();
- }
- }
- else
- {
- if (pDatasetName.Name.IndexOf(name) >= 0)
- {
- DeleteByName(pFeaWorkspace, pDatasetName);
- returntrue;
- }
- }
- pDatasetName = pEnumDatasetName.Next();
- }
- returnfalse;
- }
- catch (Exception ex)
- {
- ErrMsg = ex.Message;
- returnfalse;
- }
- }
- //刪除名稱物件
- publicstaticvoid DeleteByName(IFeatureWorkspace pFeaWorkspace, IDatasetName pDatasetName)
- {
- IFeatureWorkspaceManage pWorkspaceManager = pFeaWorkspace as IFeatureWorkspaceManage;
- pWorkspaceManager.DeleteByName(pDatasetName);
- }
- 方法二:
- 呼叫GP工具,datamanagement下的delete工具
- ESRI.ArcGIS.DataManagementTools.Delete deleteTool = new ESRI.ArcGIS.DataManagementTools.Delete();
deleteTool.in_data = otherPara[0];
geoProcessor.Execute(deleteTool, null);