目录
- 系统演示
- 数据获取
- 算法封装
- 系统
系统演示
数据获取
基于TVDI的土壤水分反演需要有地表温度和植被指数数据,该部分参考Landsat计算TVDI进行干旱监测(二)
得到两张TIF影像
算法封装
初始的.py代码参数是直接指定的,然而在封装后.exe获取输入参数和输出参数需要依靠外部赋予,所以这部分需要有改动
改成如下方式:
sys.argv依次来获取外部即将传入的参数,此处为何从1开始呢,因为sys.argv[0]代表算法本身。
在修改好参数输入方式后,可以进行封装。
在代码目录中打开cmd
输入口令
pyinstaller -F xxx.py
回车,运行
系统
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace new_tvdi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = true;
fileDialog.Title = "请选择文件";
fileDialog.Filter = "所有文件(*.*)|*.*";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string file = fileDialog.FileName;
MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Text = file;
}
}
private void Button2_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = true;
fileDialog.Title = "请选择文件";
fileDialog.Filter = "所有文件(*.*)|*.*";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string file = fileDialog.FileName;
MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox2.Text = file;
}
}
private void Button3_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "";
sfd.InitialDirectory = @"D:\workspace_java_c++";
sfd.Filter = "| *.tif";
sfd.ShowDialog();
string path = sfd.FileName;
if (path == "")
{
return;
}
textBox3.Text = path;
}
private void Button4_Click(object sender, EventArgs e)
{
string lst = textBox1.Text;
string ndvi = textBox2.Text;
string output = textBox3.Text;
string data = string.Empty;
string str = @"D:\Learn_Python\remote_sensing\遥感指数\TVDI\dist\TVDI_exe.exe" + " " + lst + " " + ndvi + " " + output;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.AutoFlush = true;
//p.StandardInput.WriteLine(str + "&exit");
p.StandardInput.WriteLine(str);
data = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
}
}