ArcGIS Engine - 图层操作 Union(联合)Intersect(相交)Erase(擦除)

ArcGIS Engine - 图层操作 Union(联合)Intersect(相交)Erase(擦除)_第1张图片

        /// 
        /// 联合要素
        /// 
        /// 合并图层列表
        /// 输出路径
        /// 
        private void UnionFeatureClass(List<ILayer> pLayers, string path)
        {
            //对要素类进行相交运算
            IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();
            gpValueTableObject.SetColumns(pLayers.Count);
            for(int i = 0; i < pLayers.Count;i++)
            {
                IFeatureClass pFeatureClass = (pLayers[i] as IFeatureLayer).FeatureClass;
                object Row = pFeatureClass; 
                gpValueTableObject.AddRow(ref Row);
            }

            //联合工具
            ESRI.ArcGIS.AnalysisTools.Union UnionTool = new ESRI.ArcGIS.AnalysisTools.Union();
            UnionTool.in_features = gpValueTableObject;
            UnionTool.out_feature_class = path;

            //执行GP工具
            ExecuteGPTool(UnionTool);
        }

 		/// 
        /// 相交要素
        /// 
        /// 相交图层列表
        /// 输出路径
        /// 
        private void IntersectFeatureClass(List<ILayer> pLayers, string path)
        {
            //对要素类进行相交运算
            IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();
            gpValueTableObject.SetColumns(pLayers.Count);
            for (int i = 0; i < pLayers.Count; i++)
            {
                IFeatureClass pFeatureClass = (pLayers[i] as IFeatureLayer).FeatureClass;
                object Row = pFeatureClass;
                gpValueTableObject.AddRow(ref Row);
            }

            //相交工具
            ESRI.ArcGIS.AnalysisTools.Intersect IntersectTool = new ESRI.ArcGIS.AnalysisTools.Intersect();
            IntersectTool.in_features = gpValueTableObject;
            IntersectTool.out_feature_class = path;

            //执行GP工具
            ExecuteGPTool(IntersectTool);
        }

		/// 
        /// 擦除要素
        /// 
        /// 输入要素
        /// 相减要素
        /// 输出路径
        /// 
        private void EraseFeatureClass(ILayer in_pLayer, ILayer erase_pLayer, string out_path)
        {
            //擦除工具
            ESRI.ArcGIS.AnalysisTools.Erase EraseTool = new ESRI.ArcGIS.AnalysisTools.Erase();
            EraseTool.in_features = in_pLayer;
            EraseTool.erase_features = erase_pLayer;
            EraseTool.out_feature_class = out_path;

            //执行GP工具
            ExecuteGPTool(EraseTool);
        }
        /// 
        /// 执行GP工具
        /// 
        /// 
        /// 
        private void ExecuteGPTool(IGPProcess gpProcess)
        {
            Geoprocessor GP = new Geoprocessor();
            GP.OverwriteOutput = true;
            GP.LogHistory = true;
            GP.ClearMessages();
            try
            {
                GP.Execute(gpProcess, null);
            }
            catch (Exception)
            {
                object sev = null;
                MessageBox.Show(GP.GetMessages(ref sev));
            }
        }

        /// 
        /// 导出
        /// 
        /// 
        /// 
        private void export_Click(object sender, EventArgs e)
        {
            //初始化保存窗体
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Title = "输出要素类";
            saveFileDialog.Filter = "shape文件(*.shp)|*.shp";
            saveFileDialog.InitialDirectory = Configuration.Environment.WorkPath;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                exportText.Text = saveFileDialog.FileName.ToString();
            }  
        }

        

你可能感兴趣的:(ArcGIS,Engine,arcgis)