Пример #1
0
        private void btn_classstatis_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断

            string sImageInput = this.txt_ImageInput.Text.Trim();
            if (sImageInput.Equals(""))
            {
                MessageBox.Show("请选择待统计影像!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //string filename = sImageInput.Substring(sImageInput.LastIndexOf("\\") + 1);
            //res = filename.Split(new char[] { '_', '.' }, StringSplitOptions.RemoveEmptyEntries);
            string filename = Path.GetFileNameWithoutExtension(sImageInput);
            res = filename.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            string sMorTime     = res[4];
            string sResultTitle = this.cbx_VIType.Text.Trim();

            #endregion

            //调用进度条界面线程
            //Thread t = new Thread(new ThreadStart(thread1));
            //t.Start();
            #region 执行统计

            try
            {
                ProgressFunc pd  = new ProgressFunc(this.ProgressBarInfo);
                IntPtr       pre = this.Handle;
                int          ire = 0;

                //string strInFile = @"D:\share\Hongxingtest\wxf\text_data\soil\soil_organic1.tif";
                char[] strInFileList = sImageInput.ToCharArray();

                string strRegionFile     = this.txt_SHPFile.Text.Trim();
                char[] strRegionFileList = strRegionFile.ToCharArray();

                string strField     = "RASTERID";
                char[] strFieldList = strField.ToCharArray();

                int nCount = ReadShape.getShapeCount(strRegionFile);

                int[] pRegionCodeList = new int[nCount];

                double[] padfResultList = new double[nCount];
                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, 2, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 6];
                for (int i = 0; i < nCount; i++)
                {
                    string sRASTERID = pRegionCodeList[i].ToString();
                    arrStatistic[i, 0] = sMorTime;//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    arrStatistic[i, 1] = DataBaseOperate.getTownName(DataBaseOperate.getGLQ(sRASTERID));
                    //arrStatistic[i, 1] = sGLQName;
                    arrStatistic[i, 2] = DataBaseOperate.getVillName(DataBaseOperate.getJMZ(sRASTERID));
                    //arrStatistic[i, 2] = sJMZName;
                    //arrStatistic[i, 3] = sPlotName;
                    arrStatistic[i, 3] = DataBaseOperate.getPlotName(sRASTERID);
                    arrStatistic[i, 4] = DataBaseOperate.getPlotId(sRASTERID);
                    //arrStatistic[i, 4] = sRASTERID; "区域代码"
                    arrStatistic[i, 5] = padfResultList[i].ToString("0.00");
                }
                //string sResultTitle = DataBaseOperate.getNUTRIENTTableTitleName(res[2]);

                //表头
                string[] arrName = { "监测时间", "作业区", "作业站", "地块名称", "地块编号", sResultTitle };
                //数组行按","拆分后转DataTable
                dtInfo = StringFormater.Convert(arrName, arrStatistic);
                InitDataSet();
                //dgvInfo.DataSource = dt;
            }
            catch (Exception ex)
            {
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                MessageBox.Show(ex.Message);
            }
            #endregion
        }
Пример #2
0
        private void btn_classstatis_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断

            string sImageInput = this.txt_ImageInput.Text.Trim();
            if (sImageInput.Equals(""))
            {
                MessageBox.Show("请选择待统计影像!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string filename = sImageInput.Substring(sImageInput.LastIndexOf("\\") + 1);
            res = filename.Split(new char[] { '_', '.' }, StringSplitOptions.RemoveEmptyEntries);
            #endregion

            //调用进度条界面线程
            //Thread t = new Thread(new ThreadStart(thread1));
            //t.Start();
            #region 执行统计

            try
            {
                ProgressFunc pd  = new ProgressFunc(this.ProgressBarInfo);
                IntPtr       pre = this.Handle;
                int          ire = 0;

                //string strInFile = @"D:\share\Hongxingtest\wxf\text_data\soil\soil_organic1.tif";
                char[] strInFileList = sImageInput.ToCharArray();

                string strRegionFile     = System.Windows.Forms.Application.StartupPath + "\\BaseData\\hongxing_plot.shp";
                char[] strRegionFileList = strRegionFile.ToCharArray();

                string strField     = "RASTERID";
                char[] strFieldList = strField.ToCharArray();

                int nCount = ReadShape.getShapeCount(strRegionFile);

                int[] pRegionCodeList = new int[nCount];

                double[] padfResultList = new double[nCount];
                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, 2, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 6];
                for (int i = 0; i < nCount; i++)
                {
                    string sRASTERID = pRegionCodeList[i].ToString();
                    //获得后,到PLOT_DKINFO中找到用sRASTERID找到对应PlotID
                    //string sPlotID = sRASTERID;///此处为测试
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应GLQ,再用GLQ到TOWN表里找到对应的[TownName]进行显示到这里(PLOT_DKINFO.GLQ=TOWN.TowCode);
                    //string sGLQName = "作业区_TOWN.TownName";
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应JMZ,再用GLQ到VILLAGE表里找到对应的VillName进行显示到这里(PLOT_DKINFO.JMZ=VILLAGE.[VillCode]);
                    ///string sJMZName = "作业站_VILLAGE.VillName";
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应FULLNAME,显示到这里;
                    //string sPlotName = "地块名称_[PLOT_DKINFO].[FULLNAME]";

                    arrStatistic[i, 0] = res[2];//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    arrStatistic[i, 1] = DataBaseOperate.getTownName(DataBaseOperate.getGLQ(sRASTERID));
                    //arrStatistic[i, 1] = sGLQName;
                    arrStatistic[i, 2] = DataBaseOperate.getVillName(DataBaseOperate.getJMZ(sRASTERID));
                    //arrStatistic[i, 2] = sJMZName;
                    //arrStatistic[i, 3] = sPlotName;
                    arrStatistic[i, 3] = DataBaseOperate.getPlotName(sRASTERID);
                    arrStatistic[i, 4] = DataBaseOperate.getPlotId(sRASTERID);
                    //arrStatistic[i, 4] = sRASTERID; "区域代码"

                    if (res[0].Contains("RETRIEVAL"))
                    {
                        //int result = (int)(padfResultList[i]*100);
                        arrStatistic[i, 5] = Math.Round(padfResultList[i]).ToString();
                    }
                    else
                    {
                        arrStatistic[i, 5] = padfResultList[i].ToString("0.00");
                    }
                }

                string sResultTitle = DataBaseOperate.getTableTitleName(res[0], res[1]);
                //表头
                string[] arrName = { "监测时间", "作业区", "作业站", "地块名称", "地块编号", sResultTitle };
                //数组行按","拆分后转DataTable
                dtInfo = StringFormater.Convert(arrName, arrStatistic);
                InitDataSet();
                //dgvInfo.DataSource = dt;
            }
            catch (Exception ex)
            {
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                MessageBox.Show(ex.Message);
            }
            #endregion
        }