当前位置:首页 > 遥感 > 正文内容

C# 调用6S.exe

admin5年前 (2020-04-25)遥感4408

代码来自此文章https://blog.csdn.net/summer_dew/article/details/91988258

我做了一点点修改,增加了输出结果到文档的功能,正则表达式实在是写不来,笨方法用字符串的方法截取的,输出大气校正的结果

输入文件为in.txt, 输出文件为out.txt

运行 调用6S模型.exe 即可

代码:

 static void Main(string[] args)
        {
            string SixSexe_dir = System.AppDomain.CurrentDomain.BaseDirectory; //项目文件夹
            Console.WriteLine(SixSexe_dir);

            string SixSexe_path = SixSexe_dir + "\6S.exe"; //6s.exe放在了bin/debug/6SModel目录下
            string intxt_path = SixSexe_dir + "\in.txt"; //参数文件

            try
            {
                using (Process myProcess = new Process())
                {
                    myProcess.StartInfo.FileName = SixSexe_path;		//exe的路径
                    myProcess.StartInfo.RedirectStandardInput = true;   //接受来自调用程度的输入
                    myProcess.StartInfo.RedirectStandardOutput = true;  //由调用程度获取输出信息
                    myProcess.StartInfo.UseShellExecute = false;        //是否使用操作系统的Shell启动
                    myProcess.StartInfo.CreateNoWindow = true;         //不显示调用程序的窗口
                    myProcess.Start();	//开启进程
                    // 向进程中输出参数
                    StreamWriter myStreamWriter = myProcess.StandardInput;
                    String inputText;
                    int numLines = 0;
                    FileStream fs = new FileStream(intxt_path, FileMode.Open);//参数文件,按行排列。
                    StreamReader sr = new StreamReader(fs);
                    inputText = sr.ReadLine();
                    while (inputText != null)
                    {
                        myStreamWriter.WriteLine(inputText);//程序的核心,向目标程序中写入数据。
                        inputText = sr.ReadLine();
                        numLines++;//行数统计
                    }
                    fs.Close();
                    myStreamWriter.Close();


                    // 获得输出内容
                    string out_str = myProcess.StandardOutput.ReadToEnd();
                    //  Console.WriteLine(out_str);

                    FileStream outToFile = new FileStream(SixSexe_dir + "\out.txt", FileMode.OpenOrCreate);
                    StreamWriter streamWriter = new StreamWriter(outToFile);
                    streamWriter.Write(out_str);
                    streamWriter.Close();

                    // 提取目标结果
                    string[] lines = out_str.Split('
');
                    string xa_xb_xc = lines[163];

                    for (int i = 155; i <= 167; i++)
                    {
                        Console.WriteLine(lines[i]);
                    }


                    string extra1 = xa_xb_xc.Substring(49, 7);
                    string extra2 = xa_xb_xc.Substring(58, 7);
                    string extra3 = xa_xb_xc.Substring(67, 7);
                    Console.WriteLine(extra1);
                    Console.WriteLine(extra2);
                    Console.WriteLine(extra3);

                    myProcess.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();

        }

附件:Debug.zip

顺便把6S手册也挂出来吧,官网不好下,文件分成了三部分包括原理,代码介绍等,全英文看懂不容易。

part1part2part3

扫描二维码推送至手机访问。

版权声明:本文由lovedm.club发布,如需转载请注明出处。

本文链接:https://www.lovedm.club/?id=42

分享给朋友:

“C# 调用6S.exe” 的相关文章

ENVI大气校正

ENVI大气校正

每次找都不方便,直接搬过来 原地址:http://blog.sina.com.cn/s/blog_764b1e9d0102v59e.html目录辐射定标和大气校正    1. 概述    2.&nbs...

GDAL-3.0.1+PROJ-6.2.1+SQLite+HDF4+HDF5+VS2019编译

这次上传百度网盘了。 https://www.lovedm.club/?id=40 不要用这个了 之前的没有加上hdf文件的读取,又重新编译的。链接如下: https://pan.baidu.com/s/154blFtGE6IIcUz_b1bk4xQ 提取码:tzx8此站也可下载https:...

利用GDAL进行波段合成

顺手写的一个小工具,给出头文件和实现 主要用了GDALDataset类下面的RasterIO函数,没有用GDALBand下面的RasterIO 另外实现了一个定时器类,实际上就是之前写的一个https://www.lovedm.club/?id=98 输出文件格式为固定的GTiff,函数的第三...

国产卫星绝对辐射定标系数(2008——2022)

来自于中国资源卫星应用中心:https://www.cresda.com/zgzywxyyzx/zlxz/article/20230410112855288395031.html...

Python GDAL In GDAL 4.0, exceptions will be enabled by default

如果报错FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by de...