private void buttonClip_Click(object sender, EventArgs e)
{
DoWork();
}
private void DoWork()
{
string Unit= comboBoxUnit.SelectedItem.ToString();
Thread t = new Thread(new ParameterizedThreadStart(this.buttonCilp));
t.Start(Unit);
}
public void buttonCilp(object unit)
{
Clippath = textBoxInput1.Text.ToString();
ToleranceUNIT = textBoxTolerance.Text.ToString() + " " + unit;
for (int i = 1; i <= listBox1.Items.Count; i++)
{
inputpath = listBox1.Items[i-1].ToString();
if (listBox1.Items.Count <= 1)
{
outputpath = textBoxOutput.Text.ToString();
}
else
{
int index = inputpath.LastIndexOf("\\");
string str = inputpath.Substring(index);
str = str.Substring(1);
string[] temp = str.Split('.');
outputpath = textBoxOutput.Text.ToString() + "\\" + temp[0].ToString()+ "_cilp.shp";
}
Thread mythread = new Thread(() => Clip(inputpath, Clippath, outputpath, ToleranceUNIT));
mythread.IsBackground = true;
mythread.Start();
}
}
public void Clip(string pInputpath,string pClippath, string pOutputpath, string pToleranceUNIT)
{
System.Diagnostics.Stopwatch stopwatch = Stopwatch.StartNew();
#region
pActiveView = m_Map.ActiveView;
pMap = m_Map.Map;
Geoprocessor gp = new Geoprocessor(); //初始化Geoprocessor
gp.OverwriteOutput = true; //允许运算结果覆盖现有文件
ESRI.ArcGIS.AnalysisTools.Clip pClip = new ESRI.ArcGIS.AnalysisTools.Clip(); //定义Clip工具
pClip.in_features = pInputpath; //输入对象,既可是IFeatureLayer对象,也可是完整文件路
pClip.clip_features = Clippath; //裁剪要素
pClip.out_feature_class = pOutputpath; //输出对象,一般是包含输出文件名的完整文件路径
pClip.cluster_tolerance = pToleranceUNIT; ;
//gp.Execute(pClip, null);
IGeoProcessorResult results = null;
int index = inputpath.LastIndexOf("\\");
string str = inputpath.Substring(index);
str = str.Substring(1);
string[] temp = str.Split('.');
try
{
results = (IGeoProcessorResult)gp.Execute(pClip, null);
if (results!=null && results.Status == esriJobStatus.esriJobSucceeded)
{
//将生成图层加入MapControl
int index1 = pOutputpath.LastIndexOf("\\");
m_Map.AddShapeFile(pOutputpath.Substring(0, index1), pOutputpath.Substring(index1));
toolStripStatusLabel1.Text = "图层 " + temp[0].ToString() + " 裁剪成功 ";
}
else
{
toolStripStatusLabel1.Text = "图层 " + temp[0].ToString() + " 裁剪失败 ";
}
}
catch (Exception ex)
{
toolStripStatusLabel1.Text = "图层 " + temp[0].ToString() + " 裁剪失败 " + ex.Message.ToString();
}
#endregion
Thread.Sleep(5);
stopwatch.Stop();
}
{
DoWork();
}
private void DoWork()
{
string Unit= comboBoxUnit.SelectedItem.ToString();
Thread t = new Thread(new ParameterizedThreadStart(this.buttonCilp));
t.Start(Unit);
}
public void buttonCilp(object unit)
{
Clippath = textBoxInput1.Text.ToString();
ToleranceUNIT = textBoxTolerance.Text.ToString() + " " + unit;
for (int i = 1; i <= listBox1.Items.Count; i++)
{
inputpath = listBox1.Items[i-1].ToString();
if (listBox1.Items.Count <= 1)
{
outputpath = textBoxOutput.Text.ToString();
}
else
{
int index = inputpath.LastIndexOf("\\");
string str = inputpath.Substring(index);
str = str.Substring(1);
string[] temp = str.Split('.');
outputpath = textBoxOutput.Text.ToString() + "\\" + temp[0].ToString()+ "_cilp.shp";
}
Thread mythread = new Thread(() => Clip(inputpath, Clippath, outputpath, ToleranceUNIT));
mythread.IsBackground = true;
mythread.Start();
}
}
public void Clip(string pInputpath,string pClippath, string pOutputpath, string pToleranceUNIT)
{
System.Diagnostics.Stopwatch stopwatch = Stopwatch.StartNew();
#region
pActiveView = m_Map.ActiveView;
pMap = m_Map.Map;
Geoprocessor gp = new Geoprocessor(); //初始化Geoprocessor
gp.OverwriteOutput = true; //允许运算结果覆盖现有文件
ESRI.ArcGIS.AnalysisTools.Clip pClip = new ESRI.ArcGIS.AnalysisTools.Clip(); //定义Clip工具
pClip.in_features = pInputpath; //输入对象,既可是IFeatureLayer对象,也可是完整文件路
pClip.clip_features = Clippath; //裁剪要素
pClip.out_feature_class = pOutputpath; //输出对象,一般是包含输出文件名的完整文件路径
pClip.cluster_tolerance = pToleranceUNIT; ;
//gp.Execute(pClip, null);
IGeoProcessorResult results = null;
int index = inputpath.LastIndexOf("\\");
string str = inputpath.Substring(index);
str = str.Substring(1);
string[] temp = str.Split('.');
try
{
results = (IGeoProcessorResult)gp.Execute(pClip, null);
if (results!=null && results.Status == esriJobStatus.esriJobSucceeded)
{
//将生成图层加入MapControl
int index1 = pOutputpath.LastIndexOf("\\");
m_Map.AddShapeFile(pOutputpath.Substring(0, index1), pOutputpath.Substring(index1));
toolStripStatusLabel1.Text = "图层 " + temp[0].ToString() + " 裁剪成功 ";
}
else
{
toolStripStatusLabel1.Text = "图层 " + temp[0].ToString() + " 裁剪失败 ";
}
}
catch (Exception ex)
{
toolStripStatusLabel1.Text = "图层 " + temp[0].ToString() + " 裁剪失败 " + ex.Message.ToString();
}
#endregion
Thread.Sleep(5);
stopwatch.Stop();
}