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; } #endregion this.btn_classstatis.Enabled = false; #region 调用IDL程序 //IDLSav的路径 string sIDLSavPath = FileManage.getApplicatonPath(); sIDLSavPath = sIDLSavPath + "IDLSav\\GetFileHist.pro"; string sCSVPath = FileManage.getApplicatonPath(); string sFullName = sCSVPath + "AllSense.csv"; COM_IDL_connectLib.COM_IDL_connectClass oCom = new COM_IDL_connectLib.COM_IDL_connectClass(); try { //初始化 oCom.CreateObject(0, 0, 0); //参数设置 oCom.SetIDLVariable("File", sImageInput); oCom.SetIDLVariable("CSVPath", sFullName); //oCom.SetIDLVariable("Background", "0"); //编译IDL功能源码 oCom.ExecuteString(".compile '" + sIDLSavPath + "'"); //执行计算 oCom.ExecuteString("GetFileHist,file,CSVPath,DataArray=DataArray"); //获取计算结果 object objArr = oCom.GetIDLVariable("DataArray"); //MessageBox.Show(objArr.ToString()); if (objArr == null) { MessageBox.Show("输入影像有误,请重新选择分类后影像!"); return; } //将对象转为一维数组 string[] arrStatistic = (string[])objArr; //表头 string[] arrName = { "作物类型", "面积(亩)", "所占比例(%)" }; //数组行按","拆分后转DataTable DataTable dt = StringFormater.Convert(arrName, arrStatistic); //数据绑定 BindDataSource(dt); oCom.DestroyObject(); //MessageBox.Show("影像裁剪完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.btn_classstatis.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion }
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 }
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 }
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 }