管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-07-22 7fb323da219c84d0275e2e1138747899d8cdc40a
1
已修改1个文件
40 ■■■■■ 文件已修改
SimuTools/Tools/Handle.cs 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/Tools/Handle.cs
@@ -9,7 +9,6 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimuTools.Tools
@@ -350,8 +349,8 @@
            List<string> vyFiles = GetFiles(flowPath, "vy");
            if (null == vxFiles || null == vyFiles || vxFiles.Count != vyFiles.Count || vxFiles.Count != layer.waters.data.Count) return;
            //Parallel.For(0, vxFiles.Count, i =>
            for (int i = 0; i < vxFiles.Count; i++)
            Parallel.For(0, vxFiles.Count, i =>
            //for (int i = 0; i < vxFiles.Count; i++)
            {
                Dataset vxDs = null, vyDs = null;
                try
@@ -368,7 +367,7 @@
                    if (null != vxDs) vxDs.Dispose();
                    if (null != vyDs) vyDs.Dispose();
                }
            }
            });
        }
        /// <summary>
@@ -414,6 +413,29 @@
                vxDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vxBuffer, width, height, 0, 0);
                vyDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vyBuffer, width, height, 0, 0);
                //double[] vxMm = new double[2];
                //vxDs.GetRasterBand(1).ComputeRasterMinMax(vxMm, 0);
                //double[] vyMm = new double[2];
                //vyDs.GetRasterBand(1).ComputeRasterMinMax(vyMm, 0);
                //double min = vxMm[0] < vyMm[0] ? vxMm[0] : vyMm[0];
                //double max = vxMm[1] > vyMm[1] ? vxMm[1] : vyMm[1];
                CreateFlowPng(vxBuffer, vyBuffer, png, width, height);
            }
            finally
            {
                if (null != vxDs) vxDs.Dispose();
                if (null != vyDs) vyDs.Dispose();
                if (File.Exists(vxTif)) File.Delete(vxTif);
                if (File.Exists(vyTif)) File.Delete(vyTif);
            }
        }
        /// <summary>
        /// 创建流速流向PNG
        /// </summary>
        private static void CreateFlowPng(float[] vxBuffer, float[] vyBuffer, string png, int width, int height)
        {
                Bitmap image = new Bitmap(width, height);
                Graphics graphic = Graphics.FromImage(image);
                graphic.Clear(Color.Transparent); // 填充透明色
@@ -432,6 +454,7 @@
                        double dy = float.IsNaN(fy) ? 0 : fy * 0.5 + 0.5;
                        int r = Convert.ToInt32(dv * 255);
                    if (r > 255) r = 255;
                        int g = Convert.ToInt32(dx * 255);
                        int b = Convert.ToInt32(dy * 255);
@@ -439,16 +462,7 @@
                        image.SetPixel(x, y, color);
                    }
                }
                image.Save(png, System.Drawing.Imaging.ImageFormat.Png);
            }
            finally
            {
                if (null != vxDs) vxDs.Dispose();
                if (null != vyDs) vyDs.Dispose();
                if (File.Exists(vxTif)) File.Delete(vxTif);
                if (File.Exists(vyTif)) File.Delete(vyTif);
            }
        }
        /// <summary>