コード例 #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);
            if (filename.Contains("-"))
            {
                res = filename.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                res = filename.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
            }
            string sMorTime     = res[4];
            string sResultTitle = this.cbx_VIType.Text.Trim();
            string sField       = this.cbx_FieldName.Text.Trim();
            string sStaType     = this.cbx_StaValueType.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();

                char[] strFieldList = sField.ToCharArray();



                List <string> fielddatalist = ReadShape.getShapeFieldDataList(strRegionFile, sField);
                int           nCount        = fielddatalist.Count;

                List <int> intfdlist       = new List <int>(nCount);
                int[]      pRegionCodeList = new int[nCount];
                //for (int i = 0; i < nCount; i++)
                //{
                //    //转LIST出错
                //    intfdlist.Add(int.Parse(fielddatalist[i]));
                //}

                //int[] pRegionCodeList = intfdlist.ToArray();

                double[] padfResultList = new double[nCount];

                int iStatisticType = 2; //默认为平均值
                if (sStaType == "Max")
                {
                    iStatisticType = 1;
                }
                else if (sStaType == "Min")
                {
                    iStatisticType = 0;
                }

                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, iStatisticType, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 4];
                for (int i = 0; i < nCount; i++)
                {
                    arrStatistic[i, 0] = sMorTime;//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    arrStatistic[i, 1] = pRegionCodeList[i].ToString();
                    arrStatistic[i, 2] = padfResultList[i].ToString("0.00");
                    arrStatistic[i, 3] = sStaType;
                }
                //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_ok_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断
            if (this.listViewImage.Items.Count <= 0)
            {
                MessageBox.Show("请选择输入影像!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.txt_ReferenceImage.Text.Equals(""))
            {
                MessageBox.Show("请输入统计单元文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string txt_SHPFile = this.txt_ReferenceImage.Text.Trim();

            #endregion
            this.btn_ok.Enabled = false;

            #region 执行
            this.progressBar.Visible = true;
            try
            {
                foreach (ListViewItem item in this.listViewImage.Items)
                {
                    string    sFile    = item.SubItems[0].Text.Trim();
                    string    filename = Path.GetFileNameWithoutExtension(sFile);
                    string [] res      = filename.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                    string    sMorTime = res[4];
                    string    sVIType  = res[res.Length - 1].ToString();
                    if (!sVIType.Contains("NDVI") && !sVIType.Contains("EVI") && !sVIType.Contains("Band1") && !sVIType.Contains("Band2") && !sVIType.Contains("Band3") && !sVIType.Contains("Band4"))
                    {
                        break;
                    }
                    string sSensorType = res[1];
                    sSensorType = sSensorType.ToUpper();
                    string sSensorCode = "1";
                    if (sSensorType.Contains("CCD"))
                    {
                        sSensorCode = "1";
                    }
                    else if (sSensorType.Contains("WFV"))
                    {
                        sSensorCode = "3";
                    }
                    else
                    {
                        break;
                    }
                    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 = sFile.ToCharArray();

                    string strRegionFile     = txt_SHPFile;
                    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];
                    if (Path.GetExtension(txt_SHPFile).Contains("shp"))
                    {
                        for (int iStatisticType = 0; iStatisticType < 3; iStatisticType++)
                        {
                            ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, iStatisticType, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                            int   result = 0;
                            float fVI    = 0.00f;
                            for (int i = 0; i < nCount; i++)
                            {
                                string sRASTERID = pRegionCodeList[i].ToString();

                                string sPlotID = DataBaseOperate.getPlotId(sRASTERID);

                                string sStatisticResult = padfResultList[i].ToString("0.00");
                                bool   b = float.TryParse(sStatisticResult, out fVI);
                                if (!b || sStatisticResult.Contains("正"))
                                {
                                    sStatisticResult = "0.00";
                                }
                                string sVI_STATYPE = "Mean";
                                if (iStatisticType == 0)
                                {
                                    sVI_STATYPE = "Min";
                                }
                                else if (iStatisticType == 1)
                                {
                                    sVI_STATYPE = "Max";
                                }

                                SqlParameter[] param = new SqlParameter[] {
                                    new SqlParameter("@PLOTID", sPlotID),
                                    new SqlParameter("@MONITORTIME", sMorTime),
                                    new SqlParameter("@CROP_CODE", 10),
                                    new SqlParameter("@VI_TYPE", sVIType),
                                    new SqlParameter("@VI_STATYPE", sVI_STATYPE),

                                    new SqlParameter("@VI_VALUE", sStatisticResult),
                                    new SqlParameter("@SENSORTYPE", sSensorCode),
                                    new SqlParameter("@RECORDTIME", DateTime.Now)
                                };
                                result = DataBaseOperate.InsertDatabase("insert_Plot_VI", param);
                            }
                        }
                    }
                    else
                    {
                        for (int iStatisticType = 0; iStatisticType < 3; iStatisticType++)
                        {
                            ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, iStatisticType, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                        }
                    }
                }

                MessageBox.Show("统计入库完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.btn_ok.Enabled = true;
                //this.btn_OpenOutPut.Visible = true;
                this.progressBar.Visible = false;
            }
            catch (Exception ex)
            {
                this.progressBar.Visible = false;
                MessageBox.Show(ex.Message);
                return;
            }
            #endregion
        }