From f0586817d86bb5b86efce42230e872fd9a254d69 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 29 八月 2023 20:12:24 +0800 Subject: [PATCH] 1 --- ExportMap/cs/Tools.cs | 82 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 79 insertions(+), 3 deletions(-) diff --git a/ExportMap/cs/Tools.cs b/ExportMap/cs/Tools.cs index 4603d02..45372bb 100644 --- a/ExportMap/cs/Tools.cs +++ b/ExportMap/cs/Tools.cs @@ -6,6 +6,7 @@ using System.Configuration; using System.Data.Common; using System.Diagnostics; +using System.Drawing; using System.IO; using System.Linq; using System.Net; @@ -16,7 +17,7 @@ using System.Runtime.Serialization.Formatters.Binary; using System.Security.AccessControl; using System.Security.Principal; -using System.Web; +using System.Web.WebSockets; namespace ExportMap.cs { @@ -197,7 +198,7 @@ /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns> public static string ExecCmd(SysTask task, List<string> list, bool isOut = false) { - string str = null; + string str; try { Process p = new Process(); @@ -304,7 +305,58 @@ if (p != null) { p.Close(); - p = null; + } + } + return str; + } + + /// <summary> + /// 鎵ц鍛戒护 + /// </summary> + public static string ExecCmd(List<string> list, ref string rs) + { + 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 so = p.StandardOutput; + StreamReader se = p.StandardError; + + LogOut.Info("cmd = " + string.Join("锛�", list)); + si.AutoFlush = true; + foreach (string cmd in list) + { + si.WriteLine(cmd); + } + si.WriteLine("exit"); + + rs = so.ReadToEnd(); + str = se.ReadToEnd(); + + se.Close(); + so.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; @@ -345,6 +397,30 @@ } /// <summary> + /// 鑾峰彇EPSG浠g爜 + /// </summary> + public static string GetEPSG(string file) + { + string gdalPath = GetSetting("gdalPath"); + string cmd = string.Format("{0}\\gdalsrsinfo.exe \"{1}\" -o epsg", gdalPath, file); + + string rs = null; + string ostr = ExecCmd(new List<string> { cmd }, ref rs); + if (string.IsNullOrEmpty(rs)) return null; + + string[] strs = rs.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + foreach (string str in strs) + { + if (str.Contains("EPSG:")) + { + return str; + } + } + + return null; + } + + /// <summary> /// 璁剧疆鍗曚綋妯″瀷鍙傛暟 /// </summary> public static void SetIsModel(XYZArgs args, List<SysMeta> list) -- Gitblit v1.9.3