管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-09-23 ca69628172dbbc8e576ae55d588e99262bb8ac19
ExportMap/cs/TerrainUtils.cs
@@ -82,12 +82,19 @@
                string uploadFolder = Tools.GetSetting("uploadFolder");
                foreach (SysMeta meta in metas)
                {
                    if (metsIds.Contains(meta.id)) return PrintInfo("元数据[" + meta.id + "] 已发布。");
                    if (metsIds.Contains(meta.id))
                    {
                        PrintInfo("元数据[" + meta.id + "] 已发布。");
                        continue;
                    }
                    string sourceFile = Path.Combine(uploadFolder, meta.path);
                    if (!File.Exists(sourceFile)) return PrintInfo("元数据[" + meta.id + "] 不存在。");
                    if (!File.Exists(sourceFile))
                    {
                        PrintInfo("元数据[" + meta.id + "] 不存在。");
                        continue;
                    }
                    string targetFile = Path.Combine(subPath, meta.name);
                    string targetFile = Path.Combine(subPath, meta.id + ".tif"); // meta.path.Split(new string[] { "\\", "//" }, StringSplitOptions.None)[1]
                    ConvertRaster(sourceFile, targetFile);
                    if (File.Exists(targetFile))
                    {
@@ -96,8 +103,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("找不到layer.json文件");
@@ -225,7 +231,7 @@
        /// <summary>
        /// 补充文件
        /// </summary>
        private static void Complement(XYZArgs args)
        public static void Complement(XYZArgs args)
        {
            string dirPath = GetTerrainPath(args.dircode);
            string p_0_0 = Path.Combine(dirPath, "0", "0");
@@ -234,13 +240,12 @@
            string p_0_1 = Path.Combine(dirPath, "0", "1");
            if (!Directory.Exists(p_0_1)) Directory.CreateDirectory(p_0_1);
            string s_0_0_0 = Path.Combine(SGUtils.LFData, "dem", "0", "0", "0.terrain");
            string s_0 = Tools.BaseDir + "\\Sources\\0.terrain";
            string d_0_0_0 = Path.Combine(dirPath, "0", "0", "0.terrain");
            if (!File.Exists(d_0_0_0)) File.Copy(s_0_0_0, d_0_0_0, true);
            if (!File.Exists(d_0_0_0)) File.Copy(s_0, d_0_0_0, true);
            string s_0_1_0 = Path.Combine(SGUtils.LFData, "dem", "0", "1", "0.terrain");
            string d_0_1_0 = Path.Combine(dirPath, "0", "1", "0.terrain");
            if (!File.Exists(d_0_1_0)) File.Copy(s_0_1_0, d_0_1_0, true);
            if (!File.Exists(d_0_1_0)) File.Copy(s_0, d_0_1_0, true);
            string layerJson = Path.Combine(dirPath, "layer.json");
            string[] lines = File.ReadAllLines(layerJson, Encoding.UTF8);
@@ -272,7 +277,7 @@
                    if (!ids.Contains(m.id)) PubDBHelper.InsertMetaPub(m.id, pubid, args.userId);
                }
                string geom = GetPointZ(args);
                PubDBHelper.UpdatePublish(pubid, args.name, args.userId, geom);
                int rows = PubDBHelper.UpdatePublish(pubid, args.name, args.userId, geom);
                return pubid;
            }
@@ -307,11 +312,47 @@
        /// <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;
            return string.Format("ST_GeomFromText('POINT Z ({0} {1} {2})')", x, y, 12);
            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})')", y, x, 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>