我们在C#中使用GDAL时,某些功能并不能像C++那样应有尽有,甚至还不如Python那么好用,因此要实现某些特定功能,可能就要迫不得已地通过cmd.exe调用GDAL工具,下以调用gdalwarp.exe为例,为正在C#中使用GDAL开发同行提供有益的参考。
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;//是否使用操作系统shell启动
process.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
process.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
process.StartInfo.RedirectStandardError = true;//重定向标准错误输出
process.StartInfo.CreateNoWindow = true;
process.Start();//启动程序
//获取gdalward.exe路径,我这里是与dll放在一起,方便其调用相关dll
var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
var executingDirectory = Path.GetDirectoryName(executingAssemblyFile);
var gdalPath = Path.Combine(executingDirectory, "gdal");
var nativePath = Path.Combine(gdalPa