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

C# 调用6S.exe

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

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

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

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

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

代码:

  1.  static void Main(string[] args)
  2.         {
  3.             string SixSexe_dir = System.AppDomain.CurrentDomain.BaseDirectory; //项目文件夹
  4.             Console.WriteLine(SixSexe_dir);
  5.  
  6.             string SixSexe_path = SixSexe_dir + "\6S.exe"; //6s.exe放在了bin/debug/6SModel目录下
  7.             string intxt_path = SixSexe_dir + "\in.txt"; //参数文件
  8.  
  9.             try
  10.             {
  11.                 using (Process myProcess = new Process())
  12.                 {
  13.                     myProcess.StartInfo.FileName = SixSexe_path; //exe的路径
  14.                     myProcess.StartInfo.RedirectStandardInput = true;   //接受来自调用程度的输入
  15.                     myProcess.StartInfo.RedirectStandardOutput = true;  //由调用程度获取输出信息
  16.                     myProcess.StartInfo.UseShellExecute = false;        //是否使用操作系统的Shell启动
  17.                     myProcess.StartInfo.CreateNoWindow = true;         //不显示调用程序的窗口
  18.                     myProcess.Start(); //开启进程
  19.                     // 向进程中输出参数
  20.                     StreamWriter myStreamWriter = myProcess.StandardInput;
  21.                     String inputText;
  22.                     int numLines = 0;
  23.                     FileStream fs = new FileStream(intxt_path, FileMode.Open);//参数文件,按行排列。
  24.                     StreamReader sr = new StreamReader(fs);
  25.                     inputText = sr.ReadLine();
  26.                     while (inputText != null)
  27.                     {
  28.                         myStreamWriter.WriteLine(inputText);//程序的核心,向目标程序中写入数据。
  29.                         inputText = sr.ReadLine();
  30.                         numLines++;//行数统计
  31.                     }
  32.                     fs.Close();
  33.                     myStreamWriter.Close();
  34.  
  35.  
  36.                     // 获得输出内容
  37.                     string out_str = myProcess.StandardOutput.ReadToEnd();
  38.                     //  Console.WriteLine(out_str);
  39.  
  40.                     FileStream outToFile = new FileStream(SixSexe_dir + "\out.txt", FileMode.OpenOrCreate);
  41.                     StreamWriter streamWriter = new StreamWriter(outToFile);
  42.                     streamWriter.Write(out_str);
  43.                     streamWriter.Close();
  44.  
  45.                     // 提取目标结果
  46.                     string[] lines = out_str.Split('
  47. ');
  48.                     string xa_xb_xc = lines[163];
  49.  
  50.                     for (int i = 155; i <= 167; i++)
  51.                     {
  52.                         Console.WriteLine(lines[i]);
  53.                     }
  54.  
  55.  
  56.                     string extra1 = xa_xb_xc.Substring(49, 7);
  57.                     string extra2 = xa_xb_xc.Substring(58, 7);
  58.                     string extra3 = xa_xb_xc.Substring(67, 7);
  59.                     Console.WriteLine(extra1);
  60.                     Console.WriteLine(extra2);
  61.                     Console.WriteLine(extra3);
  62.  
  63.                     myProcess.Close();
  64.                 }
  65.             }
  66.             catch (Exception e)
  67.             {
  68.                 Console.WriteLine(e.Message);
  69.             }
  70.  
  71.             Console.ReadLine();
  72.  
  73.         }

附件:Debug.zip

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

part1part2part3

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

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

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

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

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...

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...

葵花数据投影程序

下载的这个链接 https://download.csdn.net/download/weixin_42662293/86183693 的代码,原代码是用C++写的,平台无关,将原代码复刻为C#代码,代码如下,可以直接复制创建项目去用。 using System; using System.Co...