管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-07-23 a55f5510720c2eda302c771021e84c7bd2ee47c3
1
已修改1个文件
106 ■■■■ 文件已修改
SimuTools/Tools/Handle.cs 106 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/Tools/Handle.cs
@@ -15,6 +15,7 @@
{
    public class Handle
    {
        #region 成员变量
        public static readonly int MAX = 256 * 256;
        public static readonly double WaterHeightOffset = 1.0;
@@ -22,6 +23,7 @@
        public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
        public static readonly string GdalPath = ConfigurationManager.AppSettings["gdalPath"];
        #endregion
        /// <summary>
        /// 运行
@@ -147,57 +149,6 @@
            Dataset destDs = Gdal.Warp(dest, new Dataset[] { ds }, warpAppOptions, null, null);
            destDs.Dispose();
        }
        /// <summary>
        /// 重采样 *
        /// </summary>
        private static void Resample(string source, string dest, int width, int height)
        {
            // https://blog.51cto.com/u_16099346/6691820
            string cmd = string.Format("{0}gdalwarp.exe -t_srs {1} -ts {2} {3} -r {4} -of GTiff \"{5}\" \"{6}\"", GdalPath, "EPSG:4326", width, height, "bilinear", source, dest);
            string err = ExecExe(cmd);
        }
        /// <summary>
        /// 执行命令
        /// </summary>
        public static string ExecExe(string cmd)
        {
            string str = null;
            Process p = null;
            try
            {
                p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.Start();
                StreamWriter si = p.StandardInput;
                StreamReader se = p.StandardError;
                si.AutoFlush = true;
                si.WriteLine(cmd);
                si.WriteLine("exit");
                str = se.ReadToEnd();
                se.Close();
                si.Close();
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                str = ex.Message;
            }
            finally
            {
                if (p != null) p.Close();
            }
            return str;
        }
        /// <summary>
@@ -606,5 +557,58 @@
            }
        }
        #endregion
        #region 暂时不用
        /// <summary>
        /// 重采样 *
        /// </summary>
        private static void Resample(string source, string dest, int width, int height)
        {
            // https://blog.51cto.com/u_16099346/6691820
            string cmd = string.Format("{0}gdalwarp.exe -t_srs {1} -ts {2} {3} -r {4} -of GTiff \"{5}\" \"{6}\"", GdalPath, "EPSG:4326", width, height, "bilinear", source, dest);
            string err = ExecExe(cmd);
        }
        /// <summary>
        /// 执行命令
        /// </summary>
        public static string ExecExe(string cmd)
        {
            string str = null;
            Process p = null;
            try
            {
                p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.Start();
                StreamWriter si = p.StandardInput;
                StreamReader se = p.StandardError;
                si.AutoFlush = true;
                si.WriteLine(cmd);
                si.WriteLine("exit");
                str = se.ReadToEnd();
                se.Close();
                si.Close();
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                str = ex.Message;
            }
            finally
            {
                if (p != null) p.Close();
            }
            return str;
        }
        #endregion
    }
}