ArcEngine线分割面的实现方法

在一般的GIS数据编辑中,利用线分割面是常见的一项操作。很多同志不清楚如何在ArcEngine实现这一功能,其代码写得无比复杂。其实ArcEngine给我们提供了一个接口:IFeatureConstruction,利用这个接口可以轻松完成线分割面的操作。下面给出示例代码。

情况一:利用选中的线要素分割面要素

如下图所示:当前选择了两条线要素,我希望用这两条选中的线对面进行分割,这种情况在编辑流程中很常见。
ArcEngine线分割面的实现方法_第1张图片
代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;

namespace WindowsFormsApplication1
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            axMapControl1.LoadMxFile(@"C:\Users\DSF\Desktop\data\无标题.mxd");
        }

        // 分割
        private void btnSplitPolygon_Click(object sender, EventArgs e)
        {
            // 面要素
            IFeatureLayer pPolygonFeatureLayer = axMapControl1.get_Layer(1) as IFeatureLayer;
            IFeatureClass pPolygonFeatureClass = pPolygonFeatureLayer.FeatureClass;

            // 面要素范围
            IGeoDataset pGeoDataset = pPolygonFeatureClass as IGeoDataset;
            IEnvelope pEnvelope = pGeoDataset.Extent;

            // 获取被选择的线要素
            ISelection pSelection = axMapControl1.Map.FeatureSelection;
            IEnumFeature pEnumFeature = pSelection as IEnumFeature;

            // 线分割面
            IFeatureConstruction pFeatureConstruction = new FeatureConstruction();
            pFeatureConstruction.SplitPolygonsWithLines(null, pPolygonFeatureClass, pEnvelope, pEnumFeature, null, 0.001);
        }
    }
}

分割结果如下图所示:
ArcEngine线分割面的实现方法_第2张图片

情况二:利用线图层批量分割面要素

第一种情况需要先在地图上选择线要素,然后才能进行分割操作,如果遇到数据量较大的情况未免有些繁琐。我们同样可以利用线图层批量分割面要素,如下图所示:我希望直接用线要素图层中的所有线要素分割面要素图层。
ArcEngine线分割面的实现方法_第3张图片
代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;

namespace WindowsFormsApplication1
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            axMapControl1.LoadMxFile(@"C:\Users\DSF\Desktop\data\无标题.mxd");
        }

        // 分割
        private void btnSplitPolygon_Click(object sender, EventArgs e)
        {
            // 线要素
            IFeatureLayer pPolylineFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
            IFeatureClass pPolylineFeatureClass = pPolylineFeatureLayer.FeatureClass;
            IFeatureCursor pPolylineFeatureCursor = pPolylineFeatureClass.Search(null, true);

            // 面要素
            IFeatureLayer pPolygonFeatureLayer = axMapControl1.get_Layer(1) as IFeatureLayer;
            IFeatureClass pPolygonFeatureClass = pPolygonFeatureLayer.FeatureClass;

            // 面要素范围
            IGeoDataset pGeoDataset = pPolygonFeatureClass as IGeoDataset;
            IEnvelope pEnvelope = pGeoDataset.Extent;

            // 分割面
            IInvalidArea pInvalidArea = new InvalidArea();
            IFeatureConstruction pFeatureConstruction = new FeatureConstruction();
            pFeatureConstruction.SplitPolygonsWithLinesFromCursor(null, pPolygonFeatureClass, pEnvelope, pPolylineFeatureCursor, pInvalidArea, 0.001);
        }
    }
}

分割结果如下图所示:
ArcEngine线分割面的实现方法_第4张图片

你可能感兴趣的:(ArcEngine)