/// <summary> /// 删除fieldName属性值为1的弧段 /// </summary> /// <param name="fieldName"></param> /// <param name="t"></param> public void DelectPolyline(string fieldName, int t) { ILayer pLayer = axMapControl1.get_Layer(0); IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IFields pIFields = pFeatureLayer.FeatureClass.Fields; int fieldIndex = pIFields.FindField(fieldName); var pDataset = pFeatureClass as IDataset; IWorkspace pWorkspace = pDataset.Workspace; IFeatureWorkspace pFWs = pWorkspace as IFeatureWorkspace; IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pFWs; pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureCursor pEF = pFeatureLayer.Search(null, false); IFeature pFeatureDe = pEF.NextFeature(); while (pFeatureDe != null) { if (Convert.ToInt32(pFeatureDe.get_Value(fieldIndex)) != t) { pFeatureDe.Delete(); } pFeatureDe = pEF.NextFeature(); } pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); MessageBox.Show("删除成功"); }
///若干个线要素合并成一个 private void MergeFeatures(List<int> OneFeatureArr,ILayer tSelectLayer) { IFeatureLayer tFeatureLayer = tSelectLayer as IFeatureLayer; IFeatureClass pFeatureClass = tFeatureLayer.FeatureClass; var pDataset = pFeatureClass as IDataset; IWorkspace pWorkspace = pDataset.Workspace; IFeatureWorkspace pFWs = pWorkspace as IFeatureWorkspace; IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pFWs; pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureLayer pFeatureLayer = tSelectLayer as IFeatureLayer; IFeatureCursor pEF = pFeatureLayer.Search(null, false); IFeature pFeatureFirst = pEF.NextFeature(); while (pFeatureFirst != null) {//找到在数组里的第一个要素 if (pFeatureFirst.OID == OneFeatureArr[0]) { //OneFeatureArr.RemoveAt(0);//除掉第一个要素 break; } else pFeatureFirst = pEF.NextFeature(); } pEF = pFeatureLayer.Search(null, false); IGeometry pGeometryFirst = pFeatureFirst.Shape; ITopologicalOperator2 pTopOperatorFirst = (ITopologicalOperator2)pGeometryFirst; IRelationalOperator pRelOperatorFirst = (IRelationalOperator)pGeometryFirst; pTopOperatorFirst.IsKnownSimple_2 = false; pTopOperatorFirst.Simplify(); pGeometryFirst.SnapToSpatialReference(); IGeometry pGeometrySecond = null; IFeature pFeatureSecond = pEF.NextFeature(); IGeometryCollection Geometrybag = new GeometryBagClass();//装geometry的袋子 object oMissing = Type.Missing; while (pFeatureSecond != null) { if (OneFeatureArr.IndexOf(pFeatureSecond.OID) == -1) { pFeatureSecond = pEF.NextFeature(); continue; } pGeometrySecond = pFeatureSecond.ShapeCopy; Geometrybag.AddGeometry(pGeometrySecond, ref oMissing, ref oMissing);//将geometry装进袋子 //pFeatureSecond.Delete(); pFeatureSecond = pEF.NextFeature(); } IEnumGeometry tEnumGeometry = (IEnumGeometry)Geometrybag; pTopOperatorFirst.ConstructUnion(tEnumGeometry); pTopOperatorFirst.IsKnownSimple_2 = false; pTopOperatorFirst.Simplify(); pFeatureFirst.Shape = pGeometryFirst; pFeatureFirst.Store(); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); }
时间: 2024-10-10 17:24:22