From 168bba3491d987955aaf75907554f68c444dbeda Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期日, 25 六月 2023 21:10:44 +0800
Subject: [PATCH] 解决OSGB数据坐标解析不正确

---
 ExportMap/cs/OsgbUtils.cs |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/ExportMap/cs/OsgbUtils.cs b/ExportMap/cs/OsgbUtils.cs
index 5037fb7..3eb0ddd 100644
--- a/ExportMap/cs/OsgbUtils.cs
+++ b/ExportMap/cs/OsgbUtils.cs
@@ -56,10 +56,14 @@
                     if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);
                     if (File.Exists(jsonFile)) File.Delete(jsonFile);
 
+                    string srs = findSRS(osgbPath);
+                    if (null != srs) writeSRS(osgbPath, getSRS(srs));
+
                     string cmd = string.Format("{0}\\3dtile.exe -f osgb -i \"{1}\" -o \"{2}\" -c \"{{\\\"offset\\\": {3}}}\"", d3tilesPath, osgbPath, outPath, args.z);
                     err = Tools.ExecCmd(cmd, false, false);
                     err = null;
 
+                    if (null != srs) writeSRS(osgbPath, srs);
                     if (File.Exists(jsonFile))
                     {
                         string path = jsonFile.Replace(Tools.GetSetting("lfData") + "\\", "");
@@ -79,6 +83,60 @@
         }
 
         /// <summary>
+        /// 鏌ユ壘SRS
+        /// </summary>
+        private static string findSRS(string osgbPath)
+        {
+            string file = Path.Combine(osgbPath, "metadata.xml");
+            if (!File.Exists(file)) return null;
+
+            string[] lines = File.ReadAllLines(file);
+            foreach (string line in lines)
+            {
+                if (line.Contains("<SRS>EPSG:") && line.Contains("+"))
+                {
+                    return line;
+                }
+            }
+
+            return null;
+        }
+
+        /// <summary>
+        /// 鍐欏叆SRS
+        /// </summary>
+        private static void writeSRS(string osgbPath, string newSRS)
+        {
+            string file = Path.Combine(osgbPath, "metadata.xml");
+            if (!File.Exists(file)) return;
+
+            string[] lines = File.ReadAllLines(file);
+            for (int i = 0, c = lines.Length; i < c; i++)
+            {
+                if (lines[i].Contains("<SRS>EPSG:"))
+                {
+                    lines[i] = newSRS;
+                    break;
+                }
+            }
+
+            File.WriteAllLines(file, lines);
+        }
+
+        /// <summary>
+        /// 鑾峰彇SRS
+        /// </summary>
+        /// <param name="srs"></param>
+        private static string getSRS(string srs)
+        {
+            int start = srs.IndexOf("+");
+            int end = srs.IndexOf("</SRS>");
+            string other = srs.Substring(start, end - start);
+
+            return srs.Replace(other, "");
+        }
+
+        /// <summary>
         /// 鎻掑叆鏁版嵁搴�
         /// </summary>
         private static int InsertToDB(SysMeta meta, XYZArgs args, string path)

--
Gitblit v1.9.3