熟悉Skyline的朋友會知道,在TerraBuilder和TerraExplorer Pro軟件的安裝目錄里,提供了很多個小工具(exe程序);
雖然我們看不到這些小工具的源代碼,但我們還是可以在自定義的開發環境中來調用它們的;
尤其是可以用來實現一些批量化操作和自動化操作;
常用的小工具:
MakeXpl.exe;
MakeCPT.exe;
Triangulate Irregular Elevation Grid.exe;
Convert XYZ ASCII Elevation.exe;
Convert Z ASCII Elevation.exe;
Gather Tiled Files.exe;
Split and Merge MPU-MPT files.exe
......
用C#調用cmd執行命令,網上可以找到很多使用的方法和參數的設置示例代碼;
#region "運行工具將XYZ轉換成TRI"
//運行工具將XYZ轉換成TRI
//趙賀 2016.8.19
//輸入XYZ文件路徑和TRI文件路徑及采樣精度
private void XYZtoTRI(String inputFile, String outputFile, Double resolution)
{
String programName = TempDataPath + @"\ttd.exe"; ;
String cmd = "\"" + programName + "\"" + " -InputFile " + inputFile + " -OutputFile " + outputFile + " -Resolution " + resolution + " &exit";
using (Process proc = new Process())
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.ErrorDialog = false;
//proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.StandardInput.WriteLine(cmd);
//proc.StandardInput.AutoFlush = true;
//獲取cmd窗口的輸出信息
proc.StandardOutput.ReadToEnd();
proc.WaitForExit();//等待程序執行完退出進程
proc.Close();
}
}
#endregion
關於如何C#運行cmd,參考了園子里其他朋友的博客:http://www.cnblogs.com/babycool/p/3570648.html#undefined
