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;
}
}
}
使用GP处理制图中出现的路水关系冲突(当现状道路与水系发生压盖时,图面上要做一定距离的偏移)
最新推荐文章于 2021-01-29 18:09:37 发布