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

C# 调用6S.exe

admin4年前 (2020-04-25)遥感3471

代码来自此文章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://lovedm.club/?id=42

分享给朋友:

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

ENVI计算光谱一阶微分

ENVI计算光谱一阶微分

首先在Display菜单中选择Spectral Library Viewer,如图:再选择Import,导入ASCII文件,选择文件后,按照自己的数据选择以下选项:点击OK后,波谱曲线会绘制出来,如下:在ToolBox中找到Spectral中的Spectral Math工具,双击打开工具,工具中输入...

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

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

利用GDAL进行波段合成

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

Python embed版本安装使用

Python embed版本安装使用

最近一个项目需要使用Python脚本后台处理数据,但是用到了几个第三方包,客户使用时部署环境比较麻烦,查找资料后可以使用Python的embed版本,也就是嵌入式版本。好处是所有用到的第三方库直接安装到目录下,部署时直接拷贝走文件夹即可,无需其它配置。下面记录一下安装使用流程。 下载Pytho...

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

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