From a8028c5fe78d8e9a05f171407ac129c4fbd65e87 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 24 七月 2024 16:47:01 +0800
Subject: [PATCH] 1

---
 SimuTools/Tools/Handle.cs |   69 ++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 32 deletions(-)

diff --git a/SimuTools/Tools/Handle.cs b/SimuTools/Tools/Handle.cs
index 0a9c3fd..a7a4aa6 100644
--- a/SimuTools/Tools/Handle.cs
+++ b/SimuTools/Tools/Handle.cs
@@ -18,6 +18,10 @@
         #region 鎴愬憳鍙橀噺
         public static readonly int MAX = 256 * 256;
 
+        public static readonly double MAX_X_OFFSET = 0.002;
+
+        public static readonly double MIN_X_OFFSET = -0.00005;
+
         public static readonly double WaterHeightOffset = 1.0;
 
         public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
@@ -40,10 +44,10 @@
 
             CopeTerrain(terrainFile, outPath, layer);
             CopeWater(waterPath, outPath, layer);
-            //CopeFlow(flowPath, outPath, layer);
+            CopeFlow(flowPath, outPath, layer);
             CopeLayerJson(outPath, layer);
 
-            //if (Directory.Exists(temp)) Directory.Delete(temp, true);
+            if (Directory.Exists(temp)) Directory.Delete(temp, true);
         }
 
         #region 鍦板舰
@@ -58,7 +62,7 @@
                 ds = Gdal.Open(terrainFile, Access.GA_ReadOnly);
                 if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return;
 
-                SetTerrainInfo(ds, outPath, layer);
+                SetTerrainInfo(ds, layer);
                 CreateTerrainPng(ds, layer, outPath);
             }
             finally
@@ -70,7 +74,7 @@
         /// <summary>
         /// 璁剧疆鍦板舰淇℃伅
         /// </summary>
-        private static void SetTerrainInfo(Dataset ds, string outPath, Domain.Layer layer)
+        private static void SetTerrainInfo(Dataset ds, Domain.Layer layer)
         {
             //String srsName = ds.GetSpatialRef().GetName();
             //layer.terrain.epsg = !string.IsNullOrEmpty(srsName) && srsName.Contains(GdalHelper.CGCS2000) ? "EPSG:4490" : "EPSG:4326";
@@ -79,7 +83,7 @@
             Geometry maxPoint = GdalHelper.GetMaxPoint(ds);
             double minx = GetMinVal(minPoint.GetX(0), 10000000);
             double miny = GetMinVal(minPoint.GetY(0), 10000000);
-            double maxx = GetMaxVal(maxPoint.GetX(0), 10000000);
+            double maxx = GetMaxVal(maxPoint.GetX(0) + MAX_X_OFFSET, 10000000);
             double maxy = GetMaxVal(maxPoint.GetY(0), 10000000);
             layer.extension = new Extension(minx, miny, maxx, maxy, double.MaxValue, double.MinValue);
 
@@ -169,7 +173,8 @@
                 Graphics graphic = Graphics.FromImage(image);
                 graphic.Clear(Color.Transparent); // 濉厖閫忔槑鑹�
 
-                double perHeight = (layer.terrain.maxHeight - layer.terrain.minHeight) * 100 / 65536;
+                //double perHeight = (layer.terrain.maxHeight - layer.terrain.minHeight) * 100 / 65536;
+                double differ = layer.terrain.maxHeight - layer.terrain.minHeight;
                 for (int x = 0; x < width; x++)
                 {
                     for (int y = 0; y < height; y++)
@@ -177,10 +182,10 @@
                         int offset = x + y * width;
                         if (float.IsNaN(buffer[offset]) || buffer[offset] < -999) continue;
 
-                        //int val = Convert.ToInt32(buffer[offset] * 100);
-                        int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) * 100 / perHeight);
-                        int r = val / 65536;
-                        int g = (val - r * 65536) / 256;
+                        //int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) * 100 / perHeight);
+                        int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) / differ * 65536);
+                        int r = 0;
+                        int g = val / 256;
                         int b = val % 256;
 
                         Color color = Color.FromArgb(127, r, g, b);
@@ -210,7 +215,7 @@
             SetWaterHeight(layer, files);
             if (files.Count != layer.waters.data.Count) return;
 
-            //ProcessWaters(files, outPath, layer);
+            ProcessWaters(files, outPath, layer);
         }
 
         /// <summary>
@@ -498,7 +503,7 @@
         private static int GetSafeValue(int val)
         {
             if (val < 0) return 0;
-            if (val > 255) val = 255;
+            if (val > 255) return 255;
 
             return val;
         }
@@ -506,9 +511,27 @@
 
         #region 鍏冩暟鎹�
         /// <summary>
+        /// 澶勭悊鍏冩暟鎹�
+        /// </summary>
+        private static void CopeLayerJson(string outPath, Domain.Layer layer)
+        {
+            if (null == layer) return;
+
+            String json = JsonConvert.SerializeObject(layer);
+
+            string filePath = Path.Combine(outPath, "layer.json");
+            using (StreamWriter sw = new StreamWriter(filePath))
+            {
+                sw.Write(json);
+            }
+        }
+        #endregion
+
+        #region 鏆傛椂涓嶇敤
+        /// <summary>
         /// 璁剧疆鍦板舰淇℃伅
         /// </summary>
-        private static void SetTerrainInfo2(Dataset ds, string outPath, Domain.Layer layer)
+        private static void SetTerrainInfo(Dataset ds, string outPath, Domain.Layer layer)
         {
             string tempPath = Path.Combine(outPath, "temp");
             if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
@@ -556,25 +579,7 @@
         }
 
         /// <summary>
-        /// 澶勭悊鍏冩暟鎹�
-        /// </summary>
-        private static void CopeLayerJson(string outPath, Domain.Layer layer)
-        {
-            if (null == layer) return;
-
-            String json = JsonConvert.SerializeObject(layer);
-
-            string filePath = Path.Combine(outPath, "layer.json");
-            using (StreamWriter sw = new StreamWriter(filePath))
-            {
-                sw.Write(json);
-            }
-        }
-        #endregion
-
-        #region 鏆傛椂涓嶇敤
-        /// <summary>
-        /// 閲嶉噰鏍� *
+        /// 閲嶉噰鏍�
         /// </summary>
         private static void Resample(string source, string dest, int width, int height)
         {

--
Gitblit v1.9.3