/// <summary> /// 输出类型数据绑定,从XML文件中获取 /// </summary> public void ComBoxDataBind(string strVectorFile) { char[] strVectorFileList = strVectorFile.ToCharArray(); StringBuilder sSBuilder = new StringBuilder(300); GdalAlgInterface.GetVectorFields(strVectorFileList, sSBuilder, 300); //MessageBox.Show("sSBuilder=" + sSBuilder); List <string> list = getListByStringSplit(sSBuilder.ToString()); this.cbx_FieldName.DataSource = list; }
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_ImageOutPath.Text.Equals("")) { MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion this.btn_ok.Enabled = false; #region 界面参数获取 string sFiles = ""; foreach (ListViewItem item in this.listViewImage.Items) { string sFile = item.SubItems[0].Text.Trim(); sFiles += sFile + "*"; } sFiles = sFiles.Substring(0, sFiles.Length - 1); string sImageOutPath = this.txt_ImageOutPath.Text.Trim(); #endregion #region 执行合成 this.progressBar.Visible = true; try { ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo); IntPtr pre = this.Handle; int ire = 0; char[] strInFileList = sFiles.ToCharArray(); char[] strOutFileList = sImageOutPath.ToCharArray(); ire = GdalAlgInterface.ImageLayerStack(strInFileList, strOutFileList, 0, false, "GTiff", 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 }
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_ImageOutPath.Text.Equals("")) { MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sImageOutPath = this.txt_ImageOutPath.Text.Trim(); #endregion this.btn_ok.Enabled = false; #region 界面参数获取 #endregion #region 执行合成 this.progressBar.Visible = true; try { foreach (ListViewItem item in this.listViewImage.Items) { string sFile = item.SubItems[0].Text.Trim(); if (!sFile.Contains("WFV") && !sFile.Contains("PMS") && !sFile.Contains("wfv") && !sFile.Contains("pms")) { MessageBox.Show("请输入包含传感器名称WFV或者PMS的影像!"); return; } string sFileName = Path.GetFileNameWithoutExtension(sFile); string sSensorType = sFileName.Substring(4, 4); sSensorType = sSensorType.ToUpper(); string[] BandCoefficients = new string[4]; switch (sSensorType) { case "PMS1": BandCoefficients[0] = "*0.2082+4.6186"; //第一波段定标系数 BandCoefficients[1] = "*0.1672+4.8768"; //第二波段定标系数 BandCoefficients[2] = "*0.1748+4.8924"; //第三波段定标系数 BandCoefficients[3] = "*0.1883-9.4771"; //第四波段定标系数 break; case "PMS2": BandCoefficients[0] = "*0.2072+7.5348"; //第一波段定标系数 BandCoefficients[1] = "*0.1776+3.9395"; //第二波段定标系数 BandCoefficients[2] = "*0.177-1.7445"; //第三波段定标系数 BandCoefficients[3] = "*0.1909-7.2053"; //第四波段定标系数 break; case "WFV1": BandCoefficients[0] = "*0.1709-0.0039"; //第一波段定标系数 BandCoefficients[1] = "*0.1398-0.0047"; //第二波段定标系数 BandCoefficients[2] = "*0.1195-0.0030"; //第三波段定标系数 BandCoefficients[3] = "*0.1338-0.0274"; //第四波段定标系数 break; case "WFV2": BandCoefficients[0] = "*0.1588+5.5303"; //第一波段定标系数 BandCoefficients[1] = "*0.1515-13.642"; //第二波段定标系数 BandCoefficients[2] = "*0.1251-15.382"; //第三波段定标系数 BandCoefficients[3] = "*0.1209-7.985"; //第四波段定标系数 break; case "WFV3": BandCoefficients[0] = "*0.1556+12.28"; //第一波段定标系数 BandCoefficients[1] = "*0.1700-7.9336"; //第二波段定标系数 BandCoefficients[2] = "*0.1392-7.031"; //第三波段定标系数 BandCoefficients[3] = "*0.1354-4.3578"; //第四波段定标系数 break; case "WFV4": BandCoefficients[0] = "*0.1819+3.6469"; //第一波段定标系数 BandCoefficients[1] = "*0.1762-13.54"; //第二波段定标系数 BandCoefficients[2] = "*0.1463-10.998"; //第三波段定标系数 BandCoefficients[3] = "*0.1522-12.142"; //第四波段定标系数 break; } //默认为NDVI计算输入波段数组 int[] nBand = new int[1]; string sOutFilePath = sImageOutPath + "\\" + sFileName; sOutFilePath = sOutFilePath.Replace("\\\\", "\\"); //波段组合文件名组合参数 string sLayerStackName = ""; List <string> filelist = new List <string>(); for (int i = 1; i <= 4; i++) { string strFormula = "b" + i + "*1" + BandCoefficients[i - 1];//默认为NDVI计算公式 nBand[0] = i; string sOutFileName = sOutFilePath + "_Band" + i + ".tif"; //组装波段组合的输入参数名,所有文件名组成一个字符串,中间用*连接 sLayerStackName += sOutFileName + "*"; filelist.Add(Path.GetFileName(sOutFileName)); ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo); IntPtr pre = this.Handle; int ire = 0; char[] strInFileList = sFile.ToCharArray(); char[] strOutFileList = sOutFileName.ToCharArray(); ire = GdalAlgInterface.ImageCalculate(strInFileList, strOutFileList, strFormula, nBand, "GTiff", pd, pre); //Console.Write(ire.ToString()); } //波段叠加输入波段影像 sLayerStackName = sLayerStackName.Substring(0, sLayerStackName.Length - 1); //波段组合后输出影像文件名 string sLayerStackResult = sImageOutPath + "\\" + sFileName + "_radiocorrect.tif"; ProgressFunc pd2 = new ProgressFunc(this.ProgressBarInfo); IntPtr pre2 = this.Handle; int ire2 = 0; char[] strLayerInFileList = sLayerStackName.ToCharArray(); char[] strLayerOutFileList = sLayerStackResult.ToCharArray(); ire2 = GdalAlgInterface.ImageLayerStack(strLayerInFileList, strLayerOutFileList, 0, false, "GTiff", pd2, pre2); //MessageBox.Show("波段合成完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.btn_ok.Enabled = true; //this.btn_OpenOutPut.Visible = true; //this.progressBar.Visible = false; FileManage pFileManage = new FileManage(); pFileManage.DeteleFiles(filelist, sImageOutPath + "\\"); } } catch (Exception ex) { this.progressBar.Visible = false; MessageBox.Show(ex.Message); return; } finally { MessageBox.Show("波段提取并辐射定标完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.btn_ok.Enabled = true; //this.btn_OpenOutPut.Visible = true; this.progressBar.Visible = false; } #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_ok_Click(object sender, EventArgs e) { #region 输入与输出路径条件判断 if (this.txt_ImageInput.Text.Equals("")) { MessageBox.Show("请选择输入矢量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //if (this.cbx_FormatType.SelectedValue.ToString().Equals("请选择")) if (this.cbx_FormatType.Text.Equals("")) { MessageBox.Show("请选择转换字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sResolution = this.txt_resolution.Text; if (sResolution.Equals("")) { MessageBox.Show("请输入分辨率数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int NResolution = 30; bool BResolution = int.TryParse(sResolution, out NResolution); if (!BResolution) { MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.txt_ImageOutPath.Text.Equals("")) { MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion this.btn_ok.Enabled = false; #region 界面参数获取 string strVectorFile = txt_ImageInput.Text.Trim(); //string strField = this.cbx_FormatType.SelectedValue.ToString(); string strField = this.cbx_FormatType.Text.Trim(); string strRasterFile = this.txt_ImageOutPath.Text.Trim(); //string sFileName = FileManage.getFileName(strVectorFile); string sFileName = Path.GetFileNameWithoutExtension(strVectorFile); strRasterFile = strRasterFile + "\\" + sFileName + ".tif"; #endregion #region 调用转换算法 //声明进度信息回调函数 ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo); IntPtr p = this.Handle; int ire = 0; this.progressBar.Visible = true; try { char[] strVectorFileList = strVectorFile.ToCharArray(); char[] strRasterFileList = strRasterFile.ToCharArray(); char[] strFieldList = strField.ToCharArray(); ire = GdalAlgInterface.ShpRasterize(strVectorFileList, strRasterFileList, NResolution, 2, 0, strFieldList, "GTiff", pd, p); 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 }
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_ok_Click(object sender, EventArgs e) { #region 输入与输出路径条件判断 if (this.txt_ImageInput.Text.Equals("")) { MessageBox.Show("请选择输入影像文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sX = this.txt_X.Text; if (sX.Equals("")) { MessageBox.Show("请输入X方向采样比!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } double NX = 1.0; bool BX = double.TryParse(sX, out NX); if (!BX) { MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sY = this.txt_Y.Text; if (sY.Equals("")) { MessageBox.Show("请输入Y方向采样比!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } double NY = 1.0; bool BY = double.TryParse(sY, out NY); if (!BY) { MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.txt_ImageOutPath.Text.Equals("")) { MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion this.btn_ok.Enabled = false; #region 界面参数获取 string strInFile = txt_ImageInput.Text.Trim(); //string strField = this.cbx_FormatType.SelectedValue.ToString(); string strX = this.txt_X.Text.Trim(); string strY = this.txt_Y.Text.Trim(); string strOutFile = this.txt_ImageOutPath.Text.Trim(); //string sFileName = FileManage.getFileName(strVectorFile); string sFileName = Path.GetFileNameWithoutExtension(strInFile); strOutFile = strOutFile + "\\" + sFileName + "_" + strX + "_" + strY + ".tif"; #endregion #region 调用转换算法 //声明进度信息回调函数 ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo); IntPtr p = this.Handle; int ire = 0; this.progressBar.Visible = true; try { char[] strInFileList = strInFile.ToCharArray(); char[] strOutFileList = strOutFile.ToCharArray(); double DX = double.Parse(strX); double DY = double.Parse(strY); ire = GdalAlgInterface.ImageResample(strInFileList, strOutFileList, DX, DY, 0, "GTiff", pd, p); 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 }
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_ImageOutPath.Text.Equals("")) { MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sImageOutPath = this.txt_ImageOutPath.Text.Trim(); #endregion this.btn_ok.Enabled = false; #region 界面参数获取 #endregion #region 执行合成 this.progressBar.Visible = true; try { foreach (ListViewItem item in this.listViewImage.Items) { string sFile = item.SubItems[0].Text.Trim(); string strFormula = "(b4-b3)/(b4+b3)*1.0"; //默认为NDVI计算公式 string sFiles = sFile + "*" + sFile; //默认为NDVI计算输入数据个数,只用到2个波段,所以输入2遍,中间用*隔开 //默认为NDVI计算输入波段数组 int[] nBand = new int[2]; nBand[0] = 3; nBand[1] = 4; string sOutFileName = sImageOutPath + "\\" + Path.GetFileNameWithoutExtension(sFile); sOutFileName = sOutFileName.Replace("\\\\", "\\"); switch (this.cbx_VIType.Text.Trim()) { case "NDVI": //sFiles = sFile + "*" + sFile; //strFormula = "(b4-b3)/(b4+b3)*1.0"; //nBand = new int[2]; //nBand[0] = 3; //nBand[1] = 4; sOutFileName = sOutFileName + "_NDVI.tif"; break; case "EVI": sFiles = sFile + "*" + sFile + "*" + sFile; strFormula = "2.5*(b4-b3)/(b4+6*b3-7.5*b1+1)"; nBand = new int[3]; nBand[0] = 1; nBand[1] = 3; nBand[2] = 4; sOutFileName = sOutFileName + "_EVI.tif"; break; case "Band1": sFiles = sFile; strFormula = "b1*1.0"; nBand = new int[1]; nBand[0] = 1; sOutFileName = sOutFileName + "_Band1.tif"; break; case "Band2": sFiles = sFile; strFormula = "b2*1.0"; nBand = new int[1]; nBand[0] = 2; sOutFileName = sOutFileName + "_Band2.tif"; break; case "Band3": sFiles = sFile; strFormula = "b3*1.0"; nBand = new int[1]; nBand[0] = 3; sOutFileName = sOutFileName + "_Band3.tif"; break; case "Band4": sFiles = sFile; strFormula = "b4*1.0"; nBand = new int[1]; nBand[0] = 4; sOutFileName = sOutFileName + "_Band4.tif"; break; } ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo); IntPtr pre = this.Handle; int ire = 0; char[] strInFileList = sFiles.ToCharArray(); char[] strOutFileList = sOutFileName.ToCharArray(); ire = GdalAlgInterface.ImageCalculate(strInFileList, strOutFileList, strFormula, nBand, "GTiff", pd, pre); //Console.Write(ire.ToString()); } } catch (Exception ex) { this.progressBar.Visible = false; MessageBox.Show(ex.Message); return; } finally { MessageBox.Show("指数计算完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.btn_ok.Enabled = true; //this.btn_OpenOutPut.Visible = true; this.progressBar.Visible = false; } #endregion }
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 strMskFile = this.txt_ReferenceImage.Text.Trim(); if (this.txt_ImageOutPath.Text.Equals("")) { MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sImageOutPath = this.txt_ImageOutPath.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 sOutFileName = sImageOutPath + "\\" + Path.GetFileNameWithoutExtension(sFile); sOutFileName = sOutFileName.Replace("\\\\", "\\"); sOutFileName = sOutFileName + "_Clip.tif"; ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo); IntPtr pre = this.Handle; int ire = 0; char[] strInFileList = sFile.ToCharArray(); char[] strOutFileList = sOutFileName.ToCharArray(); char[] pszMskFileList = strMskFile.ToCharArray(); //int[] nBand = new int[1]; //nBand[0] = 1; if (Path.GetExtension(strMskFile).Contains("shp")) { ire = GdalAlgInterface.ImageSubsetAoi(strInFileList, strOutFileList, pszMskFileList, null, null, 0, "GTiff", pd, pre); } else { ire = GdalAlgInterface.ImageSubsetMask(strInFileList, strOutFileList, pszMskFileList, null, 0, "GTiff", 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 }
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 }
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 }