管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-07-18 0a70f99e51b0ea0c83288213e3b1f7904d78ede0
创建PNG
已修改3个文件
91 ■■■■ 文件已修改
SimuTools/FrmMain.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/Tools/GdalHelper.cs 74 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/Tools/Handle.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/FrmMain.cs
@@ -113,7 +113,7 @@
            try
            {
                flag = true;
                LogOut.Info(">> 开始运行 >>");
                LogOut.Info("开始运行 >>");
                outPath = Path.Combine(outPath, serviceName);
                if (!Directory.Exists(outPath))
@@ -124,7 +124,7 @@
                Tools.Handle.Run(terrainFile, waterPath, flowPath, outPath);
                flag = false;
                LogOut.Info("<< 运行结束 <<");
                LogOut.Info("运行结束 <<");
                MessageBox.Show("运行结束!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
SimuTools/Tools/GdalHelper.cs
@@ -4,9 +4,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimuTools.Tools
{
@@ -83,9 +80,9 @@
            Gdal.AllRegister();
        }
        /**
         * 获取Dataset的最小点
         */
        /// <summary>
        /// 获取Dataset的最小点
        /// </summary>
        public static Geometry GetMinPoint(Dataset ds)
        {
            double[] transform = new double[6];
@@ -100,9 +97,9 @@
            return Transform(ds, point);
        }
        /**
         * 获取Dataset的最大点
         */
        /// <summary>
        /// 获取Dataset的最大点
        /// </summary>
        public static Geometry GetMaxPoint(Dataset ds)
        {
            /*
@@ -126,9 +123,9 @@
            return Transform(ds, point);
        }
        /**
         * 坐标转换
         */
        /// <summary>
        /// 坐标转换
        /// </summary>
        public static Geometry Transform(Dataset ds, Geometry point)
        {
            point.AssignSpatialReference(ds.GetSpatialRef());
@@ -151,9 +148,9 @@
            return point;
        }
        /**
         * 创建金字塔
         */
        /// <summary>
        /// 创建金字塔
        /// </summary>
        public static void CreatePyramid(String file)
        {
            Dataset ds = null;
@@ -164,7 +161,7 @@
                ds = Gdal.Open(file, Access.GA_ReadOnly);
                if (null == ds) return;
                Band band = ds.GetRasterBand(1);
                OSGeo.GDAL.Band band = ds.GetRasterBand(1);
                if (0 == band.GetOverviewCount())
                {
                    ds.BuildOverviews("nearest", new int[] { 2, 4, 6, 8, 16 });
@@ -179,5 +176,50 @@
                if (null != ds) ds.Dispose();
            }
        }
        /// <summary>
        /// 创建PNG
        /// </summary>
        public void CreatePng(string filePath, int width, int height, int bands = 3)
        {
            // 创建内存驱动
            OSGeo.GDAL.Driver memDriver = Gdal.GetDriverByName("MEM");
            // 创建内存数据集
            Dataset ds = memDriver.Create("mem::", width, height, bands, DataType.GDT_Byte, null);
            // 设置图像信息
            for (int i = 1; i <= bands; i++)
            {
                Band band = ds.GetRasterBand(i);
                band.SetRasterColorInterpretation((ColorInterp)i);
            }
            // 填充内存图像
            byte[] buffer = new byte[width * height * bands];
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = (byte)(i % 256);
            }
            // 写入内存图像
            for (int i = 1; i <= bands; i++)
            {
                Band band = ds.GetRasterBand(i);
                band.WriteRaster(0, 0, width, height, buffer, width, height, 0, 0);
            }
            // 创建PNG驱动
            OSGeo.GDAL.Driver pngDriver = Gdal.GetDriverByName("PNG");
            // 保存为PNG文件
            //ds.SetProjection(Gdal.GetProjectionRef(""));
            //ds.SetGeoTransform(Gdal.GetGeoTransform(""));
            pngDriver.CreateCopy(filePath, ds, 0, null, null, null);
            pngDriver.Dispose();
            // 关闭数据集
            ds.Dispose();
            memDriver.Dispose();
        }
    }
}
SimuTools/Tools/Handle.cs
@@ -22,6 +22,7 @@
        {
            Domain.Layer layer = new Domain.Layer();
            layer.duration = new Duration();
            layer.terrain = new Terrain();
            layer.waters = new Water();
            CopeTerrain(terrainFile, outPath, layer);
@@ -42,6 +43,7 @@
                if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return;
                SetTerrainInfo(ds, layer);
                CreateTerrainPng(ds, layer, outPath);
            }
            finally
            {
@@ -65,6 +67,17 @@
        }
        /// <summary>
        /// 创建地形图层
        /// </summary>
        private static void CreateTerrainPng(Dataset ds, Domain.Layer layer, string outPath)
        {
            foreach (int[] sizes in layer.terrain.size)
            {
            }
        }
        /// <summary>
        /// 处理水面
        /// </summary>
        private static void CopeWater(string waterPath, string outPath, Domain.Layer layer)