From 9d9f97954c5eef9ee909eda39f082e0f19247111 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 21 三月 2023 14:14:29 +0800 Subject: [PATCH] 1 --- ExportMap/cs/XYZUtils.cs | 120 ++++++++++++++++++++++++++++-------------------------------- 1 files changed, 56 insertions(+), 64 deletions(-) diff --git a/ExportMap/cs/XYZUtils.cs b/ExportMap/cs/XYZUtils.cs index c809e7c..b9f244b 100644 --- a/ExportMap/cs/XYZUtils.cs +++ b/ExportMap/cs/XYZUtils.cs @@ -43,6 +43,29 @@ } /// <summary> + /// bat璺緞 + /// </summary> + public static string BatPath + { + get + { + return @"C:\Program Files\QGIS 3.16\bin\"; + } + } + + /// <summary> + /// 鍩虹bat鏂囦欢 + /// </summary> + public static string BaseBat + { + get + { + // python-qgis-ltr.bat锛宷gis_process-qgis-ltr.bat + return @"C:\Program Files\QGIS 3.16\bin\qgis_process-qgis-ltr.bat"; + } + } + + /// <summary> /// 鑾峰彇鍙戝竷鍦板潃 /// </summary> public static string GetReleaseUrl(string dircode) @@ -58,10 +81,12 @@ /// <returns>鏁版嵁鍙戝竷ID</returns> public static int Generate(XYZArgs args, ref string err) { - List<SysMeta> list = selectMetas(args.ids, "and type in ('tif', 'tiff', 'img')"); + List<SysMeta> list = SelectMetas(args.ids, "and type in ('tif', 'tiff', 'img')"); if (null == list || list.Count == 0) return 0; - string tifFile = Path.Combine(Tool.TempDir, ExportUtil.DateStr + ".txt"); + string dateStr = ExportUtil.DateStr; + string batFile = Path.Combine(BatPath, dateStr + ".bat"); + string tifFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".txt"); string xyzPath = Path.Combine(SGUtils.LFData, "2d\\tiles", args.dircode); if (!Directory.Exists(xyzPath)) Directory.CreateDirectory(xyzPath); @@ -80,10 +105,17 @@ //string newPy = tifFile.Replace(".txt", ".py").Replace("\\", "\\\\"); //File.WriteAllText(newPy, pyText); //string cmd = string.Format("exec(open('{0}', 'r', encoding='utf-8').read()) & exit()", newPy); + //err = ExecCmd(cmd); - err = ExecCmd(cmd); + //List<string> cmds = GetCmds(cmd); + //err = Tools.ExecCmd(cmds); + + List<string> cmds = GetCmds(batFile, cmd); + err = Tools.ExecCmd(cmds); if (File.Exists(tifFile)) File.Delete(tifFile); + if (File.Exists(batFile)) File.Delete(batFile); + string viewFile = Path.Combine(xyzPath, "view.html"); if (File.Exists(viewFile)) { @@ -96,12 +128,23 @@ } /// <summary> + /// 鑾峰彇鍛戒护琛� + /// </summary> + private static List<string> GetCmds(string batFile, string cmd) + { + string str = File.ReadAllText(BaseBat) + cmd; + File.WriteAllText(batFile, str); + + return new List<string>() { "\"" + batFile + "\"" }; + } + + /// <summary> /// 鏌ヨ鍏冩暟鎹� /// </summary> - public static List<SysMeta> selectMetas(List<int> ids, string types = "") + public static List<SysMeta> SelectMetas(List<int> ids, string types = "") { string sql = string.Format("select * from lf.sys_meta where id in ({0}) {1} order by id", string.Join(",", ids), types); - DataTable dt = Tool.DBHelper.GetDataTable(sql); + DataTable dt = Tools.DBHelper.GetDataTable(sql); List<SysMeta> list = ModelHandler.FillModel<SysMeta>(dt); return list; @@ -112,70 +155,19 @@ /// </summary> private static void WriteText(string file, List<SysMeta> list) { - string uploadFolder = Tool.GetSetting("uploadFolder"); + string uploadFolder = Tools.GetSetting("uploadFolder"); List<string> files = new List<string>(); - foreach (SysMeta meta in list) - { - string filePath = Path.Combine(uploadFolder, meta.path); - if (File.Exists(filePath)) files.Add(filePath); - } + //foreach (SysMeta meta in list) + //{ + // string filePath = Path.Combine(uploadFolder, meta.path); + // if (File.Exists(filePath)) files.Add(filePath); + //} + files.Add(@"E:\01.Data\33.DOM\2.澶у簡DOM\5154.50-415.50.tif"); + files.Add(@"E:\01.Data\33.DOM\2.澶у簡DOM\5154.50-416.00.tif"); string str = string.Join("\n", files); File.WriteAllText(file, str); - } - - /// <summary> - /// 鎵цCMD - /// </summary> - /// <param name="cmd">鍛戒护琛�</param> - /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns> - public static String ExecCmd(string cmd) - { - string str = null; - try - { - Process 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 = " + cmd); - si.AutoFlush = true; - si.WriteLine("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\""); - si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\qgis_process-qgis-ltr.bat\""); - //si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\""); - //si.WriteLine("exit()"); - si.WriteLine(cmd); - si.WriteLine("exit"); - - string info = so.ReadToEnd(); - str = se.ReadToEnd(); - - if (!string.IsNullOrEmpty(info)) LogOut.Debug(info); - if (!string.IsNullOrEmpty(str)) LogOut.Error(str); - if (p.HasExited == false) p.Kill(); - - se.Close(); - so.Close(); - si.Close(); - p.Close(); - } - catch (Exception ex) - { - LogOut.Error(ex.StackTrace); - str = ex.Message; - } - - return str; } /// <summary> -- Gitblit v1.9.3