ArcEngine删除sde中的图层
刚接触GIS开发.从代码中摘录出来的.
//ArcGIS 打开SDE数据库
IPropertySet pOutSDEPropset;
pOutSDEPropset = new PropertySet();
pOutSDEPropset.SetProperty("SERVER",ServerName);
pOutSDEPropset.SetProperty("INSTANCE",instance);
pOutSDEPropset.SetProperty("USER",UserName);
pOutSDEPropset.SetProperty("Password",PassWord);
pOutSDEPropset.SetProperty("version",SDEVersion);
//获取空间数据库对象的管理器
IWorkspaceFactory pWorkFact;
//这句话貌似根据数据库类型不同new的方法不一样.
//sde的是new 的SdeWorkspaceFactoryClass.
pWorkFact = new SdeWorkspaceFactoryClass();
//这个地方有些疑问,有的是用IFeatureWorkspace. 如: IFeatureWorkspace Workspace = Fact.Open(Propset,0) as IFeatureWorkspace;
//可能是我这边主要是想删除表(图层)吧,反正我这边项目中的代码是 IWorkspace.
IWorkspace pOutSDEWorkspace;
pOutSDEWorkspace = pWorkFact.Open(pOutSDEPropset,0);
//获取DataSet名字,实际运行起来,pEnumDsName里面是sde下的表空间名称
IEnumDatasetName pEnumDsName = pOutSDEWorkspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
//新建这个东西是为了循环这些表空间后,找到对应的表空间将其赋值给他.
IFeatureDatasetName pOutSDEFeatDSName = null;
///循环开始找到的表空间.
//这句是重置位置,表示下面开始从第一个循环.
pEnumDsName.Reset();
IDatasetName pSDEDSname;
//取得下一个
pSDEDSname = pEnumDsName.Next();
//找到对应的 DatasetName,将 IDatasetName 转化为 IFeatureDatasetName.
while(pSDEDSname != null)
{
if(pSDEDSname.Name ==SDEDSname)
{
pOutSDEFeatDSName = (IFeatureDatasetName)pSDEDSname;
break;
}
pSDEDSname = pEnumDsName.Next();
}
//这句是将该表空间的FeatureClassNames取出来.实际上取出来的都是表名(图层名)
//不过这个地方 他将表空间中的表组织成了IEnumDatasetName结构.
//之间他将用户sde下的表空间也组织成了IEnumDatasetName结构.
IEnumDatasetName pEnumFcName_del = pOutSDEFeatDSName.FeatureClassNames;
//以下循环这些表.
pEnumFcName_del.Reset();
IDatasetName tmpDs = pEnumFcName_del.Next();
while(tmpDs != null)
{
//判断表名是不是要删除的表名
if(tmpDs.Name.ToUpper() == UserName.ToUpper()+"."+NewLayName.ToUpper())
{
break;
}
else
{
tmpDs = pEnumFcName.Next();
}
}
//找到了要删除的表名
if(tmpDs != null)
{
//这个时候就将 IWorkspace转化为IFeatureWorkspace了.
IFeatureWorkspace pFWS = pOutSDEWorkspace as IFeatureWorkspace;
//再转为这个IFeatureWorkspaceManage 才能执行 delete.真麻烦.
IFeatureWorkspaceManage pFWSM;
pFWSM = (IFeatureWorkspaceManage)pFWS;
pFWSM.DeleteByName(tmpDs);
}