예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.OverwriteOutput = true;
            double bufferDistance = 0.0;

            bufferDistance = Convert.ToDouble(textBox1.Text);
            ILayer pLayer = new FeatureLayerClass();

            for (int i = 0; i < global.pMap.LayerCount - 1; i++)
            {
                if (global.pMap.Layer[i].Name == comboBox2.Text)
                {
                    pLayer = global.pMap.Layer[i];
                }
            }

            bufferfilesave = false;
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pLayer, textBox2.Text, textBox2.Text.Trim() + " " + (comboBox2.SelectedItem));
            buffer.dissolve_option = "ALL";   //这个要设成ALL,否则相交部分不会融合
            buffer.line_side       = "FULL";  //默认是"FULL",最好不要改否则出错
            buffer.line_end_type   = "ROUND"; //默认是"ROUND",最好不要改否则出错
            ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult results = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)(gp.Execute(buffer, null));

            if ((int)results.Status != 4)
            {
                MessageBox.Show("缓冲区分析失败!");
            }
            else
            {
                MessageBox.Show("缓冲区分析成功!"); bufferfilesave = true;
            }
            bufferShpPath = textBox2.Text;
        }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string text;

            text = textBox1.Text;


            Geoprocessor GP = new Geoprocessor();

            GP.OverwriteOutput = true;
            ESRI.ArcGIS.AnalysisTools.Buffer pBuffer = new ESRI.ArcGIS.AnalysisTools.Buffer();

            ILayer        pLayer    = aMap.get_Layer(0);
            IFeatureLayer featLayer = pLayer as IFeatureLayer;

            pBuffer.in_features = featLayer;
            string filepath = @"c:\temp";

            pBuffer.out_feature_class = filepath + "\\" + pLayer.Name + ".shp";

            pBuffer.buffer_distance_or_field = text;
            pBuffer.dissolve_option          = "ALL";

            GP.Execute(pBuffer, null);

            aMap.AddShapeFile(filepath, pLayer.Name);

            aMap.MoveLayerTo(1, 0);
        }
예제 #3
0
        public void ReturnBufferFeatureClass(IFeatureLayer pInputlayer, string pOutputPath, double bufferDistance, string units)
        {
            //判断缓冲区距离
            if (bufferDistance == 0.0)
            {
                MessageBox.Show("缓冲区距离无效!");
                //return null;
            }

            //get an instance of the geoprocessor
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pInputlayer, pOutputPath, Convert.ToString(bufferDistance) + " " + units);
            //buffer.dissolve_option = "ALL";//这个要设成ALL,否则相交部分不会融合
            buffer.dissolve_option = "NONE";//这个要设成ALL,否则相交部分不会融合
            //buffer.line_side = "FULL";//默认是"FULL",最好不要改否则出错
            //buffer.line_end_type = "ROUND";//默认是"ROUND",最好不要改否则出错
            try
            {
                //results = (IGeoProcessorResult)gp.Execute(buffer, null);
                gp.Execute(buffer, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #4
0
        private IGeoProcessorResult CreateBuffer(Geoprocessor gp)
        {
            txtMessages.Text += "Creating Buffer: " + "\r\n";
            txtMessages.Update();
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            IFeatureLayer bufferLayer = GetFeatureLayer(strBufferLayer);

            buffer.in_features       = bufferLayer;
            bufferedFeatureClassName = strBufferLayer + "_" + "Buffer";
            string outputFullPath = System.IO.Path.Combine(strOutputPath, bufferedFeatureClassName);

            buffer.out_feature_class        = outputFullPath;
            buffer.buffer_distance_or_field = bufferDistanceField;
            buffer.line_side       = strSideType;
            buffer.line_end_type   = strEndType;
            buffer.dissolve_option = strDissolveType;
            buffer.dissolve_field  = strDissolveFields;
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);

            buffer            = null;
            txtMessages.Text += ReturnMessages(gp);
            txtMessages.Text += "Buffer Created! " + "\r\n";
            ScrollToBottom(txtMessages);
            txtMessages.Update();
            return(results);
        }
예제 #5
0
        private IGeoProcessorResult CreateBuffer(Geoprocessor gp)
        {
            strBufferLayer = cboBufferLayer.Text;
            //Buffer_analysis (in_features, out_feature_class, buffer_distance_or_field, line_side, line_end_type, dissolve_option, dissolve_field)
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            IFeatureLayer bufferLayer = GetFeatureLayer(strBufferLayer);

            buffer.in_features = bufferLayer;


            string outputFullPath = System.IO.Path.Combine(strOutputPath, textBox1.Text);

            buffer.out_feature_class        = outputFullPath;
            buffer.buffer_distance_or_field = bufferDistanceField + " " + (string)comboBox1.SelectedItem;

            buffer.line_side       = strSideType;
            buffer.line_end_type   = strEndType;
            buffer.dissolve_option = strDissolveType;
            buffer.dissolve_field  = strDissolveFields;

            IGeoProcessorResult results          = (IGeoProcessorResult)gp.Execute(buffer, null);
            IFeatureLayer       pOutputFeatLayer = new FeatureLayerClass();

            outputFeatureName = textBox1.Text;


            FileInfo info = new FileInfo(outputFeatureName);
            string   path = outputFeatureName.Substring(0, outputFeatureName.Length - info.Name.Length);

            axMapControl1.AddShapeFile(path, info.Name);
            axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);

            return(results);
        }
        /// <summary>
        /// Handles the click event of the Button and starts asynchronous geoprocessing.
        /// </summary>
        private void btnRunGP_Click(object sender, EventArgs e)
        {
            try
            {
                #region tidy up any previous gp runs

                //Clear the ListView control
                listView1.Items.Clear();

                //Remove any result layers present in the map
                IMapLayers mapLayers = axMapControl1.Map as IMapLayers;
                foreach (IFeatureLayer resultLayer in _resultsList)
                {
                    mapLayers.DeleteLayer(resultLayer);
                }

                axTOCControl1.Update();

                //Empty the results layer list
                _resultsList.Clear();

                //make sure that my GP tool queue is empty
                _myGPToolsToExecute.Clear();

                #endregion

                //Buffer the selected cities by the specified distance
                ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();
                bufferTool.in_features = _layersDict["Cities"];
                bufferTool.buffer_distance_or_field = txtBufferDistance.Text + " Miles";
                bufferTool.out_feature_class        = "city_buffer.shp";

                //Clip the zip codes layer with the result of the buffer tool
                ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();
                clipTool.in_features       = _layersDict["ZipCodes"];
                clipTool.clip_features     = bufferTool.out_feature_class;
                clipTool.out_feature_class = "city_buffer_clip.shp";

                //To run multiple GP tools asynchronously, all tool inputs must exist before ExecuteAsync is called.
                //The output from the first buffer operation is used as an input to the second clip
                //operation. To deal with this restriction a Queue is created and all tools added to it. The first tool
                //is executed from this method, whereas the second is executed from the ToolExecuted event. This approach
                //is scalable - any additional geoprocessing tools added to this queue will also be executed in turn.
                _myGPToolsToExecute.Enqueue(bufferTool);
                _myGPToolsToExecute.Enqueue(clipTool);
                _gp.ExecuteAsync(_myGPToolsToExecute.Dequeue());
            }
            catch (Exception ex)
            {
                listView1.Items.Add(new ListViewItem(new string[2] {
                    "N/A", ex.Message
                }, "error"));
            }
        }
예제 #7
0
        //开始分析
        private void btnBufferStart_Click(object sender, EventArgs e)
        {
            //缓冲距离
            double bufferDistance;

            //输入的缓冲距离转换为double
            double.TryParse(txtBufferDistance.Text.ToString(), out bufferDistance);

            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputLayer.Text)) ||
                System.IO.Path.GetExtension(txtOutputLayer.Text) != ".shp")
            {
                MessageBox.Show("输出路径错误!");
                return;
            }

            //判断图层个数
            if (mHookHelper.FocusMap.LayerCount == 0)
            {
                return;
            }
            //获取图层
            IFeatureLayer pFeatureLayer = GetFeatureLayer((string)cmbLayerName.SelectedItem);

            if (null == pFeatureLayer)
            {
                MessageBox.Show("图层" + (string)cmbLayerName.SelectedItem + "不存在!\r\n");
                return;
            }

            //获取一个geoprocessor的实例
            Geoprocessor gp = new Geoprocessor();

            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;
            //缓冲区保存路径
            strOutputPath = txtOutputLayer.Text;
            //创建一个Buffer工具的实例
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pFeatureLayer, strOutputPath, bufferDistance.ToString());
            //执行缓冲区分析
            IGeoProcessorResult results = null;

            results = (IGeoProcessorResult)gp.Execute(buffer, null);
            //判断缓冲区是否成功生成
            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                MessageBox.Show("图层" + pFeatureLayer.Name + "缓冲区生成失败!");
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("缓冲区生成成功!");
            }
        }
예제 #8
0
        /// <summary>
        /// Generate buffer area for input shapefile
        /// </summary>
        /// <param name="inputFilePath"></param>
        /// <param name="bufferDistance"></param>
        /// <param name="outputFilePath"></param>
        void Buffer(string inputFilePath, double bufferDistance, string outputFilePath)
        {
            Geoprocessor geoprocessor = new Geoprocessor();

            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            buffer.in_features              = inputFilePath;
            buffer.out_feature_class        = outputFilePath;
            buffer.buffer_distance_or_field = bufferDistance;
            geoprocessor.Execute(buffer, null);

            outputCallback(inputFilePath, outputFilePath);
        }
예제 #9
0
 void IBuffer.BufferInsideSde(string in_features, string out_feature, object distance)
 {
     Geoprocessor gp = new Geoprocessor();
     ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();
     //_environment = "Database Connections/Connection to HT-LAPTOP.sde";
     //MessageBox.Show("TnBuffer-line:85--environment: " + _environment);
     gp.SetEnvironmentValue("workspace", _environment);
     bufferTool.in_features = in_features;
     bufferTool.out_feature_class = out_feature;
     bufferTool.buffer_distance_or_field = distance;
     runTool(gp, bufferTool, null);
 }
예제 #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            path     = textBox1.Text;
            distance = textBox2.Text + " " + comboBox2.Text;

            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;

            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(featureLaer, path, distance);
            Console.WriteLine(buffer);
            try
            {
                gp.Execute(buffer, null);
                MessageBox.Show("缓冲区建立成功");
            }
            catch
            {
                MessageBox.Show("缓冲区建立失败!");
            }
        }
예제 #11
0
 public static void WBuffer(IFeature Feature)
 {
     Geoprocessor gp = new Geoprocessor();
     ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(Feature, @"F:\Github\Traffic\LoowooTech.Traffic\LoowooTech.Traffic\bin\Debug\Temp\output.shp", "1 Kilometers");
     gp.Execute(buffer, null);
 }
    /// <summary>
    /// Handles the click event of the Button and starts asynchronous geoprocessing.
    /// </summary>
    private void btnRunGP_Click(object sender, EventArgs e)
    {
      try
      {
        #region tidy up any previous gp runs

        //Clear the ListView control
        listView1.Items.Clear();

        //Remove any result layers present in the map
        IMapLayers mapLayers = axMapControl1.Map as IMapLayers;
        foreach (IFeatureLayer resultLayer in _resultsList)
        {
          mapLayers.DeleteLayer(resultLayer);
        }

        axTOCControl1.Update();
        
        //Empty the results layer list
        _resultsList.Clear();

        //make sure that my GP tool queue is empty
        _myGPToolsToExecute.Clear();

        #endregion

        //Buffer the selected cities by the specified distance
        ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();
        bufferTool.in_features = _layersDict["Cities"];
        bufferTool.buffer_distance_or_field = txtBufferDistance.Text + " Miles";
        bufferTool.out_feature_class = "city_buffer.shp";
       
        //Clip the zip codes layer with the result of the buffer tool
        ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();
        clipTool.in_features = _layersDict["ZipCodes"];
        clipTool.clip_features = bufferTool.out_feature_class;
        clipTool.out_feature_class = "city_buffer_clip.shp";

        //To run multiple GP tools asynchronously, all tool inputs must exist before ExecuteAsync is called.
        //The output from the first buffer operation is used as an input to the second clip
        //operation. To deal with this restriction a Queue is created and all tools added to it. The first tool
        //is executed from this method, whereas the second is executed from the ToolExecuted event. This approach
        //is scalable - any additional geoprocessing tools added to this queue will also be executed in turn.
        _myGPToolsToExecute.Enqueue(bufferTool);
        _myGPToolsToExecute.Enqueue(clipTool);
        _gp.ExecuteAsync(_myGPToolsToExecute.Dequeue());
      }
      catch (Exception ex)
      {
        listView1.Items.Add(new ListViewItem(new string[2] { "N/A", ex.Message }, "error")); 
      }
    }
예제 #13
0
        private void buttonX1Buffer_Click(object sender, EventArgs e)
        {
            //make sure that all parameters are okay
            double bufferDistance;

            //转换distance为double类型
            double.TryParse(textBoxX1.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("缓冲区距离无效!");
                return;
            }
            //判断输出路径是否合法
            try
            {
                if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(textBoxX2.Text)) || ".shp" != System.IO.Path.GetExtension(textBoxX2.Text))
                {
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("路径无效!");
            }
            //判断图层个数
            if (m_hookHelper.FocusMap.LayerCount == 0)
            {
                return;
            }

            //get the layer from the map
            IFeatureLayer pInputlayer = GetFeatureLayer((string)comboBoxEx1.SelectedItem);

            if (null == pInputlayer)
            {
                textBoxX3.Text += "找不到图层 " + (string)comboBoxEx1.SelectedItem + "!\r\n";
                return;
            }

            //scroll the textbox to the bottom
            ScrollToBottom();

            textBoxX3.Text += "\r\n缓冲区分析开始,请稍候..\r\n";
            textBoxX3.Update();



            //get an instance of the geoprocessor
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;


            //IDataset dataset1 = pInputlayer as IDataset;
            //IGeoDataset geoDataset = dataset1 as IGeoDataset;

            //ClsConvertUnit clsConvertUnit = new ClsConvertUnit();
            //double pTrandist = clsConvertUnit.GetBufferValueByUnit(geoDataset.SpatialReference, bufferDistance);

            object test = Convert.ToString(bufferDistance) + " " + (string)comboBoxEx2.SelectedItem;

            //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pInputlayer, textBoxX2.Text, Convert.ToString(bufferDistance) + " " + (string)comboBoxEx2.SelectedItem);
            ////ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pInputlayer, textBoxX2.Text, Convert.ToString(pTrandist) + " " + (string)comboBoxEx2.SelectedItem);

            //buffer.dissolve_option = "ALL";//这个要设成ALL,否则相交部分不会融合
            buffer.dissolve_option = "NONE";//这个要设成ALL,否则相交部分不会融合
            //buffer.line_side = "FULL";//默认是"FULL",最好不要改否则出错
            //buffer.line_end_type = "ROUND";//默认是"ROUND",最好不要改否则出错

            //execute the buffer tool (very easy :-))
            IGeoProcessorResult results = null;

            try
            {
                results = (IGeoProcessorResult)gp.Execute(buffer, null);
            }
            catch (Exception ex)
            {
                textBoxX3.Text += "缓冲区分析失败: " + pInputlayer.Name + "\r\n";
            }
            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                textBoxX3.Text += "缓冲区分析失败: " + pInputlayer.Name + "\r\n";
            }

            //scroll the textbox to the bottom
            ScrollToBottom();

            textBoxX3.Text += "\r\n分析完成.\r\n";
            textBoxX3.Text += "-----------------------------------------------------------------------------------------\r\n";
            //scroll the textbox to the bottom
            ScrollToBottom();
        }
        //开始分析
        private void btnBufferStart_Click(object sender, EventArgs e)
        {
            //缓冲距离
            double bufferDistance;
            //输入的缓冲距离转换为double
            double.TryParse(txtBufferDistance.Text.ToString(), out bufferDistance);

            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputLayer.Text)) ||
              System.IO.Path.GetExtension(txtOutputLayer.Text) != ".shp")
            {
                MessageBox.Show("输出路径错误!");
                return;
            }

            //判断图层个数
            if (mHookHelper.FocusMap.LayerCount == 0)
                return;
            //获取图层
            IFeatureLayer pFeatureLayer = GetFeatureLayer((string)cmbLayerName.SelectedItem);
            if (null == pFeatureLayer)
            {
                MessageBox.Show("图层" + (string)cmbLayerName.SelectedItem + "不存在!\r\n");
                return;
            }

            //获取一个geoprocessor的实例
            Geoprocessor gp = new Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;
            //缓冲区保存路径
            strOutputPath = txtOutputLayer.Text;
            //创建一个Buffer工具的实例
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pFeatureLayer, strOutputPath, bufferDistance.ToString());
            //执行缓冲区分析
            IGeoProcessorResult results = null;
            results = (IGeoProcessorResult)gp.Execute(buffer, null);
            //判断缓冲区是否成功生成
            if (results.Status != esriJobStatus.esriJobSucceeded)
                MessageBox.Show("图层" + pFeatureLayer.Name + "缓冲区生成失败!");
            else
            {
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("缓冲区生成成功!");
            }
        }
예제 #15
0
        private void gpProcess()
        {
            try
            {
                #region tidy up any previous gp runs

                //Clear the ListView control
                listView1.Items.Clear();

                //Remove any result layers present in the map
                IMapLayers mapLayers = axMapControl1.Map as IMapLayers;
                foreach (IFeatureLayer resultLayer in _resultsList)
                {
                    mapLayers.DeleteLayer(resultLayer);
                }

                axTOCControl1.Update();

                //Empty the results layer list
                _resultsList.Clear();

                //make sure that my GP tool queue is empty
                _myGPToolsToExecute.Clear();

                #endregion

                //Buffer the selected cities by the specified distance
                ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();
                bufferTool.in_features = _layersDict["Cities"];
                bufferTool.buffer_distance_or_field = txtBufferDistance.Text + " Miles";
                bufferTool.out_feature_class = "city_buffer.shp";

                //Clip the zip codes layer with the result of the buffer tool
                ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();
                clipTool.in_features = _layersDict["ZipCodes"];
                clipTool.clip_features = bufferTool.out_feature_class;
                clipTool.out_feature_class = "city_buffer_clip.shp";

                _myGPToolsToExecute.Enqueue(bufferTool);
                _myGPToolsToExecute.Enqueue(clipTool);

                _gp.ExecuteAsync(_myGPToolsToExecute.Dequeue());
            }
            catch (Exception ex)
            {
                listView1.Items.Add(new ListViewItem(new string[2] { "N/A", ex.Message }, "error"));
            }
        }
예제 #16
0
        private void outBuffer_Click(object sender, EventArgs e)
        {
            double bufferDistance;

            //转换distance为double类型
            double.TryParse(BufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("错误的距离!");
                return;
            }
            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(TxtOutPutPath.Text)) ||
                ".shp" != System.IO.Path.GetExtension(TxtOutPutPath.Text))
            {
                MessageBox.Show("错误的路径!");
                return;
            }
            //判断图层个数
            if (m_hookHelper.FocusMap.LayerCount == 0)
            {
                return;
            }

            //获取图层
            IFeatureLayer layer = GetFeatureLayer((string)chooseLayer.SelectedItem);

            if (null == layer)
            {
                txtMessage.Text += "图层 " + (string)chooseLayer.SelectedItem + "不能被建立!\r\n";
                return;
            }

            //将文本框滚动到底部
            ScrollToBottom();

            txtMessage.Text += "\r\n分析开始,这可能需要几分钟时间,请稍候..\r\n";
            txtMessage.Update();
            //get an instance of the geoprocessor
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            strOutPutPath      = TxtOutPutPath.Text;
            //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, TxtOutPutPath.Text, Convert.ToString(bufferDistance) + " " + (string)Units.SelectedItem);
            buffer.dissolve_option = "ALL"; //这个要设成ALL,否则相交部分不会融合
                                            //buffer.line_side = "FULL";//默认是"FULL",最好不要改否则出错
                                            //buffer.line_end_type = "ROUND";//默认是"ROUND",最好不要改否则出错

            //execute the buffer tool (very easy :-))
            IGeoProcessorResult results = null;

            try
            {
                results = (IGeoProcessorResult)gp.Execute(buffer, null);
            }
            catch (Exception ex)
            {
                txtMessage.Text += "图层: " + layer.Name + "缓冲区生成失败!" + "\r\n";
            }
            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                txtMessage.Text += "图层: " + layer.Name + "缓冲区生成失败!" + "\r\n";
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                txtMessage.Text  += "缓冲区生成成功!";
            }

            //scroll the textbox to the bottom
            ScrollToBottom();

            txtMessage.Text += "\r\n分析完成.\r\n";
            txtMessage.Text += "-----------------------------------------------------------------------------------------\r\n";
            //scroll the textbox to the bottom
            ScrollToBottom();
        }
예제 #17
0
        private void buttonAnalysis_Click(object sender, EventArgs e)
        {
            //修改当前指针样式
            this.Cursor = Cursors.WaitCursor;

            //make sure that all parameters are okay
            double bufferDistance;

            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("无效的缓冲距离!");
                return;
            }

            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
                ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("无效的文件名!");
                return;
            }

            if (m_hookHelper.FocusMap.LayerCount == 0)
            {
                return;
            }

            //get the layer from the map
            IFeatureLayer layer = GetFeatureLayer((string)cboLayers.SelectedItem);

            if (null == layer)
            {
                txtMessages.Text += "图层 " + (string)cboLayers.SelectedItem + "未被找到!\r\n";
                return;
            }

            //scroll the textbox to the bottom
            ScrollToBottom();
            //add message to the messages box
            txtMessages.Text += "进行缓冲区的图层: " + layer.Name + "\r\n";

            txtMessages.Text += "\r\n正在获取空间数据。这可能需要几秒钟时间...\r\n";
            txtMessages.Update();
            //get an instance of the geoprocessor
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            txtMessages.Text  += "正在进行缓冲区分析...\r\n";
            txtMessages.Update();

            //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, txtOutputPath.Text, Convert.ToString(bufferDistance) + " " + (string)cboUnits.SelectedItem);

            //execute the buffer tool (very easy :-))
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);

            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                txtMessages.Text += "缓冲区失败的图层: " + layer.Name + "\r\n";
            }
            txtMessages.Text += ReturnMessages(gp);
            //scroll the textbox to the bottom
            ScrollToBottom();

            txtMessages.Text += "\r\n完成!\r\n";
            txtMessages.Text += "------------------------------------------------------\r\n";
            //scroll the textbox to the bottom
            ScrollToBottom();

            //修改当前指针样式
            this.Cursor = Cursors.Default;
        }
예제 #18
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            //检验参数是否正确设置
            double bufferDistance;

            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("距离设置错误!");
                return;
            }

            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) || ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("输出格式错误!");
                return;
            }

            if (ComboBoxLayer.Items.Count <= 0)
            {
                return;
            }

            IFeatureLayer pFeatureLayer = (IFeatureLayer)GetLayerByName(ComboBoxLayer.SelectedItem.ToString());

            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = true;

            string unit = "Kilometers";

            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pFeatureLayer, txtOutputPath.Text, Convert.ToString(bufferDistance) + " " + unit);
            IGeoProcessorResult results             = (IGeoProcessorResult)gp.Execute(buffer, null);

            //添加缓冲区图层到当前地图中
            string fileDirectory = txtOutputPath.Text.ToString().Substring(0, txtOutputPath.Text.LastIndexOf("\\"));
            int    j;

            j = txtOutputPath.Text.LastIndexOf("\\");
            string            tmpstr            = txtOutputPath.Text.ToString().Substring(j + 1);
            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory() as IWorkspaceFactory;
            IWorkspace        pWS = pWorkspaceFactory.OpenFromFile(fileDirectory, 0);
            IFeatureWorkspace pFS = pWS as IFeatureWorkspace;
            //IFeatureClass pfc = pFS.OpenFeatureClass(this.ComboBoxLayer.SelectedText+ "_buffer.shp");
            IFeatureClass pfc = pFS.OpenFeatureClass(tmpstr);
            IFeatureLayer pfl = new FeatureLayer() as IFeatureLayer;

            pfl.FeatureClass = pfc;
            pfl.Name         = pfc.AliasName;

            IRgbColor pColor = new RgbColor() as IRgbColor;

            pColor.Red          = 255;
            pColor.Green        = 0;
            pColor.Blue         = 0;
            pColor.Transparency = 255;
            //产生一个线符号对象
            ILineSymbol pOutline = new SimpleLineSymbol();

            pOutline.Width = 2;
            pOutline.Color = pColor;
            //设置颜色属性
            pColor              = new RgbColor();
            pColor.Red          = 255;
            pColor.Green        = 0;
            pColor.Blue         = 0;
            pColor.Transparency = 100;
            //设置填充符号的属性
            ISimpleFillSymbol pFillSymbol = new SimpleFillSymbol();

            pFillSymbol.Color   = pColor;
            pFillSymbol.Outline = pOutline;
            pFillSymbol.Style   = esriSimpleFillStyle.esriSFSSolid;

            ISimpleRenderer  pRen;
            IGeoFeatureLayer pGeoFeatLyr = pfl as IGeoFeatureLayer;

            pRen                 = pGeoFeatLyr.Renderer as ISimpleRenderer;
            pRen.Symbol          = pFillSymbol as ISymbol;
            pGeoFeatLyr.Renderer = pRen as IFeatureRenderer;

            ILayerEffects pLayerEffects = pfl as ILayerEffects;

            pLayerEffects.Transparency = 150;

            Form1.m_mapControl.AddLayer((ILayer)pfl, 0);
            MessageBox.Show(ComboBoxLayer.SelectedText + "缓存生成成功!");
        }
예제 #19
0
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            //缓冲距离
            double bufferDistance;

            //输入的缓冲距离转换为double
            double.TryParse(txtBufferDistance.Text.ToString(), out bufferDistance);

            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
                ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("输出路径错误!");
                return;
            }

            //判断图层个数
            if (mHookHelper.FocusMap.LayerCount == 0)
            {
                return;
            }
            //获取图层
            IFeatureLayer pFeatureLayer = GetFeatureLayer((string)cboLayers.SelectedItem);

            if (null == pFeatureLayer)
            {
                MessageBox.Show("图层" + (string)cboLayers.SelectedItem + "不存在!\r\n");
                return;
            }

            //MessageBox.Show("正在规划绿化带……");
            //获取一个geoprocessor的实例
            Geoprocessor gp = new Geoprocessor();

            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;
            //缓冲区保存路径
            strOutputPath = txtOutputPath.Text;
            //创建一个Buffer工具的实例
            string distance = this.txtBufferDistance.Text.ToString();
            //ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pFeatureLayer, strOutputPath, bufferDistance.ToString());
            string para = distance + " Meters";

            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            buffer.in_features              = pFeatureLayer;
            buffer.out_feature_class        = strOutputPath;
            buffer.buffer_distance_or_field = para;
            buffer.dissolve_option          = "ALL";

            //执行缓冲区分析
            IGeoProcessorResult results = null;

            results = (IGeoProcessorResult)gp.Execute(buffer, null);
            //判断缓冲区是否成功生成
            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                MessageBox.Show("图层" + pFeatureLayer.Name + "绿化带生成失败!");
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("绿化带生成成功!");
            }
        }
예제 #20
0
        private void BufferByDistance()
        {
            string pBufferDistanceOrField = null;
            string pBufferUnits           = cbx_GlobalUnit.SelectedItem.ToString();
            string pDissovle = null;

            //if (0.0 == pBufferDistanceOrField)
            //{
            //    MessageBox.Show("Bad buffer distance!");
            //    return;
            //}
            if (m_MapControl.ActiveView.FocusMap.LayerCount == 0)
            {
                return;
            }

            if (null == m_FeatureLayer)
            {
                return;
            }
            if (rdb_Field.Checked == true)
            {
                pBufferDistanceOrField = cbx_Field.SelectedItem.ToString();
            }
            else if (rdb_Distance.Checked == true)
            {
                pBufferDistanceOrField = nmUD_Distance.Value.ToString() + " " + pBufferUnits;;
            }

            if (rdb_DissovleFalse.Checked == true)
            {
                pDissovle = "NONE";
            }
            else if (rdb_DissolveTrue.Checked == true)
            {
                pDissovle = "ALL";
            }


            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;

            //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            buffer.in_features              = m_FeatureLayer;
            buffer.out_feature_class        = m_OutPutShpPath;
            buffer.buffer_distance_or_field = pBufferDistanceOrField;
            buffer.dissolve_option          = pDissovle;


            //execute the buffer tool (very easy :-))
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);



            //if (results.Status != esriJobStatus.esriJobSucceeded)
            //{
            //    MessageBox.Show("Failed to buffer layer: ");
            //}
        }
예제 #21
0
        private void Buffer(string unit)
        {
            //修改当前指针样式
            Cursor = Cursors.WaitCursor;



            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(outputPath.Text)) ||
                ".shp" != System.IO.Path.GetExtension(outputPath.Text))
            {
                MessageBox.Show("无效的文件名!");
                return;
            }

            if (_hookHelper.FocusMap.LayerCount == 0)
            {
                return;
            }

            //get the layer from the map
            IFeatureLayer layer = GetFeatureLayer((string)inputComBox.SelectedItem);

            if (null == layer)
            {
                txtMessages.Text += "图层 " + (string)inputComBox.SelectedItem + "未被找到!\r\n";
                return;
            }

            //scroll the textbox to the bottom
            ScrollToBottom();
            //add message to the messages box
            txtMessages.Text += "进行缓冲区的图层: " + layer.Name + "\r\n";

            txtMessages.Text += "\r\n正在获取空间数据。这可能需要几秒钟时间...\r\n";
            txtMessages.Update();

            //get an instance of the geoprocessor
            Geoprocessor gp = new Geoprocessor {
                OverwriteOutput = true
            };

            txtMessages.Text += "正在进行缓冲区分析...\r\n";
            txtMessages.Update();



            //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(
                layer, outputPath.Text, unit
                );

            //execute the buffer tool (very easy :-))
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);


            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                txtMessages.Text += "缓冲区失败的图层: " + layer.Name + "\r\n";
            }

            txtMessages.Text += ReturnMessages(gp);
            //scroll the textbox to the bottom
            ScrollToBottom();

            txtMessages.Text += "\r\n完成!\r\n";
            txtMessages.Text += "------------------------------------------------------\r\n";
            //scroll the textbox to the bottom
            ScrollToBottom();

            //修改当前指针样式
            this.Cursor = Cursors.Default;
        }
예제 #22
0
        public string Buffer(string inLayerName, string distString, string outLayerName = "")
        {
            ILayer inLayer = this._getLayerByName(inLayerName);
            if (inLayer == null)
            {
                return "";
            }

            string tempDir = System.IO.Path.GetTempPath();
            string outLayerFile = "";
            if (outLayerName == "")
            {
                outLayerFile = System.IO.Path.Combine(tempDir, inLayerName + "_buffer.shp");
            }
            else
            {
                outLayerFile = System.IO.Path.Combine(tempDir, outLayerName + ".shp");
            }

            //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(inLayer, outLayerFile, distString);

            //execute the buffer tool
            IGeoProcessorResult results = (IGeoProcessorResult)this._geoProcessor.Execute(buffer, null);
            if (results.Status == esriJobStatus.esriJobSucceeded)
            {
                return outLayerFile;
            }

            return "";
        }