管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-06-27 2b36cb4c4e2be350663189638b9f1132f3eccd26
获取TB需要的影像、高程、shp文件
已修改2个文件
70 ■■■■ 文件已修改
ExportMap/cs/TBUtils.cs 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/cs/Tools.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/cs/TBUtils.cs
@@ -20,9 +20,9 @@
        }
        /// <summary>
        /// 获取时间客串
        /// 时间字符串
        /// </summary>
        public static string GetTime
        public static string TimeStr
        {
            get
            {
@@ -44,13 +44,18 @@
        /// <summary>
        /// 创建MPT
        /// </summary>
        public static string CreateMpt(string path, ref string err)
        public static string CreateMpt(string sourcePath, ref string err)
        {
            string tbp = null;
            string time = TimeStr;
            string targetPath = Path.Combine(Tools.TempDir, time);
            try
            {
                tbp = GetNewTbp();
                if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath);
                MoveFilesToTemp(sourcePath, targetPath);
                string tbp = GetNewTbp(time);
                string js = GetNewJs(time, tbp, targetPath);
                return null;
            }
@@ -62,18 +67,17 @@
            }
            finally
            {
                if (tbp != null && File.Exists(tbp)) File.Delete(tbp);
                if (Directory.Exists(targetPath)) Directory.Delete(targetPath, true);
            }
        }
        /// <summary>
        /// 获取新Tbp文件
        /// </summary>
        private static string GetNewTbp()
        private static string GetNewTbp(string time)
        {
            string tbp = Path.Combine(SourcesPath, "tb.tbp");
            string newTbp = Path.Combine(SourcesPath, GetTime + ".tbp");
            string newTbp = Path.Combine(Tools.TempDir, time, time + ".tbp");
            File.Copy(tbp, newTbp);
@@ -81,25 +85,59 @@
        }
        /// <summary>
        /// 移动文件至临时目录
        /// </summary>
        private static void MoveFilesToTemp(string sourcePath, string targetPath)
        {
            string imgPath = Path.Combine(targetPath, "img");
            //if (!Directory.Exists(imgPath)) Directory.CreateDirectory(imgPath);
            string demPath = Path.Combine(targetPath, "dem");
            //if (!Directory.Exists(demPath)) Directory.CreateDirectory(demPath);
            string shpPath = Path.Combine(targetPath, "shp");
            //if (!Directory.Exists(shpPath)) Directory.CreateDirectory(shpPath);
            File.Move(Path.Combine(sourcePath, "数字正射影像图"), imgPath);
            File.Move(Path.Combine(sourcePath, "数字高程模型"), demPath);
            File.Move(Path.Combine(sourcePath, "中线裁剪范围"), shpPath);
        }
        /// <summary>
        /// 获取新JS
        /// </summary>
        private static string GetNewJs(string tbp, string shp, string img, string dem)
        private static string GetNewJs(string time, string tbp, string targetPath)
        {
            string js = Path.Combine(SourcesPath, "template.js");
            string img = GetFilePath(Path.Combine(targetPath, "img"), "*.tif");
            string dem = GetFilePath(Path.Combine(targetPath, "dem"), "*.tif");
            string shp = GetFilePath(Path.Combine(targetPath, "shp"), "*.shp");
            string str = File.ReadAllText(js);
            str = str.Replace("{tbp}", tbp)
                .Replace("{shp}", shp)
                .Replace("{img}", img)
                .Replace("{dem}", dem)
                .Replace("{shp}", shp)
                .Replace("\\", "\\\\");
            string newJs = Path.Combine(SourcesPath, GetTime + ".js");
            string newJs = Path.Combine(Tools.TempDir, time, time + ".js");
            File.WriteAllText(newJs, str);
            return newJs;
        }
        /// <summary>
        /// 获取文件路径
        /// </summary>
        private static string GetFilePath(string path, string ext)
        {
            DirectoryInfo di = new DirectoryInfo(path);
            FileInfo[] files = di.GetFiles(ext);
            return null == files || 0 == files.Length ? string.Empty : files[0].FullName;
        }
        /// <summary>
        /// 重启TB程序
        /// </summary>
        private static void ReloadTB()
ExportMap/cs/Tools.cs
@@ -26,6 +26,9 @@
        private static string tempDir;
        /// <summary>
        /// 临时目录
        /// </summary>
        public static string TempDir
        {
            get
@@ -33,7 +36,10 @@
                if (string.IsNullOrWhiteSpace(tempDir))
                {
                    tempDir = Path.Combine(BaseDir, "temp");
                    if (!Directory.Exists(tempDir)) Directory.CreateDirectory(tempDir);
                    if (!Directory.Exists(tempDir))
                    {
                        Directory.CreateDirectory(tempDir);
                    }
                }
                return tempDir;