From a10e925cdda6f92a7bbf86188e317f5c5ee839b5 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 26 七月 2024 14:21:20 +0800
Subject: [PATCH] 水面数据在计算时添加建筑物避让功能

---
 SimuTools/FrmMain.cs          |   30 +++--
 SimuTools/FrmMain.Designer.cs |   66 ++++++++++--
 SimuTools/SimuTools.csproj    |    1 
 SimuTools/Tools/Handle.cs     |  131 +++++++++++++++-----------
 SimuTools/Domain/Args.cs      |   50 ++++++++++
 5 files changed, 197 insertions(+), 81 deletions(-)

diff --git a/SimuTools/Domain/Args.cs b/SimuTools/Domain/Args.cs
new file mode 100644
index 0000000..5f44481
--- /dev/null
+++ b/SimuTools/Domain/Args.cs
@@ -0,0 +1,50 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace SimuTools.Domain
+{
+    public class Args
+    {
+        public string serviceName { set; get; }
+
+        public string terrainFile { set; get; }
+
+        public string buildingFile { set; get; }
+
+        public string waterPath { set; get; }
+
+        public string flowPath { set; get; }
+
+        public string outPath { set; get; }
+
+        public string temp { set; get; }
+
+        public Dictionary<string, float[]> buildings { set; get; }
+
+        public Args()
+        {
+            buildings = new Dictionary<string, float[]>();
+        }
+
+        public Args(string serviceName, string terrainFile, string buildingFile, string waterPath, string flowPath, string outPath) : this()
+        {
+            this.serviceName = serviceName;
+            this.terrainFile = terrainFile;
+            this.buildingFile = buildingFile;
+            this.waterPath = waterPath;
+            this.flowPath = flowPath;
+            this.outPath = outPath;
+
+            this.outPath = Path.Combine(this.outPath, serviceName);
+            if (!Directory.Exists(this.outPath)) Directory.CreateDirectory(this.outPath);
+
+            this.temp = Path.Combine(this.outPath, "temp");
+            if (!Directory.Exists(this.temp)) Directory.CreateDirectory(this.temp);
+        }
+    }
+}
diff --git a/SimuTools/FrmMain.Designer.cs b/SimuTools/FrmMain.Designer.cs
index ae523de..eeaa1af 100644
--- a/SimuTools/FrmMain.Designer.cs
+++ b/SimuTools/FrmMain.Designer.cs
@@ -43,6 +43,9 @@
             this.btnOutPath = new System.Windows.Forms.Button();
             this.txtServiceName = new System.Windows.Forms.TextBox();
             this.lblService = new System.Windows.Forms.Label();
+            this.txtBuildingPath = new System.Windows.Forms.TextBox();
+            this.lblBuilding = new System.Windows.Forms.Label();
+            this.btnBuildingPath = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // btnTerrainPath
@@ -79,7 +82,7 @@
             // txtWaterPath
             // 
             this.txtWaterPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.txtWaterPath.Location = new System.Drawing.Point(118, 94);
+            this.txtWaterPath.Location = new System.Drawing.Point(118, 143);
             this.txtWaterPath.MaxLength = 2000;
             this.txtWaterPath.Name = "txtWaterPath";
             this.txtWaterPath.Size = new System.Drawing.Size(482, 26);
@@ -90,7 +93,7 @@
             // 
             this.lblWater.AutoSize = true;
             this.lblWater.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.lblWater.Location = new System.Drawing.Point(33, 99);
+            this.lblWater.Location = new System.Drawing.Point(33, 148);
             this.lblWater.Name = "lblWater";
             this.lblWater.Size = new System.Drawing.Size(79, 16);
             this.lblWater.TabIndex = 51;
@@ -99,7 +102,7 @@
             // btnWaterPath
             // 
             this.btnWaterPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnWaterPath.Location = new System.Drawing.Point(616, 94);
+            this.btnWaterPath.Location = new System.Drawing.Point(616, 143);
             this.btnWaterPath.Name = "btnWaterPath";
             this.btnWaterPath.Size = new System.Drawing.Size(130, 26);
             this.btnWaterPath.TabIndex = 50;
@@ -110,7 +113,7 @@
             // txtFlowPath
             // 
             this.txtFlowPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.txtFlowPath.Location = new System.Drawing.Point(118, 144);
+            this.txtFlowPath.Location = new System.Drawing.Point(118, 193);
             this.txtFlowPath.MaxLength = 2000;
             this.txtFlowPath.Name = "txtFlowPath";
             this.txtFlowPath.Size = new System.Drawing.Size(482, 26);
@@ -121,7 +124,7 @@
             // 
             this.lblFlow.AutoSize = true;
             this.lblFlow.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.lblFlow.Location = new System.Drawing.Point(33, 149);
+            this.lblFlow.Location = new System.Drawing.Point(33, 198);
             this.lblFlow.Name = "lblFlow";
             this.lblFlow.Size = new System.Drawing.Size(79, 16);
             this.lblFlow.TabIndex = 54;
@@ -130,7 +133,7 @@
             // btnFlowPath
             // 
             this.btnFlowPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnFlowPath.Location = new System.Drawing.Point(616, 144);
+            this.btnFlowPath.Location = new System.Drawing.Point(616, 193);
             this.btnFlowPath.Name = "btnFlowPath";
             this.btnFlowPath.Size = new System.Drawing.Size(130, 26);
             this.btnFlowPath.TabIndex = 53;
@@ -142,7 +145,7 @@
             // 
             this.btnRun.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.btnRun.ForeColor = System.Drawing.SystemColors.Highlight;
-            this.btnRun.Location = new System.Drawing.Point(616, 248);
+            this.btnRun.Location = new System.Drawing.Point(616, 297);
             this.btnRun.Name = "btnRun";
             this.btnRun.Size = new System.Drawing.Size(130, 26);
             this.btnRun.TabIndex = 57;
@@ -153,7 +156,7 @@
             // txtOutPath
             // 
             this.txtOutPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.txtOutPath.Location = new System.Drawing.Point(118, 196);
+            this.txtOutPath.Location = new System.Drawing.Point(118, 245);
             this.txtOutPath.MaxLength = 2000;
             this.txtOutPath.Name = "txtOutPath";
             this.txtOutPath.Size = new System.Drawing.Size(482, 26);
@@ -164,7 +167,7 @@
             // 
             this.lblOut.AutoSize = true;
             this.lblOut.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.lblOut.Location = new System.Drawing.Point(33, 201);
+            this.lblOut.Location = new System.Drawing.Point(33, 250);
             this.lblOut.Name = "lblOut";
             this.lblOut.Size = new System.Drawing.Size(79, 16);
             this.lblOut.TabIndex = 59;
@@ -173,7 +176,7 @@
             // btnOutPath
             // 
             this.btnOutPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnOutPath.Location = new System.Drawing.Point(616, 196);
+            this.btnOutPath.Location = new System.Drawing.Point(616, 245);
             this.btnOutPath.Name = "btnOutPath";
             this.btnOutPath.Size = new System.Drawing.Size(130, 26);
             this.btnOutPath.TabIndex = 58;
@@ -183,7 +186,7 @@
             // txtServiceName
             // 
             this.txtServiceName.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.txtServiceName.Location = new System.Drawing.Point(118, 248);
+            this.txtServiceName.Location = new System.Drawing.Point(118, 297);
             this.txtServiceName.MaxLength = 2000;
             this.txtServiceName.Name = "txtServiceName";
             this.txtServiceName.Size = new System.Drawing.Size(482, 26);
@@ -194,17 +197,51 @@
             // 
             this.lblService.AutoSize = true;
             this.lblService.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.lblService.Location = new System.Drawing.Point(33, 253);
+            this.lblService.Location = new System.Drawing.Point(33, 302);
             this.lblService.Name = "lblService";
             this.lblService.Size = new System.Drawing.Size(79, 16);
             this.lblService.TabIndex = 61;
             this.lblService.Text = "鏈嶅姟鍚嶇О:";
             // 
+            // txtBuildingPath
+            // 
+            this.txtBuildingPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.txtBuildingPath.Location = new System.Drawing.Point(118, 94);
+            this.txtBuildingPath.MaxLength = 2000;
+            this.txtBuildingPath.Name = "txtBuildingPath";
+            this.txtBuildingPath.Size = new System.Drawing.Size(482, 26);
+            this.txtBuildingPath.TabIndex = 65;
+            this.txtBuildingPath.Text = "D:\\simu\\input\\tongzhou-local-mesh2-buildings.tif";
+            // 
+            // lblBuilding
+            // 
+            this.lblBuilding.AutoSize = true;
+            this.lblBuilding.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.lblBuilding.Location = new System.Drawing.Point(33, 99);
+            this.lblBuilding.Name = "lblBuilding";
+            this.lblBuilding.Size = new System.Drawing.Size(79, 16);
+            this.lblBuilding.TabIndex = 64;
+            this.lblBuilding.Text = "寤虹瓚鏁版嵁:";
+            // 
+            // btnBuildingPath
+            // 
+            this.btnBuildingPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.btnBuildingPath.Location = new System.Drawing.Point(616, 94);
+            this.btnBuildingPath.Name = "btnBuildingPath";
+            this.btnBuildingPath.Size = new System.Drawing.Size(130, 26);
+            this.btnBuildingPath.TabIndex = 63;
+            this.btnBuildingPath.Text = "閫夋嫨鍦板舰鏂囦欢";
+            this.btnBuildingPath.UseVisualStyleBackColor = true;
+            this.btnBuildingPath.Click += new System.EventHandler(this.btnBuildingPath_Click);
+            // 
             // FrmMain
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(804, 324);
+            this.ClientSize = new System.Drawing.Size(804, 364);
+            this.Controls.Add(this.txtBuildingPath);
+            this.Controls.Add(this.lblBuilding);
+            this.Controls.Add(this.btnBuildingPath);
             this.Controls.Add(this.txtServiceName);
             this.Controls.Add(this.lblService);
             this.Controls.Add(this.txtOutPath);
@@ -247,6 +284,9 @@
         private System.Windows.Forms.Button btnOutPath;
         private System.Windows.Forms.TextBox txtServiceName;
         private System.Windows.Forms.Label lblService;
+        private System.Windows.Forms.TextBox txtBuildingPath;
+        private System.Windows.Forms.Label lblBuilding;
+        private System.Windows.Forms.Button btnBuildingPath;
     }
 }
 
diff --git a/SimuTools/FrmMain.cs b/SimuTools/FrmMain.cs
index 62b2ed8..d15b5a0 100644
--- a/SimuTools/FrmMain.cs
+++ b/SimuTools/FrmMain.cs
@@ -1,4 +1,5 @@
-锘縰sing SimuTools.Tools;
+锘縰sing SimuTools.Domain;
+using SimuTools.Tools;
 using System;
 using System.IO;
 using System.Windows.Forms;
@@ -34,11 +35,21 @@
 
         private void btnTerrainPath_Click(object sender, EventArgs e)
         {
+            selectFile(this.txtTerrainPath);
+        }
+
+        private void btnBuildingPath_Click(object sender, EventArgs e)
+        {
+            selectFile(this.txtBuildingPath);
+        }
+
+        private void selectFile(TextBox tb)
+        {
             OpenFileDialog dialog = new OpenFileDialog();
             dialog.Filter = "Tif files(*.tif)|*.tif|Tiff files (*.tiff)|*.tiff";
             dialog.RestoreDirectory = true;
 
-            string path = this.txtTerrainPath.Text.Trim();
+            string path = tb.Text.Trim();
             if (File.Exists(path))
             {
                 dialog.InitialDirectory = Path.GetDirectoryName(path);
@@ -46,7 +57,7 @@
 
             if (dialog.ShowDialog() == DialogResult.OK)
             {
-                this.txtTerrainPath.Text = dialog.FileName;
+                tb.Text = dialog.FileName;
             }
         }
 
@@ -87,6 +98,7 @@
         {
             string serviceName = this.txtServiceName.Text.Trim();
             string terrainFile = this.txtTerrainPath.Text.Trim();
+            string buildingFile = this.txtBuildingPath.Text.Trim();
             string waterPath = this.txtWaterPath.Text.Trim();
             string flowPath = this.txtFlowPath.Text.Trim();
             string outPath = this.txtOutPath.Text.Trim();
@@ -96,9 +108,9 @@
                 ShowErr("鏈嶅姟鍚嶇О锛岃姹傚繀濉紒");
                 return;
             }
-            if (!File.Exists(terrainFile))
+            if (!File.Exists(terrainFile) || !File.Exists(buildingFile))
             {
-                ShowErr("鍦板舰鏂囦欢锛岃姹傚繀椤诲瓨鍦紒");
+                ShowErr("鍦板舰鍜屽缓绛戞枃浠讹紝瑕佹眰蹇呴』瀛樺湪锛�");
                 return;
             }
             if (!Directory.Exists(waterPath) || !Directory.Exists(flowPath) || !Directory.Exists(outPath))
@@ -112,13 +124,7 @@
                 this.btnRun.Enabled = false;
                 LogOut.Info("寮�濮嬭繍琛� >>");
 
-                outPath = Path.Combine(outPath, serviceName);
-                if (!Directory.Exists(outPath))
-                {
-                    Directory.CreateDirectory(outPath);
-                }
-
-                Tools.Handle.Run(terrainFile, waterPath, flowPath, outPath);
+                Tools.Handle.Run(new Args(serviceName, terrainFile, buildingFile, waterPath, flowPath, outPath));
 
                 this.btnRun.Enabled = true;
                 LogOut.Info("杩愯缁撴潫 <<");
diff --git a/SimuTools/SimuTools.csproj b/SimuTools/SimuTools.csproj
index 65be7b8..144022e 100644
--- a/SimuTools/SimuTools.csproj
+++ b/SimuTools/SimuTools.csproj
@@ -67,6 +67,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Domain\Args.cs" />
     <Compile Include="Domain\Duration.cs" />
     <Compile Include="Domain\Extension.cs" />
     <Compile Include="Domain\Layer.cs" />
diff --git a/SimuTools/Tools/Handle.cs b/SimuTools/Tools/Handle.cs
index 0b3938d..96b9021 100644
--- a/SimuTools/Tools/Handle.cs
+++ b/SimuTools/Tools/Handle.cs
@@ -32,39 +32,37 @@
         /// <summary>
         /// 杩愯
         /// </summary>
-        public static void Run(string terrainFile, string waterPath, string flowPath, string outPath)
+        public static void Run(Args args)
         {
             Domain.Layer layer = new Domain.Layer();
             layer.duration = new Duration();
             layer.terrain = new Terrain();
             layer.waters = new Water();
 
-            string temp = Path.Combine(outPath, "temp");
-            if (!Directory.Exists(temp)) Directory.CreateDirectory(temp);
+            CopeTerrain(args, layer);
+            CopeBuilding(args, layer);
+            CopeWater(args, layer);
+            CopeFlow(args, layer);
+            CopeLayerJson(args, layer);
 
-            CopeTerrain(terrainFile, waterPath, outPath, layer);
-            CopeWater(waterPath, outPath, layer);
-            CopeFlow(flowPath, outPath, layer);
-            CopeLayerJson(outPath, layer);
-
-            if (Directory.Exists(temp)) Directory.Delete(temp, true);
+            if (Directory.Exists(args.temp)) Directory.Delete(args.temp, true);
         }
 
         #region 鍦板舰
         /// <summary>
         /// 澶勭悊鍦板舰
         /// </summary>
-        private static void CopeTerrain(string terrainFile, string waterPath, string outPath, Domain.Layer layer)
+        private static void CopeTerrain(Args args, Domain.Layer layer)
         {
             Dataset ds = null;
             try
             {
-                ds = Gdal.Open(terrainFile, Access.GA_ReadOnly);
+                ds = Gdal.Open(args.terrainFile, Access.GA_ReadOnly);
                 if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return;
 
                 SetTerrainInfo(ds, layer);
-                SetWaterInfo(waterPath, layer);
-                CreateTerrainPng(ds, layer, outPath);
+                SetWaterInfo(args, layer);
+                CreateTerrainPng(args, ds, layer);
             }
             finally
             {
@@ -113,16 +111,14 @@
         /// <summary>
         /// 鍒涘缓鍦板舰PNG
         /// </summary>
-        private static void CreateTerrainPng(Dataset ds, Domain.Layer layer, string outPath)
+        private static void CreateTerrainPng(Args args, Dataset ds, Domain.Layer layer)
         {
-            string tempPath = Path.Combine(outPath, "temp");
-            if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
-            string terrainPath = Path.Combine(outPath, "terrain");
+            string terrainPath = Path.Combine(args.outPath, "terrain");
             if (!Directory.Exists(terrainPath)) Directory.CreateDirectory(terrainPath);
 
             foreach (int[] sizes in layer.terrain.size)
             {
-                string tif = Path.Combine(tempPath, DateTime.Now.Ticks.ToString() + ".tif");
+                string tif = Path.Combine(args.temp, "terrain_" + sizes[0] + "_" + sizes[1] + ".tif");
                 //Resample(ds.GetDescription(), tif, sizes[0], sizes[1]);
                 Resample(ds, tif, sizes[0], sizes[1], layer);
                 if (!File.Exists(tif)) continue;
@@ -166,7 +162,7 @@
                 ds = Gdal.Open(tif, Access.GA_ReadOnly);
                 if (null == ds || 0 == ds.RasterCount) return;
 
-                OSGeo.GDAL.Band band = ds.GetRasterBand(1);
+                Band band = ds.GetRasterBand(1);
                 float[] buffer = new float[width * height];
                 band.ReadRaster(0, 0, width, height, buffer, width, height, 0, 0);
 
@@ -175,7 +171,6 @@
                 graphic.Clear(Color.Transparent); // 濉厖閫忔槑鑹�
 
                 //double perHeight = (layer.terrain.maxHeight - layer.terrain.minHeight) * 100 / 65536;
-                //double differ = layer.terrain.maxHeight - layer.terrain.minHeight;
                 double differ = layer.extension.maxHeight - layer.extension.minHeight, minHeight = layer.extension.minHeight;
                 for (int x = 0; x < width; x++)
                 {
@@ -186,7 +181,6 @@
 
                         //int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) * 100 / perHeight);
                         //int val = Convert.ToInt32((buffer[offset] - layer.terrain.minHeight) / differ * 255); // 65535
-
                         int r = 0, g, b;
                         if (buffer[offset] - layer.extension.maxHeight > 0)
                         {
@@ -213,13 +207,48 @@
         }
         #endregion
 
+        #region 寤虹瓚
+        /// <summary>
+        /// 澶勭悊寤虹瓚
+        /// </summary>
+        private static void CopeBuilding(Args args, Domain.Layer layer)
+        {
+            Dataset ds = null;
+            try
+            {
+                ds = Gdal.Open(args.buildingFile, Access.GA_ReadOnly);
+                if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return;
+
+                foreach (int[] sizes in layer.terrain.size)
+                {
+                    string tif = Path.Combine(args.temp, "building_" + sizes[0] + "_" + sizes[1] + ".tif");
+                    Resample(ds, tif, sizes[0], sizes[1], layer);
+                    if (!File.Exists(tif)) continue;
+
+                    Dataset dataset = Gdal.Open(tif, Access.GA_ReadOnly);
+                    if (null == dataset || 0 == dataset.RasterCount) return;
+
+                    float[] buffer = new float[sizes[0] * sizes[1]];
+                    dataset.GetRasterBand(1).ReadRaster(0, 0, sizes[0], sizes[1], buffer, sizes[0], sizes[1], 0, 0);
+                    args.buildings[sizes[0] + "_" + sizes[1]] = buffer;
+
+                    dataset.Dispose();
+                }
+            }
+            finally
+            {
+                if (null != ds) ds.Dispose();
+            }
+        }
+        #endregion
+
         #region 姘撮潰
         /// <summary>
         /// 璁剧疆姘撮潰淇℃伅
         /// </summary>
-        private static void SetWaterInfo(string waterPath, Domain.Layer layer)
+        private static void SetWaterInfo(Args args, Domain.Layer layer)
         {
-            List<string> files = layer.waters.files = GetFiles(waterPath);
+            List<string> files = layer.waters.files = GetFiles(args.waterPath);
             if (null == files || files.Count == 0) return;
 
             SetWaterData(layer, files);
@@ -229,12 +258,12 @@
         /// <summary>
         /// 澶勭悊姘撮潰
         /// </summary>
-        private static void CopeWater(string waterPath, string outPath, Domain.Layer layer)
+        private static void CopeWater(Args args, Domain.Layer layer)
         {
             List<String> files = layer.waters.files;
             if (files.Count == 0 || files.Count != layer.waters.data.Count) return;
 
-            ProcessWaters(files, outPath, layer);
+            ProcessWaters(args, files, layer);
         }
 
         /// <summary>
@@ -302,7 +331,7 @@
         /// <summary>
         /// 澶勭悊姘撮潰鏁版嵁
         /// </summary>
-        private static void ProcessWaters(List<string> files, string outPath, Domain.Layer layer)
+        private static void ProcessWaters(Args args, List<string> files, Domain.Layer layer)
         {
             Parallel.For(0, files.Count, i =>
             //for (int i = 0; i < files.Count; i++)
@@ -313,7 +342,7 @@
                     ds = Gdal.Open(files[i], Access.GA_ReadOnly);
                     if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return;
 
-                    CreateWaterPng(ds, layer, outPath, layer.waters.data[i]);
+                    CreateWaterPng(args, ds, layer, layer.waters.data[i]);
                 }
                 finally
                 {
@@ -325,29 +354,27 @@
         /// <summary>
         /// 鍒涘缓姘撮潰PNG
         /// </summary>
-        private static void CreateWaterPng(Dataset ds, Domain.Layer layer, string outPath, long ticks)
+        private static void CreateWaterPng(Args args, Dataset ds, Domain.Layer layer, long ticks)
         {
-            string tempPath = Path.Combine(outPath, "temp");
-            if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
-            string waterPath = Path.Combine(outPath, "waters", ticks.ToString());
+            string waterPath = Path.Combine(args.outPath, "waters", ticks.ToString());
             if (!Directory.Exists(waterPath)) Directory.CreateDirectory(waterPath);
 
             foreach (int[] sizes in layer.terrain.size)
             {
                 string fileName = Path.GetFileNameWithoutExtension(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
-                string tif = Path.Combine(tempPath, fileName + ".tif");
+                string tif = Path.Combine(args.temp, fileName + ".tif");
                 Resample(ds, tif, sizes[0], sizes[1], layer);
                 if (!File.Exists(tif)) continue;
 
                 string png = Path.Combine(waterPath, sizes[0] + "_" + sizes[1] + ".png");
-                Water2Png(layer, tif, png, sizes[0], sizes[1]);
+                Water2Png(args, layer, tif, png, sizes[0], sizes[1]);
             }
         }
 
         /// <summary>
         /// 姘撮潰杞琍NG
         /// </summary>
-        private static void Water2Png(Domain.Layer layer, string tif, string png, int width, int height)
+        private static void Water2Png(Args args, Domain.Layer layer, string tif, string png, int width, int height)
         {
             Dataset ds = null;
             try
@@ -358,6 +385,7 @@
                 Band band = ds.GetRasterBand(1);
                 float[] buffer = new float[width * height];
                 band.ReadRaster(0, 0, width, height, buffer, width, height, 0, 0);
+                float[] building = args.buildings[width + "_" + height];
 
                 Bitmap image = new Bitmap(width, height);
                 Graphics graphic = Graphics.FromImage(image);
@@ -371,13 +399,9 @@
                     {
                         int offset = x + y * width;
                         if (float.IsNaN(buffer[offset]) || buffer[offset] < -999 || buffer[offset] < minHeight) continue;
+                        if (!float.IsNaN(building[offset]) && building[offset] > -999) continue;
 
-                        //int val = Convert.ToInt32(buffer[offset] * 100);
                         //int val = Convert.ToInt32((buffer[offset] - layer.extension.minHeight + WaterHeightOffset) * 100 / perHeight);
-                        //int r = val / 65536;
-                        //int g = (val - r * 65536) / 256;
-                        //int b = val % 256;
-
                         int r = 0, g, b;
                         if (buffer[offset] - layer.extension.maxHeight > 0)
                         {
@@ -408,10 +432,10 @@
         /// <summary>
         /// 澶勭悊娴侀�熸祦鍚�
         /// </summary>
-        private static void CopeFlow(string flowPath, string outPath, Domain.Layer layer)
+        private static void CopeFlow(Args args, Domain.Layer layer)
         {
-            List<string> vxFiles = GetFiles(flowPath, "vx");
-            List<string> vyFiles = GetFiles(flowPath, "vy");
+            List<string> vxFiles = GetFiles(args.flowPath, "vx");
+            List<string> vyFiles = GetFiles(args.flowPath, "vy");
             if (null == vxFiles || null == vyFiles || vxFiles.Count != vyFiles.Count || vxFiles.Count != layer.waters.data.Count) return;
 
             Parallel.For(0, vxFiles.Count, i =>
@@ -425,7 +449,7 @@
                     if (null == vxDs || 0 == vxDs.RasterCount || null == vxDs.GetSpatialRef() ||
                         null == vyDs || 0 == vyDs.RasterCount || null == vyDs.GetSpatialRef()) return;
 
-                    CreateFlowPng(vxDs, vyDs, layer, outPath, layer.waters.data[i]);
+                    CreateFlowPng(args, vxDs, vyDs, layer, layer.waters.data[i]);
                 }
                 finally
                 {
@@ -438,21 +462,19 @@
         /// <summary>
         /// 鍒涘缓娴侀�熸祦鍚慞NG
         /// </summary>
-        private static void CreateFlowPng(Dataset vxDs, Dataset vyDs, Domain.Layer layer, string outPath, long ticks)
+        private static void CreateFlowPng(Args args, Dataset vxDs, Dataset vyDs, Domain.Layer layer, long ticks)
         {
-            string tempPath = Path.Combine(outPath, "temp");
-            if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
-            string flowPath = Path.Combine(outPath, "flows", ticks.ToString());
+            string flowPath = Path.Combine(args.outPath, "flows", ticks.ToString());
             if (!Directory.Exists(flowPath)) Directory.CreateDirectory(flowPath);
 
             foreach (int[] sizes in layer.terrain.size)
             {
                 string vxName = Path.GetFileNameWithoutExtension(vxDs.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
-                string vxTif = Path.Combine(tempPath, vxName + ".tif");
+                string vxTif = Path.Combine(args.temp, vxName + ".tif");
                 Resample(vxDs, vxTif, sizes[0], sizes[1], layer);
 
                 string vyName = Path.GetFileNameWithoutExtension(vyDs.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
-                string vyTif = Path.Combine(tempPath, vyName + ".tif");
+                string vyTif = Path.Combine(args.temp, vyName + ".tif");
                 Resample(vyDs, vyTif, sizes[0], sizes[1], layer);
 
                 if (!File.Exists(vxTif) || !File.Exists(vyTif)) continue;
@@ -547,13 +569,13 @@
         /// <summary>
         /// 澶勭悊鍏冩暟鎹�
         /// </summary>
-        private static void CopeLayerJson(string outPath, Domain.Layer layer)
+        private static void CopeLayerJson(Args args, Domain.Layer layer)
         {
             if (null == layer) return;
 
             String json = JsonConvert.SerializeObject(layer);
 
-            string filePath = Path.Combine(outPath, "layer.json");
+            string filePath = Path.Combine(args.outPath, "layer.json");
             using (StreamWriter sw = new StreamWriter(filePath))
             {
                 sw.Write(json);
@@ -565,12 +587,9 @@
         /// <summary>
         /// 璁剧疆鍦板舰淇℃伅
         /// </summary>
-        private static void SetTerrainInfo(Dataset ds, string outPath, Domain.Layer layer)
+        private static void SetTerrainInfo(Args args, Dataset ds, Domain.Layer layer)
         {
-            string tempPath = Path.Combine(outPath, "temp");
-            if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
-
-            string tif = Path.Combine(tempPath, Path.GetFileNameWithoutExtension(ds.GetDescription()) + ".tif");
+            string tif = Path.Combine(args.temp, Path.GetFileNameWithoutExtension(ds.GetDescription()) + ".tif");
             Resample(ds, tif);
             if (!File.Exists(tif)) throw new Exception("楂樼▼鏂囦欢閲嶆姇褰卞け璐ワ紒");
 

--
Gitblit v1.9.3