using ExportMap.db; using ExportMap.Models; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Web; namespace ExportMap.cs { public class XYZUtils { private static string pyFile; /// /// 获取Python文件 /// public static string PyFile { get { if (string.IsNullOrWhiteSpace(pyFile)) { pyFile = Path.Combine(ExportUtil.SourcesPath, "xyz.py"); } return pyFile; } } /// /// QGIS工程 /// public static string Qgz { get { //return Path.Combine(ExportUtil.SourcesPath, "xyz.qgz"); return "xyz.qgz"; } } /// /// 生成 /// /// XYZ参数 /// 错误信息 /// 数据发布ID public static int Generate(XYZArgs args, ref string err) { string tifFile = Path.Combine(Tool.TempDir, ExportUtil.DateStr + ".txt"); string xyzPath = Path.Combine(SGUtils.LFData, "2d\\tiles", args.id.ToString()); if (!Directory.Exists(xyzPath)) Directory.CreateDirectory(xyzPath); List list = selectMetas(args.ids, "and type in ('tif', 'tiff', 'img')"); if (null == list || list.Count == 0) return 0; WriteText(tifFile, list); string cmd = string.Format("python \"{0}\" -qgz {1} -file \"{2}\" -out \"{3}\" -min {4} -max {5}", PyFile, Qgz, tifFile, xyzPath, args.min, args.max); err = Tool.ExecCmd(cmd, true); if (File.Exists(tifFile)) File.Delete(tifFile); string viewFile = Path.Combine(xyzPath, "view.html"); return File.Exists(viewFile) ? args.id : 0; } /// /// 查询元数据 /// public static List selectMetas(List 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); List list = ModelHandler.FillModel(dt); return list; } /// /// 写文本文件 /// private static void WriteText(string file, List list) { string uploadFolder = Tool.GetSetting("uploadFolder"); List files = new List(); foreach (SysMeta meta in list) { string filePath = Path.Combine(uploadFolder, meta.path); if (File.Exists(filePath)) files.Add(filePath); } string str = string.Join("\n", files); File.WriteAllText(file, str); } } }