管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2022-11-10 00700f5ef12d33da898e9b4391aa5b4a09828ee3
ExportMap/cs/ExportUtil.cs
@@ -119,44 +119,76 @@
        /// <param name="py">Python文件</param>
        /// <param name="qgz">QGIS工程</param>
        /// <param name="qpt">QGIS模板</param>
        public static void ExecPython(string py, string qgz, string qpt)
        /// <returns>执行结果</returns>
        public static string ExecPython(string py, string qgz, string qpt)
        {
            string str = null;
            try
            {
                string args = string.Format("{0} -qgz {1} -qpt {2}", py, qgz, qpt);
                string cmdText = string.Format("python {0} -qgz {1} -qpt {2}", py, qgz, qpt);
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.ErrorDialog = true;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                p.StartInfo.RedirectStandardError = false;
                p.StartInfo.FileName = "python";
                p.StartInfo.Arguments = args;
                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; // 标准错误流
                si.AutoFlush = true;
                si.WriteLine(cmdText);
                si.WriteLine("exit");
                string info = so.ReadToEnd();
                str = se.ReadToEnd();
                if (p.HasExited == false)
                {
                    p.Kill();
                }
                si.Close();
                so.Close();
                se.Close();
                p.Close();
            }
            catch
            catch (Exception ex)
            {
                str = ex.Message;
            }
            return str;
        }
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="args">出图参数</param>
        public static void Generate(ExportArgs args)
        /// <returns>图片路径</returns>
        public static string Generate(ExportArgs args)
        {
            string date = DateStr;
            string sub = GetExportSubFolder();
            string qgz = "Test.qgz";
            args.imgPath = sub + "/" + date + ".png";
            args.imgPath = sub + "\\" + date + ".png";
            args.qpt = date + ".qpt";
            args.SetDefault();
            CreateTemplate(args);
            string info = ExecPython(PyFile, qgz, args.qpt);
            ExecPython(PyFile, qgz, args.qpt);
            string qptFile = Path.Combine(SourcesPath, args.qpt);
            if (File.Exists(qptFile))
            {
                File.Delete(qptFile);
            }
            return args.imgPath;
        }
        /// <summary>