管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-10-24 2bdf37bae40dd37a90363679be3245cad797769a
测试TB生成MPT功能
已添加1个文件
已修改5个文件
124 ■■■■ 文件已修改
ExportMap/Controllers/TBController.cs 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/ExportMap.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/TerraBuilder/tb.js 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/TerraBuilder/说明.txt 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/cs/TBUtils.cs 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/cs/Tools.cs 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/Controllers/TBController.cs
@@ -7,6 +7,8 @@
using System.Net.Http;
using System.Web.Http;
using System.IO;
using System.Diagnostics;
using System.Threading;
namespace ExportMap.Controllers
{
@@ -36,5 +38,46 @@
                return ResponseMsg<string>.fail(ex.Message);
            }
        }
        [HttpGet] // http://localhost/ExportMap/TB/Test
        public ResponseMsg<string> Test()
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                string err = null;
                bool rs = TBUtils.Test(ref err);
                sw.Stop();
                return ResponseMsg<string>.success((rs ? "成功" : "失败") + ",耗时:" + sw.ElapsedMilliseconds / 1000.0 + " s", rs.ToString());
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return ResponseMsg<string>.fail(ex.Message);
            }
        }
        [HttpGet]
        public ResponseMsg<string> Wait(long seconds)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Thread.Sleep(new TimeSpan(seconds * 10 * 1000 * 1000));
                sw.Stop();
                return ResponseMsg<string>.success("成功", "耗时:" + sw.ElapsedMilliseconds / 1000.0 + " s");
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return ResponseMsg<string>.fail(ex.Message);
            }
        }
    }
}
ExportMap/ExportMap.csproj
@@ -130,6 +130,7 @@
    <Content Include="Sources\说明.txt" />
    <Content Include="TerraBuilder\tb.js" />
    <Content Include="TerraBuilder\template.js" />
    <Content Include="TerraBuilder\说明.txt" />
    <Content Include="UE.html" />
    <Content Include="up.html" />
    <Content Include="Web.config">
ExportMap/TerraBuilder/tb.js
@@ -3,7 +3,7 @@
    var project = TerraBuilder.OpenProject("E:\\terrait\\TianJin\\ExportMap\\ExportMap\\TerraBuilder\\tb01.tbp");
    var shp = "D:\\LF\\data\\shp\\buffer_midline.shp";
    var imgLayer = project.Layers.InsertLayer("D:\\LF\\data\\DOM\\CABQ_0641.tif", "imagery");
    var imgLayer = project.Layers.InsertLayer("D:\\LF\\data\\DOM\\D0M_M.tif", "imagery");
    if (null != imgLayer) {
        imgLayer.ImageryPyramidFormat = 0;
@@ -16,7 +16,7 @@
        poly2.type = 0;
    }
    var eleLayer = project.Layers.InsertLayer("D:\\LF\\data\\DEM\\DEM.tif", "Elevation");
    var eleLayer = project.Layers.InsertLayer("D:\\LF\\data\\DEM\\DEM_M.tif", "Elevation");
    if (null != eleLayer) {
        eleLayer.ElevationPyramidFormat = 0;
@@ -34,8 +34,8 @@
        poly3.type = 0;
    }
    project.CreateResolutionPyramids();
    //project.Settings.MPTFileName = "D:\\LF\\data\\mpt\\0A.MPT";
    project.CreateResolutionPyramids();
    //project.Save();
    project.CreateMPT();
ExportMap/TerraBuilder/˵Ã÷.txt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,15 @@
cmd:
cd "C:/Program Files/Skyline/TerraBuilder"
TerraBuilder.exe -script E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/tb.js
D:\LF\data\DOM
D:\LF\data\DEM
D:\LF\data\mpt
E:\terrait\TianJin\ExportMap\ExportMap\TerraBuilder
http://localhost/ExportMap/TB/Test
http://localhost/ExportMap/TB/Wait?seconds=30
ExportMap/cs/TBUtils.cs
@@ -49,7 +49,6 @@
        public static string CreateMpt(string sourcePath, ref string err)
        {
            string time = TimeStr;
            try
            {
                if (isBusy) throw new Exception("已有一个生成Mpt的任务正在执行");
@@ -62,9 +61,10 @@
                string tbp = GetNewTbp(time);
                string js = GetNewJs(time, tbp, targetPath);
                string cmd = string.Format("\"C:\\Program Files\\Skyline\\TerraBuilder\\TerraBuilder.exe\" -script \"{0}\"", js); // -DisablePrint
                ReloadTB();
                err = Tools.ExecCmdForWin(new List<string> { cmd });
                //string cmd = string.Format("\"C:\\Program Files\\Skyline\\TerraBuilder\\TerraBuilder.exe\" -script \"{0}\"", js); // -DisablePrint
                //err = Tools.ExecCmd(new List<string> { cmd });
                err = Tools.ExecExe("\"C:/Program Files/Skyline/TerraBuilder/TerraBuilder.exe\"", string.Format("-script \"{0}\"", js));
                isBusy = false;
                return File.Exists(MptPath) ? MoveMpt(MptPath, sourcePath) : null;
@@ -83,6 +83,37 @@
        }
        /// <summary>
        /// æµ‹è¯•
        /// </summary>
        public static bool Test(ref string err)
        {
            string time = TimeStr;
            try
            {
                if (isBusy) throw new Exception("已有一个生成Mpt的任务正在执行");
                isBusy = true;
                string js = "E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/tb.js";
                File.Copy("E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/tb.tbp", "E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/tb01.tbp", true);
                //string cmd = string.Format("\"C:/Program Files/Skyline/TerraBuilder/TerraBuilder.exe\" -script \"{0}\"", js); // -DisablePrint
                ReloadTB();
                //err = Tools.ExecCmdForWin(new List<string> { cmd });
                err = Tools.ExecExe("\"C:/Program Files/Skyline/TerraBuilder/TerraBuilder.exe\"", string.Format("-script \"{0}\"", js), false);
                isBusy = false;
                return File.Exists("D:/LF/data/mpt/tb.mpt");
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                err = ex.Message;
                isBusy = false;
                return false;
            }
        }
        /// <summary>
        /// èŽ·å–æ–°Tbp文件
        /// </summary>
        private static string GetNewTbp(string time)
ExportMap/cs/Tools.cs
@@ -377,35 +377,23 @@
        /// æ‰§è¡Œå‘½ä»¤
        /// </summary>
        /// <param name="list">命令集合</param>
        public static string ExecCmdForWin(List<string> list, bool noWin = false)
        public static string ExecExe(string exe, string args, bool noWin = true)
        {
            string str = null;
            Process p = null;
            try
            {
                p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.FileName = exe;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = noWin;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                if (!string.IsNullOrEmpty(args)) p.StartInfo.Arguments = args;
                p.Start();
                StreamWriter si = p.StandardInput;
                StreamReader se = p.StandardError;
                LogOut.Info("cmd = " + string.Join(",", list));
                si.AutoFlush = true;
                foreach (string cmd in list)
                {
                    si.WriteLine(cmd);
                }
                si.WriteLine("exit");
                str = se.ReadToEnd();
                se.Close();
                si.Close();
                p.WaitForExit();
            }
            catch (Exception ex)
            {