From a67a20d4be54f2a5943f16c187febbe59403456c Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 20 九月 2023 17:52:28 +0800
Subject: [PATCH] 获取las坐标JSON

---
 ExportMap/cs/Tools.cs                      |   11 +++++
 ExportMap/cs/PyLasUtils.cs                 |   80 +++++++++++++++++++++++++++++++++++++++-
 ExportMap/Controllers/ConvertController.cs |    3 +
 3 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/ExportMap/Controllers/ConvertController.cs b/ExportMap/Controllers/ConvertController.cs
index 1c9abb4..6e0db2f 100644
--- a/ExportMap/Controllers/ConvertController.cs
+++ b/ExportMap/Controllers/ConvertController.cs
@@ -27,7 +27,8 @@
             //TerrainUtils.Project("D:/xyz/dem/dem/32a_4326_.tif", "EPSG:4490");
 
             //string wkt = TerrainUtils.GetPointZ(new XYZArgs() { dircode = "0B" });
-            PyLasUtils.CsTransform("EPSG:4528", 400925.079, 2541768.173);
+            //PyLasUtils.CsTransform("EPSG:4528", 400925.079, 2541768.173);
+            string json = PyLasUtils.GetLasGeomJSON(@"D:\LF\data\las\1_lfz_0.05m.las", 1314);
 
             return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
         }
diff --git a/ExportMap/cs/PyLasUtils.cs b/ExportMap/cs/PyLasUtils.cs
index 8ba8eab..00097b3 100644
--- a/ExportMap/cs/PyLasUtils.cs
+++ b/ExportMap/cs/PyLasUtils.cs
@@ -40,7 +40,6 @@
                 if (null == list || list.Count == 0) return null;
 
                 string pyPath = Tools.GetSetting("pythonFolder");
-                string tilerPath = Tools.GetSetting("tilerPath");
                 string uploadFolder = Tools.GetSetting("uploadFolder");
 
                 List<int> ids = new List<int>();
@@ -108,7 +107,7 @@
         }
 
         /// <summary>
-        /// 鍧愭爣杞崲
+        /// 鍧愭爣杞崲 *
         /// </summary>
         public static void CsTransform(string epsg, double x, double y, double z = 0)
         {
@@ -123,5 +122,82 @@
 
             //return rs;
         }
+
+        /// <summary>
+        /// 鑾峰彇las鍧愭爣JSON
+        /// </summary>
+        public static string GetLasGeomJSON(string lasFile, int id)
+        {
+            try
+            {
+                string cmd = string.Format("\"{0}\\lasinfo.exe\" \"{1}\"", Tools.GetSetting("tilerPath"), lasFile);
+                string rs = Tools.ExecCmd(new List<string> { cmd });
+                if (string.IsNullOrEmpty(rs)) return null;
+
+                string[] strs = rs.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
+                string epsg = GetEpsgFromStrs(strs);
+                string minStr = GetCoordFromStrs(strs, "min x y z:");
+                string maxStr = GetCoordFromStrs(strs, "max x y z:");
+                string scaleStr = GetCoordFromStrs(strs, "scale factor x y z:");
+                if (string.IsNullOrEmpty(epsg) || string.IsNullOrEmpty(minStr) || string.IsNullOrEmpty(maxStr) || string.IsNullOrEmpty(scaleStr)) return null;
+
+                string[] minXYZ = minStr.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+                string[] maxXYZ = maxStr.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+                string[] scales = scaleStr.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+                double minX = double.Parse(minXYZ[0]), minY = double.Parse(minXYZ[1]), minZ = double.Parse(minXYZ[2]);
+                double maxX = double.Parse(maxXYZ[0]), maxY = double.Parse(maxXYZ[1]), maxZ = double.Parse(maxXYZ[2]);
+                double x = (minX + maxX) / 2, y = (minY + maxY) / 2, z = maxZ, scale = Math.Round(1 / double.Parse(scales[0]), 2);
+
+                string url = ExportUtil.LFServer + "/publish/selectCsTransform?token=" + Tools.Token + "&x=" + x + "&y=" + y + "&epsg=" + epsg;
+                rs = ExportUtil.GetData(url);
+                if (string.IsNullOrEmpty(rs)) return null;
+
+                strs = rs.Replace("\"", "").Split(new string[] { "," }, StringSplitOptions.None);
+                x = double.Parse(strs[0]);
+                y = double.Parse(strs[1]);
+
+                return string.Format("{{\"lon\":{0},\"lat\":{1},\"height\":{2},\"yaw\":0,\"alpha\":1,\"modelid\":\"DbId\",\"scale\":{3},\"lasId\":{4}}}", x, y, z, scale, id);
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.StackTrace);
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 浠庡瓧绗︿覆鏁扮粍涓幏鍙朎PSG
+        /// </summary>
+        private static string GetEpsgFromStrs(string[] strs)
+        {
+            foreach (string str in strs)
+            {
+                if (str.Contains("key 3072 "))
+                {
+                    int start = str.IndexOf("value_offset") + 12;
+                    int end = str.IndexOf("-", start);
+
+                    return str.Substring(start, end - start).Replace(" ", "");
+                }
+            }
+
+            return null;
+        }
+
+        /// <summary>
+        /// 浠庡瓧绗︿覆鏁扮粍涓幏鍙栧潗鏍�
+        /// </summary>
+        private static string GetCoordFromStrs(string[] strs, string key)
+        {
+            foreach (string str in strs)
+            {
+                if (str.Contains(key))
+                {
+                    return str.Replace(key, "");
+                }
+            }
+
+            return null;
+        }
     }
 }
diff --git a/ExportMap/cs/Tools.cs b/ExportMap/cs/Tools.cs
index 45372bb..6517612 100644
--- a/ExportMap/cs/Tools.cs
+++ b/ExportMap/cs/Tools.cs
@@ -28,6 +28,17 @@
         /// </summary>
         public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
 
+        /// <summary>
+        /// 鑾峰彇浠ょ墝
+        /// </summary>
+        public static string Token
+        {
+            get
+            {
+                return "c36e4f94-dfde-401e-9967-2c4a449f1300";
+            }
+        }
+
         private static string tempDir;
 
         /// <summary>

--
Gitblit v1.9.3