//删除节点 private void button4_Click(object sender, EventArgs e) { strOperator = "del"; IPointCollection pointCollection; if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { pointCollection = new PolylineClass(); IPolyline polyline = m_Feature.Shape as IPolyline; pointCollection = polyline as IPointCollection; //如果点个数少于两个无法构成线 if (pointCollection.PointCount > 2) { //移除指定的节点 pointCollection.RemovePoints(pointCollection.PointCount - 1, 1); } } else if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { pointCollection = new PolygonClass(); IPolygon polygon = m_Feature.Shape as IPolygon; pointCollection = polygon as IPointCollection; //如果点个数少于三个无法构成面 if (pointCollection.PointCount > 3) { //移除指定的节点 pointCollection.RemovePoints(pointCollection.PointCount - 1, 1); } } IWorkspaceEdit workspaceEdit; IWorkspace workspace; IDataset dataset = m_FeatureLayer.FeatureClass as IDataset; workspace = dataset.Workspace; workspaceEdit = workspace as IWorkspaceEdit; //开始编辑 workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); //保存数据 m_Feature.Store(); //结束编辑 workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); m_activeView.Refresh(); }
//IFeatureLayer m_FeatureLayer /// <summary> /// 删除节点 /// </summary> /// <param name="m_Feature"></param> public bool deleteFeature(int x, int y) { //IGeometryCollection pGeomColn ; //IPointCollection pPointColn; IObjectClass pObjectClass; IFeature pFeature; IGeometry pGeom; //IPath pPath ; IPoint pHitPoint = null; IPoint pPoint = null; Double hitDist = 0.0; double tol; int vertexIndex = 0; //int numVertices; int partIndex = 0; bool vertex = false; try { m_pMap.ClearSelection(); // 取得鼠标击中的第一个对象 SelectMouseDown(x, y); IEnumFeature pSelected = (IEnumFeature)m_pMap.FeatureSelection; pFeature = pSelected.Next(); if (pFeature == null) return false; IActiveView pActiveView = (IActiveView)m_pMap; pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); // 节点空间查询容差 tol = ConvertPixelsToMapUnits(pActiveView, 4.0); pGeom = pFeature.Shape; pObjectClass = pFeature.Class; m_pEditFeature = pFeature; object objNull = Missing.Value; //object objBefore, objAfter; IPointCollection pointCollection; if (m_pEditFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline & TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex)) { pointCollection = new PolylineClass(); IPolyline polyline = m_pEditFeature.Shape as IPolyline; pointCollection = polyline as IPointCollection; //如果点个数少于两个就无法构成线 if (pointCollection.PointCount > 2) { //移除指定的节点 pointCollection.RemovePoints(vertexIndex, 1); } else { MessageBox.Show("此先已经少于两个点,不能在删除"); } } else if (m_pEditFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon & TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex)) { pointCollection = new PolygonClass(); IPolygon polygon = m_pEditFeature.Shape as IPolygon; pointCollection = polygon as IPointCollection; //点数少于三个就不能能构成面 if (pointCollection.PointCount > 3) { //移除指点的节点 pointCollection.RemovePoints(vertexIndex, 1); } else { MessageBox.Show("此先已经少于三个点,不能在删除"); } } IWorkspaceEdit workspaceEdit; IWorkspace workspace; IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; IDataset dataset = pFeatureLayer.FeatureClass as IDataset; workspace = dataset.Workspace; workspaceEdit = workspace as IWorkspaceEdit; //开始编辑 workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); //保存数据 m_pEditFeature.Store(); //结束编辑 workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); pActiveView = (IActiveView)m_pMap; pActiveView.Refresh(); return true; } catch (Exception e) { Console.WriteLine(e.Message.ToString()); return false; } }