AE+C# GP批量裁剪

本文介绍了一个基于ArcGIS的多线程裁剪工具实现方案,通过按钮触发事件,选择不同的单位进行批量裁剪操作。该工具能够处理多个输入文件,并支持输出文件的自定义命名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();
        }
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值