使用GP处理制图中出现的路水关系冲突(当现状道路与水系发生压盖时,图面上要做一定距离的偏移)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.esriSystem;

namespace Plot.DataExtract.TiaoHui
{
    public partial class frmRoadRiver : DevExpress.XtraEditors.XtraForm
    {
        private string strWsPath = @"C:\Users\KONE\Desktop\testDb.gdb";

        private string strJJXLayerName = "JJX";
        private string strXZDWLayerName = "HL";

        private string strIntersectOutputLayerName = "";
        private string strMsg = null;
        public frmRoadRiver()
        {
            InitializeComponent();
        }

        private void BtnStart_Click(object sender, EventArgs e)
        {
            try
            {
                strMsg = "开始进行路水冲突处理...";
                // Initialize the Geoprocessor 
                Geoprocessor GP = new Geoprocessor();
                GP.SetEnvironmentValue("workspace", strWsPath);
                GP.SetEnvironmentValue("referenceScale", 1000);


                ESRI.ArcGIS.CartographyTools.ResolveRoadConflicts resolveRoadConflicts = new ESRI.ArcGIS.CartographyTools.ResolveRoadConflicts();
                resolveRoadConflicts.in_layers = @"C:\Users\KONE\Desktop\JJX.lyr" + ";" + @"C:\Users\KONE\Desktop\JJX.lyr";
                resolveRoadConflicts.hierarchy_field = "level";
                resolveRoadConflicts.out_displacement_features = "exportFeaCls";

                string strGPMsg = null;
                IGeoProcessorResult tGeoResultIntersect = Execute(GP, resolveRoadConflicts, null, out strGPMsg);
                strMsg += strGPMsg;
                if (tGeoResultIntersect.Status != esriJobStatus.esriJobSucceeded)
                {
                    strMsg += "重叠要素提取失败!";
                }
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "提示");
            }
        }


        /// <summary>
        /// 执行GP
        /// </summary>
        /// <param name="mGP">GP对象</param>
        /// <param name="process">GP工具实例</param>
        /// <param name="TC"></param>
        /// <param name="strMessage">消息</param>
        /// <returns></returns>
        private static IGeoProcessorResult Execute(Geoprocessor mGP, IGPProcess process, ITrackCancel TC, out string strMessage)
        {
            IGeoProcessorResult tGeoResult = null;
            mGP.OverwriteOutput = true; // 是否覆盖
            try
            {
                tGeoResult = (IGeoProcessorResult)mGP.Execute(process, null);
                strMessage = ReturnMessages(mGP);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
                strMessage = ReturnMessages(mGP);
            }
            return tGeoResult;
        }

        /// <summary>
        /// 消息内容
        /// </summary>
        /// <param name="gp"></param>
        /// <returns></returns>
        private static string ReturnMessages(Geoprocessor gp)
        {
            string ms = "";
            if (gp.MessageCount > 0)
            {
                for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
                {
                    ms += "$" + gp.GetMessage(Count) + "\n";
                }
            }

            return ms;
        } 
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值