删除SDE中要素,依据属性条件删除SDE某要素集中满足要求的要素
#region 删除要素集满足某条件指定要素3
/// <summary>
/// 删除要素集满足某条件指定要素
/// </summary>
/// <param name="workspace"></param>
/// <param name="featureclass"></param>
public static void DeleteSDEFeature3()
{
//删除要素集满足某条件指定要素条件 线路编码=G321
string featureclass = "SDE.RoadLines";//SDE中要素集名称
string strKey = "G321";//删除的道路要素 线路编码
//打开SDE工作空间
IPropertySet pProSet = new PropertySetClass();
pProSet.SetProperty("Server", "service");
pProSet.SetProperty("Instance", "5151");
pProSet.SetProperty("Database", "sde");
pProSet.SetProperty("user", "sde");
pProSet.SetProperty("password", "sdepassword");
pProSet.SetProperty("version", "sde.DEFAULT");
IWorkspaceFactory factory = new SdeWorkspaceFactoryClass();
IWorkspace WKS = factory.Open(pProSet, 0);
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)WKS;
ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(featureclass);
ESRI.ArcGIS.Geodatabase.IWorkspaceEdit workspaceEdite = (ESRI.ArcGIS.Geodatabase.IWorkspaceEdit)WKS;
workspaceEdite.StartEditing(true);
workspaceEdite.StartEditOperation();
ESRI.ArcGIS.Geodatabase.IQueryFilter que = new QueryFilterClass();
que.WhereClause = "线路编码='" + strKey + "'";
ESRI.ArcGIS.Geodatabase.IFeatureCursor ifc = featureClass.Search(que, true);
ESRI.ArcGIS.Geodatabase.IFeature fedel = ifc.NextFeature();
while (fedel != null)
{
fedel.Delete();
fedel = ifc.NextFeature();
}
bool hasEdits = false;
workspaceEdite.HasEdits(ref hasEdits);
if (hasEdits)
{
workspaceEdite.StopEditing(true);
}
}
#endregion