From 81d9f361726e760ffd69cd000cb2e154d4cd3749 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 06 十二月 2023 14:45:07 +0800 Subject: [PATCH] 添加地形处理程序 --- JavaCode/cs/TerrainHelper.cs | 77 ++++++++++++++++++++++++++++++++++++++ JavaCode/FrmMain.Designer.cs | 14 +++++++ JavaCode/FrmMain.cs | 5 ++ JavaCode/JavaCode.csproj | 1 4 files changed, 97 insertions(+), 0 deletions(-) diff --git a/JavaCode/FrmMain.Designer.cs b/JavaCode/FrmMain.Designer.cs index 549e673..88acdec 100644 --- a/JavaCode/FrmMain.Designer.cs +++ b/JavaCode/FrmMain.Designer.cs @@ -31,6 +31,7 @@ this.btnSys = new System.Windows.Forms.Button(); this.btnMybatis = new System.Windows.Forms.Button(); this.btnQGis = new System.Windows.Forms.Button(); + this.btnTerrain = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnSys @@ -66,11 +67,23 @@ this.btnQGis.UseVisualStyleBackColor = true; this.btnQGis.Click += new System.EventHandler(this.btnQGis_Click); // + // btnTerrain + // + this.btnTerrain.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnTerrain.Location = new System.Drawing.Point(143, 197); + this.btnTerrain.Name = "btnTerrain"; + this.btnTerrain.Size = new System.Drawing.Size(183, 25); + this.btnTerrain.TabIndex = 16; + this.btnTerrain.Text = "鍦� 褰� 鏂� 浠� 澶� 鐞�"; + this.btnTerrain.UseVisualStyleBackColor = true; + this.btnTerrain.Click += new System.EventHandler(this.btnTerrain_Click); + // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(484, 261); + this.Controls.Add(this.btnTerrain); this.Controls.Add(this.btnQGis); this.Controls.Add(this.btnMybatis); this.Controls.Add(this.btnSys); @@ -86,5 +99,6 @@ private System.Windows.Forms.Button btnSys; private System.Windows.Forms.Button btnMybatis; private System.Windows.Forms.Button btnQGis; + private System.Windows.Forms.Button btnTerrain; } } \ No newline at end of file diff --git a/JavaCode/FrmMain.cs b/JavaCode/FrmMain.cs index 847b0cc..285593a 100644 --- a/JavaCode/FrmMain.cs +++ b/JavaCode/FrmMain.cs @@ -34,5 +34,10 @@ { QGisHelper.Create(); } + + private void btnTerrain_Click(object sender, EventArgs e) + { + TerrainHelper.RemoveTerrain(); + } } } diff --git a/JavaCode/JavaCode.csproj b/JavaCode/JavaCode.csproj index 7d1c7c9..db95c31 100644 --- a/JavaCode/JavaCode.csproj +++ b/JavaCode/JavaCode.csproj @@ -78,6 +78,7 @@ <Compile Include="cs\PostgreHelper.cs" /> <Compile Include="cs\QGisHelper.cs" /> <Compile Include="cs\TabInfo.cs" /> + <Compile Include="cs\TerrainHelper.cs" /> <Compile Include="FrmMain.cs"> <SubType>Form</SubType> </Compile> diff --git a/JavaCode/cs/TerrainHelper.cs b/JavaCode/cs/TerrainHelper.cs new file mode 100644 index 0000000..9acc1bc --- /dev/null +++ b/JavaCode/cs/TerrainHelper.cs @@ -0,0 +1,77 @@ +锘縰sing System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JavaCode.cs +{ + public class TerrainHelper + { + public static void RemoveTerrain() + { + char[] chars = new char[] { ',' }; + string folder = @"E:\data\35.ty\terrain"; + string[] strs = File.ReadAllLines(folder + "\\layer.json"); + + int i = -1; + foreach (string str in strs) + { + if (!str.Contains("[ {")) continue; + + i++; + if (i < 5 || i > 12) continue; + + // ,[ { "startX": 6604, "startY": 2834, "endX": 6702, "endY": 2975 } ] + string[] vals = str.Replace("startX", "").Replace("startY", "").Replace("endX", "").Replace("endY", "").Replace("[ {", "").Replace("} ]", "").Replace("\"", "").Replace(":", "").Replace(" ", "").Split(chars, StringSplitOptions.RemoveEmptyEntries); + + int startX = int.Parse(vals[0]), startY = int.Parse(vals[1]), endX = int.Parse(vals[2]), endY = int.Parse(vals[3]); + RemoveFiles(folder, i, startX, endX, startY, endY); + } + } + + private static void RemoveFiles(string folder, int level, int startX, int endX, int startY, int endY) + { + string path = Path.Combine(folder, level.ToString()); + if (!Directory.Exists(path)) return; + + string[] dirs = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly); + foreach (string dir in dirs) + { + string dirName = Path.GetFileName(dir); + + int d = 0; + if (!int.TryParse(dirName, out d)) + { + Directory.Delete(dir, true); + continue; + } + + if (d < startX || d > endX) + { + Directory.Delete(dir, true); + continue; + } + + string[] files = Directory.GetFiles(dir); + foreach (string file in files) + { + string fileName = Path.GetFileName(file).Replace(".terrain", ""); + + int f= 0; + if (!int.TryParse(fileName, out f)) + { + File.Delete(file); + continue; + } + + if (f < startY || f > endY) + { + File.Delete(file); + } + } + } + } + } +} -- Gitblit v1.9.3