¶Ô±ÈÐÂÎļþ |
| | |
| | | using 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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 |
| | |
| | | // 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); |
| | |
| | | // |
| | | 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; |
| | |
| | | // 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; |
| | |
| | | // 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); |
| | |
| | | // |
| | | 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; |
| | |
| | | // 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; |
| | |
| | | // |
| | | 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; |
| | |
| | | // 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); |
| | |
| | | // |
| | | 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; |
| | |
| | | // 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; |
| | |
| | | // 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); |
| | |
| | | // |
| | | 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); |
| | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | |
| | | using SimuTools.Tools; |
| | | using SimuTools.Domain; |
| | | using SimuTools.Tools; |
| | | using System; |
| | | using System.IO; |
| | | using System.Windows.Forms; |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | if (dialog.ShowDialog() == DialogResult.OK) |
| | | { |
| | | this.txtTerrainPath.Text = dialog.FileName; |
| | | tb.Text = dialog.FileName; |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | 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(); |
| | |
| | | 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)) |
| | |
| | | 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("è¿è¡ç»æ <<"); |
| | |
| | | <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" /> |
| | |
| | | /// <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 |
| | | { |
| | |
| | | /// <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; |
| | |
| | | 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); |
| | | |
| | |
| | | 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++) |
| | | { |
| | |
| | | |
| | | //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) |
| | | { |
| | |
| | | } |
| | | #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); |
| | |
| | | /// <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> |
| | |
| | | /// <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++) |
| | |
| | | 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 |
| | | { |
| | |
| | | /// <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> |
| | | /// æ°´é¢è½¬PNG |
| | | /// </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 |
| | |
| | | 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); |
| | |
| | | { |
| | | 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) |
| | | { |
| | |
| | | /// <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 => |
| | |
| | | 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 |
| | | { |
| | |
| | | /// <summary> |
| | | /// å建æµéæµåPNG |
| | | /// </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; |
| | |
| | | /// <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); |
| | |
| | | /// <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("é«ç¨æä»¶éæå½±å¤±è´¥ï¼"); |
| | | |