本文主要是介绍基于arcpro3.0.2的删除图层中与掩码图层不相交的要素功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
基于arcpro3.0.2的删除图层中与掩码图层不相交的要素功能
其代码如下所示:
//开始删除功能
private void btnRun_Click(object sender, EventArgs e)
{ProcessWindow pw = null;try{//获取图层var delFeatsLayer = this.cb_DeleteFeatures.SelectedItem as FeatureLayer;if (delFeatsLayer == null){MessageBox.Show("请先选择一个要删除要素的图层", "提示");return;}var maskLayer = this.cb_MaskLayer.SelectedItem as FeatureLayer;if (maskLayer == null){MessageBox.Show("请先选择一个掩码图层", "提示");return;}pw = appTool.getNewProcessWindow("删除进度...");pw.Show();QueuedTask.Run(() =>{pw.setMinValue(0);pw.setMaxValue(10);pw.setValue(0);//FeatureClass delFc = delFeatsLayer.GetFeatureClass();FeatureClass maskFc = maskLayer.GetFeatureClass();long fIndex = 0;long fCount = delFc.GetCount();pw.setMaxValue(fCount);using (RowCursor rowCursor =delFc.Search(null)){ using(RowCursor maskCursor=maskFc.Search(null)){//合并几何对象pw.addMessageTime("正在准备合并掩码几何对象");Geometry maskGeo = null;while(maskCursor.MoveNext()){using(Feature maskFeat =maskCursor.Current as Feature){if(maskFeat != null && maskFeat.GetShape()!=null){if(maskGeo==null){maskGeo = maskFeat.GetShape();}else{maskGeo = GeometryEngine.Instance.Union(maskGeo, maskFeat.GetShape());}}}}pw.addMessageTime("合并掩码几何对象完毕");pw.addMessageTime("准备删除与掩码图层不相交的要素...");//判断并删除要素List<long> idList = new List<long>();while (rowCursor.MoveNext()){using (Feature delFeat = rowCursor.Current as Feature){fIndex += 1;if (delFeat != null){if (GeometryEngine.Instance.Intersects(delFeat.GetShape(),maskGeo)==false){ //不相交的要素,则删除之 idList.Add(delFeat.GetObjectID());}}if (fIndex % 5000 == 0){pw.addMessageTime("正在处理要素: " + fIndex + "/" + fCount);}}}pw.setMaxValue(idList.Count);Table table = delFeatsLayer.GetTable(); //for (int i=0;i<idList.Count; i++){ long oid = idList[i];EditOperation delFeats = new EditOperation();delFeats.Delete(table, oid);if (delFeats.IsEmpty == false){delFeats.Execute(); }if (i % 5000 == 0){pw.addMessageTime("正在删除要素: " + i + "/" + idList.Count);}}pw.addMessageTime("处理要素个数 " + fCount + "/" + fCount);} } pw.addMessageTime("处理完毕");//});}catch (Exception ex){MessageBox.Show(ex.ToString());}finally{}}
本blog地址:https://blog.csdn.net/hsg77
这篇关于基于arcpro3.0.2的删除图层中与掩码图层不相交的要素功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!