private void btn_InDatabase_Click(object sender, EventArgs e) { int result = 0; string sVI_TYPE = this.cbx_VIType.Text.Trim(); string sVI_STATYPE = this.cbx_StaValueType.Text.Trim(); float fVI = 0.00f; for (int i = 1; i < dtInfo.Rows.Count - 1; i++) { string str = dtInfo.Rows[i][5].ToString(); bool b = float.TryParse(str, out fVI); if (!b || str.Contains("正")) { str = "0.00"; } string sSensorType = "1"; if (this.cbx_sensortype.Text.Trim() == "WFV") { sSensorType = "3"; } SqlParameter[] param = new SqlParameter[] { new SqlParameter("@PLOTID", dtInfo.Rows[i]["地块编号"]), new SqlParameter("@MONITORTIME", dtInfo.Rows[i]["监测时间"]), new SqlParameter("@CROP_CODE", 10), new SqlParameter("@VI_TYPE", sVI_TYPE), new SqlParameter("@VI_STATYPE", sVI_STATYPE), new SqlParameter("@VI_VALUE", str), new SqlParameter("@SENSORTYPE", sSensorType), new SqlParameter("@RECORDTIME", DateTime.Now) }; result = DataBaseOperate.InsertDatabase("insert_Plot_VI", param); } if (result > 0) { MessageBox.Show("入库成功!"); } }
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 }