From bff584de802c085aeb6d18fc08557c4b68bbbecb Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 02 八月 2023 14:35:47 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/TerraUtils.cs |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/ExportMap/cs/TerraUtils.cs b/ExportMap/cs/TerraUtils.cs
index bdc0014..c4b370a 100644
--- a/ExportMap/cs/TerraUtils.cs
+++ b/ExportMap/cs/TerraUtils.cs
@@ -13,6 +13,8 @@
     {
         private static string pyFile;
 
+        public static int DEFAULT_MAX_LEVEL = 16;
+
         /// <summary>
         /// 鑾峰彇Python鏂囦欢
         /// </summary>
@@ -205,17 +207,46 @@
         }
 
         /// <summary>
+        /// 鑾峰彇鍦板舰鏈�澶х骇鍒�
+        /// </summary>
+        private static int GetTerrainMaxLevel(XYZArgs args, string tifFile)
+        {
+            string ctbPath = Tools.GetSetting("ctbPath");
+            string dirPath = GetTerrainPath(args.dircode);
+
+            string gdal_data = string.Format("set GDAL_DATA={0}\\data", ctbPath);
+            string createLayer = string.Format("{0}\\ctb-tile.exe -l -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode);
+
+            Tools.ExecCmd(new List<string>() { gdal_data, createLayer });
+
+            string layerJson = Path.Combine(dirPath, "layer.json");
+            if (!File.Exists(layerJson)) return DEFAULT_MAX_LEVEL;
+
+            string[] lines = File.ReadAllLines(layerJson, Encoding.UTF8);
+
+            int level = -1;
+            foreach (string line in lines)
+            {
+                if (line.IndexOf("startX") > -1) level++;
+            }
+            if (File.Exists(layerJson)) File.Delete(layerJson);
+
+            return level;
+        }
+
+        /// <summary>
         /// 鍒涘缓楂樼▼鍒囩墖
         /// </summary>
         private static void CreateTerrain(XYZArgs args, string tifFile, ref string err)
         {
             string ctbPath = Tools.GetSetting("ctbPath");
             string dirPath = GetTerrainPath(args.dircode);
+            int maxLevel = GetTerrainMaxLevel(args, tifFile);
 
             string gdal_data = string.Format("set GDAL_DATA={0}\\data", ctbPath);
             // -N 椤剁偣娉曠嚎, -C 寮哄埗鍒涘缓缂哄け鏍圭摝鐗�, -R 涓嶈鐩栫幇鏈夋枃浠�
-            string createMesh = string.Format("{0}\\ctb-tile.exe -R -C -s 16 -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode);
-            string createLayer = string.Format("{0}\\ctb-tile.exe -l -s 16 -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode);
+            string createMesh = string.Format("{0}\\ctb-tile.exe -R -C -s {4} -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode, maxLevel);
+            string createLayer = string.Format("{0}\\ctb-tile.exe -l -s {4} -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode, maxLevel);
 
             List<string> list = new List<string>() { gdal_data, createMesh, createLayer };
             err = Tools.ExecCmd(list);

--
Gitblit v1.9.3