From d9c6232dac8c1af6586d116fe558d154feb46011 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 21 六月 2023 15:50:22 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/Tools.cs                      |    2 
 ExportMap/cs/OsgbUtils.cs                  |   82 +++++++++++++++++++
 ExportMap/Controllers/ConvertController.cs |   12 +-
 ExportMap/Models/XYZArgs.cs                |   11 ++
 ExportMap/export.html                      |   12 ++
 ExportMap/Web.config                       |    8 +
 ExportMap/cs/LasUtils.cs                   |   80 +++++++++++++++++++
 7 files changed, 192 insertions(+), 15 deletions(-)

diff --git a/ExportMap/Controllers/ConvertController.cs b/ExportMap/Controllers/ConvertController.cs
index 2b4f1e2..16b151b 100644
--- a/ExportMap/Controllers/ConvertController.cs
+++ b/ExportMap/Controllers/ConvertController.cs
@@ -29,7 +29,7 @@
             try
             {
                 ResponseMsg<string> msg = checkArgs(args);
-                if (null != args) return msg;
+                if (null != msg) return msg;
 
                 List<int> rs = ConvertUtils.Convert(args);
                 if (null == rs || rs.Count == 0)
@@ -55,7 +55,7 @@
             try
             {
                 ResponseMsg<string> msg = checkArgs(args, true);
-                if (null != args) return msg;
+                if (null != msg) return msg;
 
                 checkMinMax(args, true);
 
@@ -84,7 +84,7 @@
             try
             {
                 ResponseMsg<string> msg = checkArgs(args);
-                if (null != args) return msg;
+                if (null != msg) return msg;
 
                 string err = null;
                 SGUtils utils = new SGUtils();
@@ -112,7 +112,7 @@
             try
             {
                 ResponseMsg<string> msg = checkArgs(args, true);
-                if (null != args) return msg;
+                if (null != msg) return msg;
 
                 checkMinMax(args);
 
@@ -141,7 +141,7 @@
             try
             {
                 ResponseMsg<string> msg = checkArgs(args);
-                if (null != args) return msg;
+                if (null != msg) return msg;
 
                 string err = null;
                 List<int> rs = LasUtils.Generate(args, ref err);
@@ -168,7 +168,7 @@
             try
             {
                 ResponseMsg<string> msg = checkArgs(args);
-                if (null != args) return msg;
+                if (null != msg) return msg;
 
                 string err = null;
                 List<int> rs = OsgbUtils.Generate(args, ref err);
diff --git a/ExportMap/Models/XYZArgs.cs b/ExportMap/Models/XYZArgs.cs
index 13f4201..e5b731e 100644
--- a/ExportMap/Models/XYZArgs.cs
+++ b/ExportMap/Models/XYZArgs.cs
@@ -14,6 +14,7 @@
         {
             ids = new List<int>();
             isNew = true;
+            srid = 4326;
         }
 
         /// <summary>
@@ -70,5 +71,15 @@
         /// 鏄�/鍚﹀叏鏂板彂甯�
         /// </summary>
         public bool isNew { set; get; }
+
+        /// <summary>
+        /// 鍧愭爣绯籌D
+        /// </summary>
+        public int srid { set; get; }
+
+        /// <summary>
+        /// 楂樺害鍋忕Щ閲�
+        /// </summary>
+        public double z { set; get; }
     }
 }
diff --git a/ExportMap/Web.config b/ExportMap/Web.config
index dd890b1..47f1665 100644
--- a/ExportMap/Web.config
+++ b/ExportMap/Web.config
@@ -13,9 +13,13 @@
     <add key="sgDB" value="E:\soft\SGConfig\catalog.db"/>
     <!-- cesium-terrain-builder璺緞 -->
     <add key="ctbPath" value="E:\WebSite\Cesium\Tool\ctb_0.41" />
+    <!-- 3dtiles璺緞 -->
+    <add key="d3tilesPath" value="E:\WebSite\Cesium\Tool\3dtiles" />
+    <!-- gocesiumtiler璺緞 -->
+    <add key="tilerPath" value="E:\WebSite\Cesium\Tool\gocesiumtiler-1.2.3" />
     <!-- PG杩炴帴 -->
-    <!--<add key="pgConn" value="Server=127.0.0.1;Port=5433;Database=langfang;User Id=postgres;Password=postgres;"/>-->
-    <add key="pgConn" value="Server=192.168.20.205;Port=5433;Database=langfang;User Id=postgres;Password=Postgres!_14_Lf;"/>
+    <add key="pgConn" value="Server=127.0.0.1;Port=5433;Database=langfang;User Id=postgres;Password=postgres;"/>
+    <!--<add key="pgConn" value="Server=192.168.20.205;Port=5433;Database=langfang;User Id=postgres;Password=Postgres!_14_Lf;"/>-->
     <!--<add key="pgConn" value="Server=103.85.165.99;Port=5433;Database=langfang;User Id=postgres;Password=Postgres!_14_Lf;"/>-->
     <add key="webpages:Version" value="3.0.0.0"/>
     <add key="webpages:Enabled" value="false"/>
diff --git a/ExportMap/cs/LasUtils.cs b/ExportMap/cs/LasUtils.cs
index f3963ad..09eb78f 100644
--- a/ExportMap/cs/LasUtils.cs
+++ b/ExportMap/cs/LasUtils.cs
@@ -1,6 +1,8 @@
-锘縰sing ExportMap.Models;
+锘縰sing ExportMap.db;
+using ExportMap.Models;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Web;
 
@@ -9,6 +11,22 @@
     public class LasUtils
     {
         /// <summary>
+        /// 鑾峰彇璺緞
+        /// </summary>
+        public static string GetPath(int id)
+        {
+            return Path.Combine(SGUtils.LFData, "3d\\3dtiles\\las", id.ToString());
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍙戝竷鍦板潃
+        /// </summary>
+        public static string GetReleaseUrl(SysMeta meta)
+        {
+            return "http://{host}/LFData/3d/3dtiles/las/" + meta.id + "/tileset.json";
+        }
+
+        /// <summary>
         /// 鐢熸垚
         /// </summary>
         /// <param name="args">XYZ鍙傛暟</param>
@@ -16,9 +34,67 @@
         /// <returns>鏁版嵁鍙戝竷ID闆嗗悎</returns>
         public static List<int> Generate(XYZArgs args, ref string err)
         {
+            try
+            {
+                List<SysMeta> list = XYZUtils.SelectMetas(args.ids, "and type in ('las', 'laz')");
+                if (null == list || list.Count == 0) return null;
 
+                string tilerPath = Tools.GetSetting("tilerPath");
+                string uploadFolder = Tools.GetSetting("uploadFolder");
 
-            return null;
+                List<int> ids = new List<int>();
+                foreach (SysMeta meta in list)
+                {
+                    string osgbPath = Path.Combine(uploadFolder, meta.path);
+                    if (!Directory.Exists(osgbPath)) continue;
+
+                    meta.ismeta = 0; // 0-鍊炬枩鎽勫奖鏁版嵁
+                    string outPath = GetPath(meta.id);
+                    string jsonFile = Path.Combine(outPath, "tileset.json");
+
+                    if (args.isNew && Directory.Exists(outPath)) Tools.DelPath(outPath);
+                    if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);
+                    if (File.Exists(jsonFile)) File.Delete(jsonFile);
+
+                    string cmd = string.Format("{0}\\gocesiumtiler.exe -i \"{1}\" -o \"{2}\" -e {3} -z {4} -g -s", tilerPath, osgbPath, outPath, args.srid, args.z);
+                    err = Tools.ExecCmd(cmd, false, false);
+
+                    if (File.Exists(jsonFile))
+                    {
+                        string path = jsonFile.Replace(Tools.GetSetting("lfData") + "\\", "");
+                        int pubid = InsertToDB(meta, args, path);
+                        if (pubid > 0) ids.Add(pubid);
+                    }
+                }
+
+                return ids;
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                err = ex.Message;
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 鎻掑叆鏁版嵁搴�
+        /// </summary>
+        private static int InsertToDB(SysMeta meta, XYZArgs args, string path)
+        {
+            if (PubDBHelper.IsPublish(meta.id)) return 0;
+
+            SysPublish sys = Tools.NewPublish(meta, args, GetReleaseUrl(meta), path);
+
+            int pubid = PubDBHelper.InsertPublish(sys);
+            if (pubid > 0)
+            {
+                sys.id = pubid;
+                PubDBHelper.InsertLayer(sys, meta);
+                PubDBHelper.InsertMetaPub(meta.id, pubid, args.userId);
+            }
+
+            return pubid;
         }
     }
 }
diff --git a/ExportMap/cs/OsgbUtils.cs b/ExportMap/cs/OsgbUtils.cs
index 4c90fa9..8053cfa 100644
--- a/ExportMap/cs/OsgbUtils.cs
+++ b/ExportMap/cs/OsgbUtils.cs
@@ -1,6 +1,8 @@
-锘縰sing ExportMap.Models;
+锘縰sing ExportMap.db;
+using ExportMap.Models;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Web;
 
@@ -9,6 +11,22 @@
     public class OsgbUtils
     {
         /// <summary>
+        /// 鑾峰彇璺緞
+        /// </summary>
+        public static string GetPath(int id)
+        {
+            return Path.Combine(SGUtils.LFData, "3d\\3dtiles\\osgb", id.ToString());
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍙戝竷鍦板潃
+        /// </summary>
+        public static string GetReleaseUrl(SysMeta meta)
+        {
+            return "http://{host}/LFData/3d/3dtiles/osgb/" + meta.id + "/tileset.json";
+        }
+
+        /// <summary>
         /// 鐢熸垚
         /// </summary>
         /// <param name="args">XYZ鍙傛暟</param>
@@ -16,9 +34,67 @@
         /// <returns>鏁版嵁鍙戝竷ID闆嗗悎</returns>
         public static List<int> Generate(XYZArgs args, ref string err)
         {
-            //
+            try
+            {
+                List<SysMeta> list = XYZUtils.SelectMetas(args.ids, "and type = 'osgb'");
+                if (null == list || list.Count == 0) return null;
 
-            return null;
+                string d3tilesPath = Tools.GetSetting("d3tilesPath");
+                string uploadFolder = Tools.GetSetting("uploadFolder");
+
+                List<int> ids = new List<int>();
+                foreach (SysMeta meta in list)
+                {
+                    string osgbPath = Path.Combine(uploadFolder, meta.path);
+                    if (!Directory.Exists(osgbPath)) continue;
+
+                    meta.ismeta = 0; // 0-鍊炬枩鎽勫奖鏁版嵁
+                    string outPath = GetPath(meta.id);
+                    string jsonFile = Path.Combine(outPath, "tileset.json");
+
+                    if (args.isNew && Directory.Exists(outPath)) Tools.DelPath(outPath);
+                    if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);
+                    if (File.Exists(jsonFile)) File.Delete(jsonFile);
+
+                    string cmd = string.Format("{0}\\3dtile.exe -f osgb -i \"{1}\" -o \"{2}\"", d3tilesPath, osgbPath, outPath);
+                    err = Tools.ExecCmd(cmd, false, false);
+
+                    if (File.Exists(jsonFile))
+                    {
+                        string path = jsonFile.Replace(Tools.GetSetting("lfData") + "\\", "");
+                        int pubid = InsertToDB(meta, args, path);
+                        if (pubid > 0) ids.Add(pubid);
+                    }
+                }
+
+                return ids;
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                err = ex.Message;
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 鎻掑叆鏁版嵁搴�
+        /// </summary>
+        private static int InsertToDB(SysMeta meta, XYZArgs args, string path)
+        {
+            if (PubDBHelper.IsPublish(meta.id)) return 0;
+
+            SysPublish sys = Tools.NewPublish(meta, args, GetReleaseUrl(meta), path);
+
+            int pubid = PubDBHelper.InsertPublish(sys);
+            if (pubid > 0)
+            {
+                sys.id = pubid;
+                PubDBHelper.InsertLayer(sys, meta);
+                PubDBHelper.InsertMetaPub(meta.id, pubid, args.userId);
+            }
+
+            return pubid;
         }
     }
 }
diff --git a/ExportMap/cs/Tools.cs b/ExportMap/cs/Tools.cs
index 71debf0..3bc1e44 100644
--- a/ExportMap/cs/Tools.cs
+++ b/ExportMap/cs/Tools.cs
@@ -159,7 +159,7 @@
         /// </summary>
         /// <param name="cmd">鍛戒护琛�</param>
         /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
-        public static String ExecCmd(string cmd, bool isPy = false, bool isOut = false)
+        public static string ExecCmd(string cmd, bool isPy = false, bool isOut = false)
         {
             List<string> list = new List<string>();
             if (isPy)
diff --git a/ExportMap/export.html b/ExportMap/export.html
index bebe2bd..dd6ab7c 100644
--- a/ExportMap/export.html
+++ b/ExportMap/export.html
@@ -5,7 +5,7 @@
   <title></title>
   <script src="js/jquery.1.12.4.js"></script>
   <script>
-    var token = "94baeb78-d4cc-43db-b9b5-8ff9584c587d";
+    var token = "74fca142-b0cd-4ecb-965b-6b51b8866ec4";
 
     // Ajax
     function ajax(url, type, data, dataType, contentType, fn) {
@@ -128,6 +128,15 @@
         console.log(rs);
       });
     }
+
+    // 娴嬭瘯OSGB
+    function toOsgb() {
+      var data = { token: token, ids: [7187], depcode: "00", dircode: "0C", userId: 1, name: "3-1鍊炬枩妯″瀷-涓崼绔�" };
+      ajax("Convert/ToOsgb", "POST", JSON.stringify(data), null, null, function (rs) {
+        alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
+        console.log(rs);
+      });
+    }
   </script>
 </head>
 <body>
@@ -149,5 +158,6 @@
   <input type="button" value="娴嬭瘯Ifc" onclick="convert3();" />
   <input type="button" value="娴嬭瘯SG" onclick="toSG();" />
   <input type="button" value="娴嬭瘯Terra" onclick="toTerra();" />
+  <input type="button" value="娴嬭瘯OSGB" onclick="toOsgb();" />
 </body>
 </html>

--
Gitblit v1.9.3