关闭

AE+C#通过名称来删除要素类(转)

标签: ArcGISesri
977人阅读 评论(0) 收藏 举报
分类:

//: 在程序运行中往往有些要素类因为出错而无法删除,这时IDataset.Delete这个方法则无法成功,可以用轻量级的名称对象来完成这个任务。以下为C#+AE10源码。

//删除要素类
public static boolDeleteFeatureDataset(IWorkspace ws, string name)
{
if (ws == null || string.IsNullOrEmpty(name))
{
ErrMsg = “
工作空间或要素类名称不能为空!”;
return false;
}
IFeatureDataset pFeaDataSet;
IEnumDatasetName pEnumDatasetName;
IFeatureWorkspace pFeaWorkspace;
IDatasetName pDatasetName;
try
{
pFeaWorkspace = ws as IFeatureWorkspace;
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);
return true;
}
pFcName = pEnumFcName.Next();
}
}
else
{
if (pDatasetName.Name.IndexOf(name) >= 0)
{
DeleteByName(pFeaWorkspace, pDatasetName);
return true;
}
}
pDatasetName = pEnumDatasetName.Next();
}
return false;
}
catch (Exception ex)
{
ErrMsg = ex.Message;
return false;
}
}
//
删除名称对象
public static voidDeleteByName(IFeatureWorkspace pFeaWorkspace, IDatasetName pDatasetName)
{
IFeatureWorkspaceManage pWorkspaceManager = pFeaWorkspace asIFeatureWorkspaceManage;
pWorkspaceManager.DeleteByName(pDatasetName);
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:417328次
    • 积分:6994
    • 等级:
    • 排名:第3432名
    • 原创:292篇
    • 转载:3篇
    • 译文:1篇
    • 评论:36条
    最新评论