Пример #1
0
        private void Confirm_Click(object sender, EventArgs e)
        {
            if (TimeSelect.SelectedItem == null)
            {
                MessageBox.Show("请选择时段", "提示!");
                return;
            }
            try
            {
                progress(1000);
                ILayer ly = (ILayer)StasticResult.Stastic(axmapcontrol, 0, "stastic");
                gridControl1.DataSource = StasticResult.creatDataTable(ly, "统计分析");
                groupPanel1.Text        = "分析结果信息";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }/*
              * if (LayerSelect.SelectedItem == "模拟矿区坐标点.txt")
              * {
              *
              * switch (TimeSelect.SelectedIndex)
              * {
              *     case 0:
              *         //distance = 100;
              *         progress(1000);
              *         axmapcontrol.AddShapeFile(@"G:\数据库\演示数据库", name[TimeSelect.SelectedIndex]);
              *         axmapcontrol.MoveLayerTo(LayerSelect.SelectedIndex, LayerSelect.SelectedIndex + 1);
              *         ILayer ly3 = (ILayer)StasticResult.Stastic(axmapcontrol, TimeSelect.SelectedIndex + 1, name[TimeSelect.SelectedIndex]);
              *         gridControl1.DataSource = StasticResult.creatDataTable(ly3, name[TimeSelect.SelectedIndex]);
              *         groupPanel1.Text = name[TimeSelect.SelectedIndex] + "统计信息";
              *         break;
              *     case 1:
              *         //distance = 250;
              *         progress(2000);
              *         axmapcontrol.AddShapeFile(@"G:\数据库\演示数据库", name[TimeSelect.SelectedIndex]);
              *         axmapcontrol.MoveLayerTo(LayerSelect.SelectedIndex, LayerSelect.SelectedIndex + 2);
              *         ILayer ly6 = (ILayer)StasticResult.Stastic(axmapcontrol, TimeSelect.SelectedIndex + 1, name[TimeSelect.SelectedIndex]);
              *         gridControl1.DataSource = StasticResult.creatDataTable(ly6, name[TimeSelect.SelectedIndex]);
              *         groupPanel1.Text = name[TimeSelect.SelectedIndex] + "统计信息";
              *         break;
              *     case 2:
              *         //distance = 500;
              *         progress(3000);
              *         axmapcontrol.AddShapeFile(@"G:\数据库\演示数据库", name[TimeSelect.SelectedIndex]);
              *         axmapcontrol.MoveLayerTo(LayerSelect.SelectedIndex, LayerSelect.SelectedIndex + 3);
              *         ILayer ly12 = (ILayer)StasticResult.Stastic(axmapcontrol, TimeSelect.SelectedIndex + 1, name[TimeSelect.SelectedIndex]);
              *         gridControl1.DataSource = StasticResult.creatDataTable(ly12, name[TimeSelect.SelectedIndex]);
              *         groupPanel1.Text = name[TimeSelect.SelectedIndex] + "统计信息";
              *         break;
              *     default:
              *         break;
              * }
              * }
              * else
              * {
              * switch (TimeSelect.SelectedIndex)
              * {
              *     case 0:
              *         //distance = 100;
              *         progress(1000);
              *         axmapcontrol.AddShapeFile(@"G:\数据库\演示数据库", name1[TimeSelect.SelectedIndex]);
              *         axmapcontrol.MoveLayerTo(LayerSelect.SelectedIndex, LayerSelect.SelectedIndex + 1);
              *         ILayer ly3 = (ILayer)StasticResult.Stastic(axmapcontrol, TimeSelect.SelectedIndex + 1, name[TimeSelect.SelectedIndex]);
              *         gridControl1.DataSource = StasticResult.creatDataTable(ly3, name[TimeSelect.SelectedIndex]);
              *         groupPanel1.Text = name[TimeSelect.SelectedIndex] + "统计信息";
              *         break;
              *     case 1:
              *         //distance = 250;
              *         progress(2000);
              *         axmapcontrol.AddShapeFile(@"G:\数据库\演示数据库", name1[TimeSelect.SelectedIndex]);
              *         axmapcontrol.MoveLayerTo(LayerSelect.SelectedIndex, LayerSelect.SelectedIndex + 2);
              *         ILayer ly6 = (ILayer)StasticResult.Stastic(axmapcontrol, TimeSelect.SelectedIndex + 1, name[TimeSelect.SelectedIndex]);
              *         gridControl1.DataSource = StasticResult.creatDataTable(ly6, name[TimeSelect.SelectedIndex]);
              *         groupPanel1.Text = name[TimeSelect.SelectedIndex] + "统计信息";
              *         break;
              *     case 2:
              *         //distance = 500;
              *         progress(3000);
              *         axmapcontrol.AddShapeFile(@"G:\数据库\演示数据库", name1[TimeSelect.SelectedIndex]);
              *         axmapcontrol.MoveLayerTo(LayerSelect.SelectedIndex, LayerSelect.SelectedIndex + 3);
              *         ILayer ly12 = (ILayer)StasticResult.Stastic(axmapcontrol, TimeSelect.SelectedIndex + 1, name[TimeSelect.SelectedIndex]);
              *         gridControl1.DataSource = StasticResult.creatDataTable(ly12, name[TimeSelect.SelectedIndex]);
              *         groupPanel1.Text = name[TimeSelect.SelectedIndex] + "统计信息";
              *         break;
              *     default:
              *         break;
              * }
              * }
              *
              */

            /*
             * IFeatureLayer layer = GetFeatureLayer((string)LayerSelect.SelectedItem);
             * if (null == layer)
             * {
             *  MessageBox.Show("选中图层无效!");
             *  return;
             * }
             * Geoprocessor gp = new Geoprocessor();
             * gp.OverwriteOutput = true;
             * this.Cursor = Cursors.WaitCursor;
             * string path = System.IO.Path.Combine(@"I:\四平项目\实验数据", (string)LayerSelect.SelectedItem + "_Tency.shp");
             * ESRI.ArcGIS.AnalysisTools.Buffer tence = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, path, Convert.ToString(distance) + " " + meters);
             * try
             * {
             *  IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(tence, null);
             *  if (results.Status != esriJobStatus.esriJobSucceeded)
             *  {
             *      MessageBox.Show("趋势分析失败: " + layer.Name, "提示!");
             *  }
             *  this.Cursor = Cursors.Default;
             *  MessageBox.Show(layer.Name + "趋势分析完成!", "提示!");
             *  progressBarControl1.Visible = false;*/
            //将统计分析完成的图层添加到mapcontrol

            /*  IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();//定义工作空间工厂接口
             * IWorkspace pWorkSpace = pWorkspaceFactory.OpenFromFile(path.Substring(0, path.Length - ((string)LayerSelect.SelectedItem + "_Tency.shp").Length), 0);//实例化工作空间
             * IFeatureWorkspace pFeatureWorkspace = pWorkSpace as IFeatureWorkspace;
             * IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass((string)LayerSelect.SelectedItem + "_Tency.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, LayerSelect.SelectedIndex + 1);*/
            /*  axmapcontrol.AddShapeFile(@"I:\四平项目\实验数据", (string)LayerSelect.SelectedItem + "_Tency.shp");
             * axmapcontrol.MoveLayerTo(LayerSelect.SelectedIndex, LayerSelect.SelectedIndex + 1);
             * }
             * catch
             * {
             * MessageBox.Show("错误");
             *
             * }*/
            //this.Close();
        }
Пример #2
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中。完成!
        }
Пример #3
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中。完成!
        }