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.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.AnalysisTools;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using System.Threading;
using System.Diagnostics;
namespace 空间分析
{
public partial class UnionForm : Form
{
AxMapControl m_Map;
IMap pMap;
IActiveView pActiveView;
int index;//图层索引
string inputpath, outputpath, ToleranceUNIT;//输入输出路径,容差
public UnionForm(AxMapControl mmap)
{
InitializeComponent();
m_Map = mmap;
}
private void buttonInput_Click(object sender, EventArgs e)
{
OpenFileDialog FileOpen = new OpenFileDialog();
FileOpen.Filter = "shp文件(*.shp)|*.shp";
FileOpen.Title = "打开shp文件";
//FileOpen.Multiselect = true;
if (FileOpen.ShowDialog() == DialogResult.OK)
{
textBoxInput.Text = FileOpen.FileName;
}
if (!this.listBox1.Items.Contains(textBoxInput.Text.ToString()))
{
listBox1.Items.Add(textBoxInput.Text.ToString());
}
}
private void buttonOutput_Click(object sender, EventArgs e)
{
SaveFileDialog SaveFile = new SaveFileDialog();
SaveFile.Filter = "shp文件(*.shp)|*.shp";
SaveFile.Title = "保存shp文件";
if (SaveFile.ShowDialog() == DialogResult.OK)
{
textBoxOutput.Text = SaveFile.FileName;
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
private void buttonNO_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void buttonOK_Click(object sender, EventArgs e)
{
outputpath = textBoxOutput.Text.ToString();
ToleranceUNIT = textBoxTolerance.Text.ToString() + " " + comboBoxUnit.SelectedItem.ToString();
for (int i = 1; i < listBox1.Items.Count; i++)
{
inputpath += this.listBox1.Items[i].ToString() + " #;";
}
Union(inputpath, outputpath, ToleranceUNIT);
MessageBox.Show("合并成功!");
//将生成图层加入MapControl
int index = outputpath.LastIndexOf("\\");
m_Map.AddShapeFile(outputpath.Substring(0, index), outputpath.Substring(index));
}
public void Union(string pinputpath, string poutputpath, string ToleranceUNIT)
{
txtMessages.Text += "\r\n开始合并,请稍候..\r\n";
pActiveView = m_Map.ActiveView;
pMap = m_Map.Map;
Geoprocessor gp = new Geoprocessor(); //初始化Geoprocessor
gp.OverwriteOutput = true; //允许运算结果覆盖现有文件
ESRI.ArcGIS.AnalysisTools. pUnion = new ESRI.ArcGIS.AnalysisTools.Union(); //定义Union工具
pUnion.in_features = pinputpath; //输入对象,既可是IFeatureLayer对象,也可是完整文件路
pUnion.out_feature_class = outputpath; //输出对象,一般是包含输出文件名的完整文件路径
pUnion.cluster_tolerance = ToleranceUNIT;
pUnion.join_attributes = "all";
gp.Execute(pUnion, null);
IGeoProcessorResult results = null;
try
{
results = gp.Execute(pUnion, null) as IGeoProcessorResult;
if (results.Status != esriJobStatus.esriJobSucceeded)
{
txtMessages.Text += "\r\n....................................................\r\n";
txtMessages.Text += "\r\n......................合并成功......................\r\n";
txtMessages.Text += "\r\n....................................................\r\n";
}
else
{
txtMessages.Text += "\r\n....................................................\r\n";
txtMessages.Text += "\r\n......................合并成功......................\r\n";
txtMessages.Text += "\r\n....................................................\r\n";
}
}
catch (Exception ex)
{
txtMessages.Text += "\r\n...................合并出现异常.....................\r\n";
txtMessages.Text += ex.Message.ToString();
txtMessages.Text += "\r\n....................................................\r\n";
}
}
}
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.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.AnalysisTools;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using System.Threading;
using System.Diagnostics;
namespace 空间分析
{
public partial class UnionForm : Form
{
AxMapControl m_Map;
IMap pMap;
IActiveView pActiveView;
int index;//图层索引
string inputpath, outputpath, ToleranceUNIT;//输入输出路径,容差
public UnionForm(AxMapControl mmap)
{
InitializeComponent();
m_Map = mmap;
}
private void buttonInput_Click(object sender, EventArgs e)
{
OpenFileDialog FileOpen = new OpenFileDialog();
FileOpen.Filter = "shp文件(*.shp)|*.shp";
FileOpen.Title = "打开shp文件";
//FileOpen.Multiselect = true;
if (FileOpen.ShowDialog() == DialogResult.OK)
{
textBoxInput.Text = FileOpen.FileName;
}
if (!this.listBox1.Items.Contains(textBoxInput.Text.ToString()))
{
listBox1.Items.Add(textBoxInput.Text.ToString());
}
}
private void buttonOutput_Click(object sender, EventArgs e)
{
SaveFileDialog SaveFile = new SaveFileDialog();
SaveFile.Filter = "shp文件(*.shp)|*.shp";
SaveFile.Title = "保存shp文件";
if (SaveFile.ShowDialog() == DialogResult.OK)
{
textBoxOutput.Text = SaveFile.FileName;
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
private void buttonNO_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void buttonOK_Click(object sender, EventArgs e)
{
outputpath = textBoxOutput.Text.ToString();
ToleranceUNIT = textBoxTolerance.Text.ToString() + " " + comboBoxUnit.SelectedItem.ToString();
for (int i = 1; i < listBox1.Items.Count; i++)
{
inputpath += this.listBox1.Items[i].ToString() + " #;";
}
Union(inputpath, outputpath, ToleranceUNIT);
MessageBox.Show("合并成功!");
//将生成图层加入MapControl
int index = outputpath.LastIndexOf("\\");
m_Map.AddShapeFile(outputpath.Substring(0, index), outputpath.Substring(index));
}
public void Union(string pinputpath, string poutputpath, string ToleranceUNIT)
{
txtMessages.Text += "\r\n开始合并,请稍候..\r\n";
pActiveView = m_Map.ActiveView;
pMap = m_Map.Map;
Geoprocessor gp = new Geoprocessor(); //初始化Geoprocessor
gp.OverwriteOutput = true; //允许运算结果覆盖现有文件
ESRI.ArcGIS.AnalysisTools. pUnion = new ESRI.ArcGIS.AnalysisTools.Union(); //定义Union工具
pUnion.in_features = pinputpath; //输入对象,既可是IFeatureLayer对象,也可是完整文件路
pUnion.out_feature_class = outputpath; //输出对象,一般是包含输出文件名的完整文件路径
pUnion.cluster_tolerance = ToleranceUNIT;
pUnion.join_attributes = "all";
gp.Execute(pUnion, null);
IGeoProcessorResult results = null;
try
{
results = gp.Execute(pUnion, null) as IGeoProcessorResult;
if (results.Status != esriJobStatus.esriJobSucceeded)
{
txtMessages.Text += "\r\n....................................................\r\n";
txtMessages.Text += "\r\n......................合并成功......................\r\n";
txtMessages.Text += "\r\n....................................................\r\n";
}
else
{
txtMessages.Text += "\r\n....................................................\r\n";
txtMessages.Text += "\r\n......................合并成功......................\r\n";
txtMessages.Text += "\r\n....................................................\r\n";
}
}
catch (Exception ex)
{
txtMessages.Text += "\r\n...................合并出现异常.....................\r\n";
txtMessages.Text += ex.Message.ToString();
txtMessages.Text += "\r\n....................................................\r\n";
}
}
}
}