Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定生成消防站有效覆盖区域吗?可能需要花费较长时间,生成时请勿操作计算机!", "提示", MessageBoxButtons.YesNo);

            if (result != DialogResult.Yes)
            {
                return;
            }
            this.Cursor = Cursors.WaitCursor;

            try
            {
                double a = double.Parse(textBox1.Text);
                double b = double.Parse(textBox2.Text);
                if (a <= 0 || a > 999 || b <= 0 || b > 999)
                {
                    MessageBox.Show("请填入符合实际情况的数值!");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("请填入符合实际情况的数值!");
                return;
            }



            //缓冲区分析,GP工具调用
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;  //新生成的文件可以覆盖旧生成的文件
            ESRI.ArcGIS.AnalysisTools.Buffer pBuffer = new ESRI.ArcGIS.AnalysisTools.Buffer();

            //设置获取缓冲区分析图层
            ILayer        pLayer       = this.mainMapControl.get_Layer(0);
            IFeatureLayer featureLayer = (IFeatureLayer)pLayer;

            pBuffer.in_features = featureLayer;
            string filePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"太原GIS模型构建(分析版)";

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

            //计算可达距离
            double longer  = double.Parse(textBox1.Text) * 1000 / 60 * double.Parse(textBox2.Text);
            int    longer2 = (int)longer;

            //设置缓冲区距离
            pBuffer.buffer_distance_or_field = longer2.ToString() + " Meters";
            pBuffer.dissolve_option          = "ALL";

            //执行缓冲区分析
            gp.Execute(pBuffer, null);

            //将生成结果添加到地图中
            this.mainMapControl.AddShapeFile(filePath, pLayer.Name + ".shp");
            this.mainMapControl.MoveLayerTo(1, 0);
            this.mainMapControl.MoveLayerTo(1, 7);
            this.Cursor = Cursors.Default;
        }
Example #2
0
        private void managedToolToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Create the geoprocessor.
            Geoprocessor GP = new Geoprocessor();

            GP.OverwriteOutput = true;
            // Create the tool process object.
            ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new
                                                          ESRI.ArcGIS.AnalysisTools.Buffer();

            // Set parameter values.
            bufferTool.in_features              = FileGDBPath + "\\LotIds";
            bufferTool.out_feature_class        = FileGDBPath + "\\LotIds_BufferSystem";
            bufferTool.buffer_distance_or_field = "100 Feet";

            object sev = null;

            try
            {
                // Execute the tool.
                GP.Execute(bufferTool, null);

                Console.WriteLine(GP.GetMessages(ref sev));
            }
            catch (Exception ex)
            {
                // Print geoprocessing execution error messages.
                Console.WriteLine(GP.GetMessages(ref sev));
            }
        }
Example #3
0
        public static void BufferAnalysis(IFeatureLayer layer, string path, double radius, string radius_unit)
        {
            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(layer, path, Convert.ToString(radius) + " " + radius_unit);

                                                          //ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, this.OutputPath, "100"+" "+"Meters" );
                                                          //以下这些设置,那么选择要素呢??。。
                        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);
                                    MessageBox.Show("缓冲区建立成功!");

                               
                }
                        catch (Exception ex)
                            {
                                    MessageBox.Show("缓冲区建立失败!");

                                   // txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
                               
                }
        }
        private void btn_Confirm_Click(object sender, RoutedEventArgs e)
        {
            Mouse.SetCursor(Cursors.Wait);

            double bufferDistance;

            double.TryParse(txb_BufferDistance.Text, out bufferDistance);

            if (0.0 == bufferDistance)
            {
                new MessageWindow("缓冲距离不可为0").Show();
                return;
            }
            if (featureLayers == null || featureLayers.Count == 0)
            {
                new MessageWindow("没有图层").Show();
                return;
            }

            IFeatureLayer featureLayer = GetFeatureLayer(comboBoxSelect);

            if (featureLayer == null)
            {
                return;
            }

            Geoprocessor geoprocessor = new Geoprocessor();

            geoprocessor.OverwriteOutput = true;

            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(featureLayer, this.txb_SavaPath.Text, Convert.ToString(bufferDistance + " Meters"));

            buffer.dissolve_option = "ALL";        //相交部分不会融合
            buffer.line_side       = "FULL";       //默认是"FULL"
            buffer.line_end_type   = "ROUND";      //默认是"ROUND"
            IGeoProcessorResult geoProcessorResult = null;

            try
            {
                geoProcessorResult = (IGeoProcessorResult)geoprocessor.Execute(buffer, null);

                loadBufferResultEvemtHandle.Invoke(savaFilePath, comboBoxSelect + "_buffer.shp");

                new MessageWindow("缓冲区建立成功").Show();

                Mouse.SetCursor(Cursors.Arrow);

                this.Close();
            }
            catch
            {
                new MessageWindow("缓冲区建立失败").Show();

                Mouse.SetCursor(Cursors.Arrow);
            }
        }
Example #5
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(texOutputPath.Text)) || ".shp" != System.IO.Path.GetExtension(texOutputPath.Text))
            {
                MessageBox.Show("输出路径错误!!!");
                return;
            }
            if (mHookHelper.FocusMap.LayerCount == 0)
            {
                return;
            }
            //获取图层
            IFeatureLayer pFeatureLayer = GetFatureLayer((string)cboLayer.SelectedItem);

            if (null == pFeatureLayer)
            {
                MessageBox.Show("图层" + (string)cboLayer.SelectedItem + "不存在!\r\n");
                return;
            }
            //获取一个geoprocessor的实例
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            strOutputPath      = texOutputPath.Text;
            //创建应Buffer工具的实例
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pFeatureLayer, strOutputPath, bufferDistance.ToString());
            //执行缓冲区分析
            IGeoProcessorResult result = null;

            result = (IGeoProcessorResult)gp.Execute(buffer, null);
            //判断缓冲区分析是否成功
            if (result.Status != esriJobStatus.esriJobSucceeded)
            {
                MessageBox.Show("图层" + pFeatureLayer.Name + "缓冲区生成失败!");
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("缓冲区生成成功!");
            }
        }
Example #6
0
        public bool MakeTimeStep(string inFileName, string outFileName, IPoint from, IPoint to)
        {
            IFeatureClass fc   = null;
            IPolyline     line = null;
            //string path;
            //string fileName;
            bool result = true;

            fc   = this.CreateEmptyFeatureClass(inFileName, "POLYLINE");
            line = this.MakePolyLine(from, to);
            this.addGeometry(fc, line as IGeometry);

            ESRI.ArcGIS.AnalysisTools.Buffer buf = new ESRI.ArcGIS.AnalysisTools.Buffer();
            buf.buffer_distance_or_field = 100;
            buf.line_end_type            = "ROUND";
            buf.in_features       = fc;
            buf.out_feature_class = outFileName;
            this.RunProcess(buf, null);

            return(result);
        }
Example #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            //判断Mapcontrol中是否包含图层
            if (this.axMapControl1.LayerCount == 0)
            {
                return;
            }
            //获取mapcontrol最终的第一图层
            ILayer pLayer = this.axMapControl1.Map.get_Layer(0);
            //输出路径,可以自行制定
            string strOutputPath = @"D:\Buffer.shp";
            //缓冲半径
            double dbDistace = 1.0;

            //获取一个geoprocessor的实例,避免与命名空间Geoprocessing中的Geoprocessor发生引用错误
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;
            //创建应Buffer工具的实例
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pLayer, strOutputPath, dbDistace);

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

            result = gp.Execute(buffer, null) as IGeoProcessorResult;
            //判断缓冲区分析是否成功
            if (result.Status != esriJobStatus.esriJobSucceeded)
            {
                MessageBox.Show("图层" + pLayer.Name + "缓冲区生成失败!");
            }
            else
            {
                MessageBox.Show("缓冲区生成成功!");
                //将生成成功的图层加入到Mapcontrol中
                int index = strOutputPath.LastIndexOf("\\");
                this.axMapControl1.AddShapeFile(strOutputPath.Substring(0, index), strOutputPath.Substring(index));
            }
        }
Example #8
0
        private void 获取报错信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Geoprocessor GP = new Geoprocessor();

            GP.OverwriteOutput = true;
            // Create the tool process object.
            ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new
                                                          ESRI.ArcGIS.AnalysisTools.Buffer();

            // Set parameter values.
            //bufferTool.in_features = FileGDBPath + "\\LotIds";
            bufferTool.in_features = FileGDBPath + "\\line";
            //bufferTool.out_feature_class = FileGDBPath + "\\LotIds_BufferSystem";
            bufferTool.out_feature_class        = FileGDBPath + "\\line_Buffer";
            bufferTool.buffer_distance_or_field = "100 Feet";
            bufferTool.line_side     = "LEFT";
            bufferTool.line_end_type = "FLAT";
            try
            {
                IGeoProcessorResult2 result = GP.Execute(bufferTool, null) as IGeoProcessorResult2;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "GP Error");
            }
            finally
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int i = 0; i < GP.MessageCount; i++)
                {
                    sb.AppendLine(GP.GetMessage(i));
                }
                if (sb.Capacity > 0)
                {
                    MessageBox.Show(sb.ToString(), "GP Messages");
                }
            }
        }
Example #9
0
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            //timer 控件可用
            timerPro.Enabled = true;
            //scroll the textbox to the bottom

            txtMessages.Text = "\r\n分析开始,这可能需要几分钟时间,请稍候..\r\n";
            txtMessages.Update();
            ScrollToBottom();

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

            //转换distance为double类型
            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("Bad buffer distance!");
                return;
            }
            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
                ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("Bad output filename!");
                return;
            }
            //判断图层个数
            if (pMap.LayerCount == 0)
            {
                return;
            }

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

            if (null == layer)
            {
                txtMessages.Text += "Layer " + (string)cboLayers.SelectedItem + "cannot be found!\r\n";
                return;
            }


            //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(layer, txtOutputPath.Text, Convert.ToString(bufferDistance) + " " + (string)cboUnits.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
            {
                txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
            }
            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
            }

            //scroll the textbox to the bottom
            ScrollToBottom();
            txtMessages.Text += "\r\n分析完成.\r\n";
            timerPro.Enabled  = false;
            gp = null;
        }
Example #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            double bufferDistance;

            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("距离设置错误", "Error!");
                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;
            }
            DataOperator  pDo = new DataOperator(m_map, null);
            IFeatureLayer pFl = (IFeatureLayer)pDo.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(pFl, txtOutputPath.Text, Convert.ToString(bufferDistance) + "" + unit);
            try
            {
                IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);
            }
            catch
            {
            }
            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 pWsf   = new ShapefileWorkspaceFactory() as IWorkspaceFactory;
            IWorkspace        pWs    = pWsf.OpenFromFile(fileDirectory, 0);
            IFeatureWorkspace pFs    = pWs as IFeatureWorkspace;
            IFeatureClass     pFc    = pFs.OpenFeatureClass(tmpstr);
            IFeatureLayer     pfl    = new FeatureLayer() as IFeatureLayer;

            pfl.FeatureClass = pFc;
            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 pGeofl = pfl as IGeoFeatureLayer;

            pRen            = pGeofl.Renderer as ISimpleRenderer;
            pRen.Symbol     = pFillSymbol as ISymbol;
            pGeofl.Renderer = pRen as IFeatureRenderer;
            ILayerEffects pLayerEffects = pfl as ILayerEffects;

            pLayerEffects.Transparency = 150;
            m_mapControl.AddLayer((ILayer)pfl, 0);
            MessageBox.Show(comboBoxLayer.SelectedText + "缓冲区生成成功!");
        }
    private void btnBuffer_Click(object sender, EventArgs e)
    {
      //make sure that all parameters are okay
      double bufferDistance;
      double.TryParse(txtBufferDistance.Text, out bufferDistance);
      if (0.0 == bufferDistance)
      {
        MessageBox.Show("Bad buffer distance!");
        return;
      }

      if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
        ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
      {
        MessageBox.Show("Bad output filename!");
        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 += "Layer " + (string)cboLayers.SelectedItem + "cannot be found!\r\n";
        return;
      }

      //scroll the textbox to the bottom
      ScrollToBottom();
      //add message to the messages box
      txtMessages.Text += "Buffering layer: " + layer.Name + "\r\n";

      txtMessages.Text += "\r\nGet the geoprocessor. This might take a few seconds...\r\n";
      txtMessages.Update();
      //get an instance of the geoprocessor
      Geoprocessor gp = new Geoprocessor();
      gp.OverwriteOutput = true;
      txtMessages.Text += "Buffering...\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 += "Failed to buffer layer: " + layer.Name + "\r\n";
      }
      txtMessages.Text += ReturnMessages(gp);
      //scroll the textbox to the bottom
      ScrollToBottom();

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

    }
Example #12
0
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            //timer �ؼ�����
            timerPro.Enabled = true;
            //scroll the textbox to the bottom

            txtMessages.Text = "\r\n������ʼ,�������Ҫ������ʱ��,���Ժ�..\r\n";
            txtMessages.Update();
            ScrollToBottom();

            //make sure that all parameters are okay
            double bufferDistance;
            //ת��distanceΪdouble����
            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("Bad buffer distance!");
                return;
            }
            //�ж����·���Ƿ�Ϸ�
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
              ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("Bad output filename!");
                return;
            }
            //�ж�ͼ�����
            if (pMap.LayerCount == 0)
                return;

            //get the layer from the map
            IFeatureLayer layer = GetFeatureLayer((string)cboLayers.SelectedItem);
            if (null == layer)
            {
                txtMessages.Text += "Layer " + (string)cboLayers.SelectedItem + "cannot be found!\r\n";
                return;
            }

            //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(layer, txtOutputPath.Text, Convert.ToString(bufferDistance) + " " + (string)cboUnits.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
            {
                txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
            }
            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
            }

            //scroll the textbox to the bottom
            ScrollToBottom();
            txtMessages.Text += "\r\n�������.\r\n";
            timerPro.Enabled = false;
            gp = null;
        }
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            //make sure that all parameters are okay
            double bufferDistance;

            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("Bad buffer distance!");
                return;
            }

            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
                ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("Bad output filename!");
                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 += "Layer " + (string)cboLayers.SelectedItem + "cannot be found!\r\n";
                return;
            }

            //scroll the textbox to the bottom
            ScrollToBottom();
            //add message to the messages box
            txtMessages.Text += "Buffering layer: " + layer.Name + "\r\n";

            txtMessages.Text += "\r\nGet the geoprocessor. This might take a few seconds...\r\n";
            txtMessages.Update();
            //get an instance of the geoprocessor
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            txtMessages.Text  += "Buffering...\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 += "Failed to buffer layer: " + layer.Name + "\r\n";
            }
            txtMessages.Text += ReturnMessages(gp);
            //scroll the textbox to the bottom
            ScrollToBottom();

            txtMessages.Text += "\r\nDone.\r\n";
            txtMessages.Text += "-----------------------------------------------------------------------------------------\r\n";
            //scroll the textbox to the bottom
            ScrollToBottom();
        }
Example #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            IFeature pFeature;
            IFeatureClass pFeatureClass;
            IFeatureCursor pFeatureCursor = null;
            pFeatureClass = (GetLayerByName(this.cboField.Text) as IFeatureLayer).FeatureClass;
            pFeatureCursor = pFeatureClass.Search(null, true);
            pFeature = pFeatureCursor.NextFeature();

            IFeature sFeature;
            IFeatureClass sFeatureClass;
            IFeatureCursor sFeatureCursor = null;
            sFeatureClass = (GetLayerByName(this.cboSch.Text) as IFeatureLayer).FeatureClass;
            sFeatureCursor = sFeatureClass.Search(null, true);
            sFeature = sFeatureCursor.NextFeature();

            IGeometry pTemPt;

            //空间包含查询
            IRelationalOperator pRelOpt = pFeature.Shape as IRelationalOperator;

            while (sFeature != null)
            {
                pTemPt = sFeature.ShapeCopy;
                if (pRelOpt.Contains(pTemPt))
                {
                    axMap.Map.SelectFeature((GetLayerByName(this.cboSch.Text) as IFeatureLayer), sFeature);
                    axMap.ActiveView.Refresh();
                }
                sFeature = sFeatureCursor.NextFeature();
            }

            IFeatureLayer pFeatureLayer = GetLayerByName(this.cboSch.Text);
            //缓冲距离
            double bufferDistance;
            //输入的缓冲距离转换为double
            double.TryParse("5000", out bufferDistance);

            string outputpath = "schdata\\中学_buffer.shp";
            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(outputpath)) ||
              ".shp" != System.IO.Path.GetExtension(outputpath))
            {
                MessageBox.Show("输出路径错误!");
                return;
            }




            //获取一个geoprocessor的实例
            Geoprocessor gp = new Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;
            string distance = "5000";
            //创建一个Buffer工具的实例
            //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();
            //IFeatureLayer pFeatureLayer = (IFeatureLayer)pEnumFeatureSetup;
            //IFeatureLayer pFeatureLayer = mMapControl.Map.FeatureSelection as IFeatureLayer;
            buffer.in_features = /*pEnumFeatureSetup*/pFeatureLayer;
            buffer.out_feature_class = outputpath;
            buffer.buffer_distance_or_field = para;
            buffer.dissolve_option = "ALL";


            //执行缓冲区分析
            IGeoProcessorResult results = null;
            //results = (IGeoProcessorResult)gp.Execute(buffer, null);

            results = (IGeoProcessorResult)gp.Execute(buffer, null);



            //判断缓冲区是否成功生成
            if (results.Status != esriJobStatus.esriJobSucceeded)
                MessageBox.Show("图层" + "缓冲区生成失败!");
            else
            {
                this.DialogResult = DialogResult.OK;
                //MessageBox.Show("缓冲区生成成功!");
                axMap.AddShapeFile("schdata", "中学_buffer.shp");

            }


            //进行叠置分析裁剪图层
            Clip(cboField.Text);

            
            
        }
Example #15
0
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            //make sure that all parameters are okay
            double bufferDistance;
            //转换distance为double类型
            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("Bad buffer distance!");
                return;
            }
            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||
              ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("Bad output filename!");
                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 += "Layer " + (string)cboLayers.SelectedItem + "cannot be found!\r\n";
                return;
            }

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

            txtMessages.Text += "\r\n分析开始,这可能需要几分钟时间,请稍候..\r\n";
            txtMessages.Update();
            //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(layer, txtOutputPath.Text, Convert.ToString(bufferDistance) + " " + (string)cboUnits.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)
            {
                txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
            }
            if (results.Status != esriJobStatus.esriJobSucceeded)
            {
                txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
            }

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

            txtMessages.Text += "\r\n分析完成.\r\n";
            txtMessages.Text += "-----------------------------------------------------------------------------------------\r\n";
            //scroll the textbox to the bottom
            ScrollToBottom();
        }
Example #16
0
        /*变量:
         * 1、图层
         * 2、距离
         * 3、单位
         * 4、保存路径
         */
        private void button1_Click(object sender, EventArgs e)
        {
            double bufferDistance, bufferDistance2, bufferDistance3;
            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            double.TryParse(txtBufferDistance2.Text, out bufferDistance2);
            double.TryParse(txtBufferDistance3.Text, out bufferDistance3);
            if (CNunit.SelectedIndex == 0)
                DW= "Meters";
            else if (CNunit.SelectedIndex == 1)
                DW= "Kilometers";
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("输入范围距离无效!");
                return;
            }
            if (CNunit.SelectedItem == null)
            {
                MessageBox.Show("请选择单位", "提示");
                return;
            }
             //判断输出路径是否合法
               if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) ||".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
             {
               MessageBox.Show("输出路径无效!");
                return;
            }
            IFeatureLayer layer = GetFeatureLayer((string)cboLayers.SelectedItem);
              if (null == layer)
              {
               MessageBox.Show("选中图层无效!");
              return;
              }
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            double[] dis = { 0, bufferDistance, bufferDistance2, bufferDistance3 };
            double[]distance={bufferDistance,bufferDistance2,bufferDistance3};
            string[] level = { "", "高级", "中级", "低级" };
            int i = 1;
            txtOutputPath.Text = System.IO.Path.Combine(SystemSet.Base_Map + "\\处理数据库\\实验数据", (level[i] + "_" + (string)cboLayers.SelectedItem + "_范围.shp"));
             int l1 = txtOutputPath.Text.LastIndexOf("\\");
             lab_message.Text = txtOutputPath.Text.Substring(l1 + 1) + "正在处理···";
             ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer mulBuffer = new MultipleRingBuffer();
             mulBuffer.Input_Features = layer;
             mulBuffer.Output_Feature_class = txtOutputPath.Text;
             mulBuffer.Buffer_Unit = "Meters";
             mulBuffer.Distances = distance;//[bufferDistance, bufferDistance2, bufferDistance3];
             mulBuffer.Outside_Polygons_Only = "full";
             mulBuffer.Field_Name = "分析半径";
             gp.Execute(mulBuffer, null);
             MessageBox.Show("成功");

            while (i < 4)
            {
                //修改当前指针样式
                this.Cursor = Cursors.WaitCursor;
                //调用缓冲去区处理工具buffer
                txtOutputPath.Text = System.IO.Path.Combine(SystemSet.Base_Map+"\\处理数据库\\实验数据", (level[i] + "_" + (string)cboLayers.SelectedItem + "_buffer.shp"));
                int l = txtOutputPath.Text.LastIndexOf("\\");
                lab_message.Text = txtOutputPath.Text.Substring(l+1) + "正在处理···";
                ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, txtOutputPath.Text, Convert.ToString(dis[i]) +" "+DW);//单级缓冲

                 //gp.Execute(buffer, null);
                try
                {

                    IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);
                    if (results.Status != esriJobStatus.esriJobSucceeded)
                    {
                        MessageBox.Show("缓冲区失败的图层: " + layer.Name, "提示!");
                    }
                    this.Cursor = Cursors.Default;
                    MessageBox.Show(level[i]+"_" +layer.Name + "分析统计完成!", "提示!");
                    //将统计分析完成的图层添加到mapcontrol
                    IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();//定义工作空间工厂接口
                    IWorkspace pWorkSpace = pWorkspaceFactory.OpenFromFile(txtOutputPath.Text.Substring(0, txtOutputPath.Text.Length - (level[i]+"_" + (string)cboLayers.SelectedItem + "_buffer.shp").Length), 0);//实例化工作空间
                    IFeatureWorkspace pFeatureWorkspace = pWorkSpace as IFeatureWorkspace;
                    IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(level[i]+"_" +(string)cboLayers.SelectedItem +  "_buffer.shp");//
                    //以上得到的是featureclass。

                    IDataset pDataset = pFeatureClass as IDataset;
                    IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = pFeatureClass;
                    pFeatureLayer.Name = pDataset.Name;//图层名称
                    ILayer pLayer = pFeatureLayer as ILayer;

                    m_hookHelper.FocusMap.AddLayer(pLayer);
                    m_hookHelper.FocusMap.MoveLayer(pLayer, cboLayers.SelectedIndex + i);
                    i++;

                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    this.Cursor = Cursors.Default;
                    this.Close();
                    return;
                }
            }

            //GISHandler.GISTools.QueryByBuffer(m_hookHelper);
            this.Close();
            StasticResult SR = new StasticResult(this.mapContol);
            SR.Show();
            SR.StartPosition = FormStartPosition.CenterScreen;
            SR.TopMost = true;

            //1、将结果图层添加到axmapcontrol中
            //2、多级缓冲 -->方法递归调用。/for循环三次  distance+=distance(图层叠加在一起  不好进行统计。)
            //3、将各级缓冲区中所叠置基图中的属性信息 自定义提取 装入 gridcontrol中。完成!
        }
Example #17
0
        /*变量:
         * 1、图层
         * 2、距离
         * 3、单位
         * 4、保存路径
         */
        private void button1_Click(object sender, EventArgs e)
        {
            double bufferDistance, bufferDistance2, bufferDistance3;

            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            double.TryParse(txtBufferDistance2.Text, out bufferDistance2);
            double.TryParse(txtBufferDistance3.Text, out bufferDistance3);
            if (CNunit.SelectedIndex == 0)
            {
                DW = "Meters";
            }
            else if (CNunit.SelectedIndex == 1)
            {
                DW = "Kilometers";
            }
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("输入范围距离无效!");
                return;
            }
            if (CNunit.SelectedItem == null)
            {
                MessageBox.Show("请选择单位", "提示");
                return;
            }
            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) || ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("输出路径无效!");
                return;
            }
            IFeatureLayer layer = GetFeatureLayer((string)cboLayers.SelectedItem);

            if (null == layer)
            {
                MessageBox.Show("选中图层无效!");
                return;
            }
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            double[] dis      = { 0, bufferDistance, bufferDistance2, bufferDistance3 };
            double[] distance = { bufferDistance, bufferDistance2, bufferDistance3 };
            string[] level    = { "", "高级", "中级", "低级" };
            int      i        = 1;

            txtOutputPath.Text = System.IO.Path.Combine(SystemSet.Base_Map + "\\处理数据库\\实验数据", (level[i] + "_" + (string)cboLayers.SelectedItem + "_范围.shp"));
            int l1 = txtOutputPath.Text.LastIndexOf("\\");

            lab_message.Text = txtOutputPath.Text.Substring(l1 + 1) + "正在处理···";
            ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer mulBuffer = new MultipleRingBuffer();
            mulBuffer.Input_Features        = layer;
            mulBuffer.Output_Feature_class  = txtOutputPath.Text;
            mulBuffer.Buffer_Unit           = "Meters";
            mulBuffer.Distances             = distance;//[bufferDistance, bufferDistance2, bufferDistance3];
            mulBuffer.Outside_Polygons_Only = "full";
            mulBuffer.Field_Name            = "分析半径";
            gp.Execute(mulBuffer, null);
            MessageBox.Show("成功");



            while (i < 4)
            {
                //修改当前指针样式
                this.Cursor = Cursors.WaitCursor;
                //调用缓冲去区处理工具buffer
                txtOutputPath.Text = System.IO.Path.Combine(SystemSet.Base_Map + "\\处理数据库\\实验数据", (level[i] + "_" + (string)cboLayers.SelectedItem + "_buffer.shp"));
                int l = txtOutputPath.Text.LastIndexOf("\\");
                lab_message.Text = txtOutputPath.Text.Substring(l + 1) + "正在处理···";
                ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, txtOutputPath.Text, Convert.ToString(dis[i]) + " " + DW);//单级缓冲

                //gp.Execute(buffer, null);
                try
                {
                    IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);
                    if (results.Status != esriJobStatus.esriJobSucceeded)
                    {
                        MessageBox.Show("缓冲区失败的图层: " + layer.Name, "提示!");
                    }
                    this.Cursor = Cursors.Default;
                    MessageBox.Show(level[i] + "_" + layer.Name + "分析统计完成!", "提示!");
                    //将统计分析完成的图层添加到mapcontrol
                    IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();                                                                                                                                     //定义工作空间工厂接口
                    IWorkspace        pWorkSpace        = pWorkspaceFactory.OpenFromFile(txtOutputPath.Text.Substring(0, txtOutputPath.Text.Length - (level[i] + "_" + (string)cboLayers.SelectedItem + "_buffer.shp").Length), 0); //实例化工作空间
                    IFeatureWorkspace pFeatureWorkspace = pWorkSpace as IFeatureWorkspace;
                    IFeatureClass     pFeatureClass     = pFeatureWorkspace.OpenFeatureClass(level[i] + "_" + (string)cboLayers.SelectedItem + "_buffer.shp");                                                                      //
                    //以上得到的是featureclass。

                    IDataset      pDataset      = pFeatureClass as IDataset;
                    IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = pFeatureClass;
                    pFeatureLayer.Name         = pDataset.Name;//图层名称
                    ILayer pLayer = pFeatureLayer as ILayer;

                    m_hookHelper.FocusMap.AddLayer(pLayer);
                    m_hookHelper.FocusMap.MoveLayer(pLayer, cboLayers.SelectedIndex + i);
                    i++;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    this.Cursor = Cursors.Default;
                    this.Close();
                    return;
                }
            }

            //GISHandler.GISTools.QueryByBuffer(m_hookHelper);
            this.Close();
            StasticResult SR = new StasticResult(this.mapContol);

            SR.Show();
            SR.StartPosition = FormStartPosition.CenterScreen;
            SR.TopMost       = true;

            //1、将结果图层添加到axmapcontrol中
            //2、多级缓冲 -->方法递归调用。/for循环三次  distance+=distance(图层叠加在一起  不好进行统计。)
            //3、将各级缓冲区中所叠置基图中的属性信息 自定义提取 装入 gridcontrol中。完成!
        }