From ad762577f716b7c0c5a21f5deeda00658fe8ed94 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 20 九月 2023 09:32:50 +0800 Subject: [PATCH] 添加获取高程的中心点位置功能 --- ExportMap/cs/TerrainUtils.cs | 43 +++++++++++++++++++++++++++++++++++++++---- 1 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ExportMap/cs/TerrainUtils.cs b/ExportMap/cs/TerrainUtils.cs index 19287c8..8a55491 100644 --- a/ExportMap/cs/TerrainUtils.cs +++ b/ExportMap/cs/TerrainUtils.cs @@ -96,8 +96,7 @@ } } - string vrt = CreateLayerJson(args, files, ref err); - + CreateLayerJson(args, files, ref err); string json = Path.Combine(dirPath, "layer.json"); if (!File.Exists(json)) return PrintInfo("鎵句笉鍒發ayer.json鏂囦欢"); @@ -307,14 +306,50 @@ /// <summary> /// 鑾峰彇涓績鐐� /// </summary> - private static string GetPointZ(XYZArgs args) + public static string GetPointZ(XYZArgs args) { - double x = 0, y = 0; + string dirPath = GetTerrainPath(args.dircode); + string vrt = Path.Combine(dirPath, "subs", "dem.vrt"); + if (!File.Exists(vrt)) return null; + + string gdalPath = Tools.GetSetting("gdalPath"); + string cmd = string.Format("\"{0}\\gdalinfo.exe\" \"{1}\"", gdalPath, vrt); + + string rs = null; + Tools.ExecCmd(new List<string> { cmd }, ref rs); + string center = GetCenter(rs); + if (string.IsNullOrEmpty(rs)) return null; + + string[] strs = center.Split(new string[] { "," }, StringSplitOptions.None); + double x = double.Parse(strs[0]); + double y = double.Parse(strs[1]); return string.Format("ST_GeomFromText('POINT Z ({0} {1} {2})')", x, y, 12); } /// <summary> + /// 鑾峰彇涓績鍧愭爣 + /// </summary> + private static string GetCenter(string rs) + { + if (string.IsNullOrEmpty(rs)) return null; + + string[] strs = rs.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + foreach (string str in strs) + { + if (str.StartsWith("Center ")) + { + int start = str.IndexOf("("); + int end = str.IndexOf(")"); + + return str.Substring(start + 1, end - start - 1).Replace(" ", ""); + } + } + + return null; + } + + /// <summary> /// 閲嶆姇褰� /// </summary> public static void Reproject(string sourceFile, string targetFile, string sourceSrs, string targetSrs) -- Gitblit v1.9.3