| | |
| | | } |
| | | |
| | | /// <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,qgis_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) |
| | |
| | | /// <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); |
| | | |
| | |
| | | //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)) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <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; |
| | |
| | | /// </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> |