Arc Engine 删除要素

查询包含光标所在点的要素,进行删除。记得


                //开始编辑

                IWorkspaceEdit workspaceEdit;

                IWorkspace workspace;

                workspaceEdit.StartEditing(true);

                workspaceEdit.StartEditOperation();


                //删除要素

                IDataset dataset = r2.FeatureClass as IDataset;

                workspace = dataset.Workspace;

                workspaceEdit = workspace as IWorkspaceEdit;

                //找到要删除的要素

                IPoint pPoint = new PointClass();

                pPoint.PutCoords(e.mapX, e.mapY);


                IFeatureLayer pFeatureLayer = new FeatureLayerClass();

                for (int i = 0; i < axMapControl1.LayerCount; i++)

                {

                    ILayer ptempLayer = axMapControl1.get_Layer(i);

                    if (ptempLayer.Name == "样本矢量")

                        pFeatureLayer = ptempLayer as IFeatureLayer;

                }

                ISpatialFilter spatialFilter = new SpatialFilterClass();

                spatialFilter.Geometry=pPoint;

                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;

                IFeatureClass featureClass = pFeatureLayer.FeatureClass;

                IFeatureCursor featureCursor;

                featureCursor = featureClass.Search(spatialFilter, false);

                IFeature pFeature = featureCursor.NextFeature();

                if(pFeature!=null)

                {

                    pFeature.Delete();

                }


                axMapControl1.Refresh();

                //结束编辑

                workspaceEdit.StopEditOperation();

                    workspaceEdit.StopEditing(true);

你可能感兴趣的:(Arc Engine 删除要素)