管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-07-18 0a70f99e51b0ea0c83288213e3b1f7904d78ede0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using Newtonsoft.Json;
using OSGeo.GDAL;
using OSGeo.OGR;
using SimuTools.Domain;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace SimuTools.Tools
{
    public class Handle
    {
        public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
 
        /// <summary>
        /// 运行
        /// </summary>
        public static void Run(string terrainFile, string waterPath, string flowPath, string outPath)
        {
            Domain.Layer layer = new Domain.Layer();
            layer.duration = new Duration();
            layer.terrain = new Terrain();
            layer.waters = new Water();
 
            CopeTerrain(terrainFile, outPath, layer);
            CopeWater(waterPath, outPath, layer);
            CopeFlow(flowPath, outPath, layer);
            CopeLayerJson(outPath, layer);
        }
 
        /// <summary>
        /// 处理地形
        /// </summary>
        private static void CopeTerrain(string terrainFile, string outPath, Domain.Layer layer)
        {
            Dataset ds = null;
            try
            {
                ds = Gdal.Open(terrainFile, Access.GA_ReadOnly);
                if (null == ds || 0 == ds.RasterCount || null == ds.GetSpatialRef()) return;
 
                SetTerrainInfo(ds, layer);
                CreateTerrainPng(ds, layer, outPath);
            }
            finally
            {
                if (null != ds) ds.Dispose();
            }
        }
 
        /// <summary>
        /// 设置地形信息
        /// </summary>
        private static void SetTerrainInfo(Dataset ds, Domain.Layer layer)
        {
            Geometry minPoint = GdalHelper.GetMinPoint(ds);
            Geometry maxPoint = GdalHelper.GetMaxPoint(ds);
            layer.extension = new Extension(minPoint.GetX(0), minPoint.GetY(0), maxPoint.GetX(0), maxPoint.GetY(0));
 
            Band band = ds.GetRasterBand(1);
            double[] mm = new double[2];
            band.ComputeRasterMinMax(mm, 0);
            layer.extension.SetHeight(mm[0], mm[1]);
        }
 
        /// <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)
        {
 
        }
 
        /// <summary>
        /// 处理流速流向
        /// </summary>
        private static void CopeFlow(string flowPath, string outPath, Domain.Layer layer)
        {
 
        }
 
        /// <summary>
        /// 处理元数据
        /// </summary>
        private static void CopeLayerJson(string outPath, Domain.Layer layer)
        {
            if (null == layer) return;
 
            String json = JsonConvert.SerializeObject(layer);
 
            string filePath = Path.Combine(outPath, "layer.json");
            using (StreamWriter sw = new StreamWriter(filePath))
            {
                sw.Write(json);
            }
        }
    }
}