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 +++++++++++++++++++++++++++++++++++++++---- ExportMap/Controllers/ConvertController.cs | 2 ++ ExportMap/export.html | 2 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/ExportMap/Controllers/ConvertController.cs b/ExportMap/Controllers/ConvertController.cs index ea51baa..9b29a17 100644 --- a/ExportMap/Controllers/ConvertController.cs +++ b/ExportMap/Controllers/ConvertController.cs @@ -26,6 +26,8 @@ //TerrainUtils.Project("D:/xyz/dem/dem/32a_4326_.tif", "EPSG:4490"); + //string wkt = TerrainUtils.GetPointZ(new XYZArgs() { dircode = "0B" }); + return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } 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) diff --git a/ExportMap/export.html b/ExportMap/export.html index 12f8ef2..15f15ee 100644 --- a/ExportMap/export.html +++ b/ExportMap/export.html @@ -10,7 +10,7 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="js/jquery.1.12.4.js"></script> <script> - var token = "0b8d4418-d7bd-4846-ba45-edccf42e87c3"; + var token = "ec6fb7ec-705d-483c-a87a-21a1478dbd64"; $(function () { $("#token").html(token); -- Gitblit v1.9.3