| | |
| | | { |
| | | private static string pyFile; |
| | | |
| | | public static int DEFAULT_MAX_LEVEL = 16; |
| | | |
| | | /// <summary> |
| | | /// 获取Python文件 |
| | | /// </summary> |
| | |
| | | if (null == metas || metas.Count == 0) return null; |
| | | |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | if (Directory.Exists(dirPath)) Tools.DelPath(dirPath); |
| | | //if (Directory.Exists(dirPath)) Tools.DelPath(dirPath); // 已存在的,删除 |
| | | |
| | | tifFile = Merge(metas, args, ref err); |
| | | if (!File.Exists(tifFile)) return null; |
| | | |
| | | string json = Path.Combine(dirPath, "layer.json"); |
| | | if (File.Exists(json)) File.Delete(json); |
| | | //Generate(args, tifFile, ref err); |
| | | CreateTerrain(args, tifFile, ref err); |
| | | |
| | | string json = Path.Combine(dirPath, "layer.json"); |
| | | if (!File.Exists(json)) return null; |
| | | |
| | | Complement(args); |
| | | |
| | | List<int> ids = new List<int>(); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message); |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | err = ex.Message; |
| | | return null; |
| | | } |
| | | finally |
| | | /*finally |
| | | { |
| | | if (!string.IsNullOrEmpty(tifFile) && File.Exists(tifFile)) |
| | | { |
| | | File.Delete(tifFile); |
| | | } |
| | | } |
| | | if (!string.IsNullOrEmpty(tifFile) && File.Exists(tifFile)) File.Delete(tifFile); |
| | | }*/ |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | string txtFile = null; |
| | | try |
| | | { |
| | | txtFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".txt"); |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath); |
| | | |
| | | txtFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".txt"); |
| | | string tifFile = Path.Combine(dirPath, args.dircode + ".tif"); |
| | | if (File.Exists(tifFile)) File.Delete(tifFile); |
| | | |
| | | WriteText(txtFile, metas); |
| | | int pubid = PubDBHelper.GetPushlishId(args.dircode, "DEM"); |
| | | if (pubid > 0 && File.Exists(tifFile)) |
| | | { |
| | | List<int> ids = PubDBHelper.GetPublishMetaId(pubid); |
| | | |
| | | List<SysMeta> news = new List<SysMeta>(); |
| | | foreach (SysMeta m in metas) |
| | | { |
| | | if (!ids.Contains(m.id)) news.Add(m); |
| | | } |
| | | if (0 == news.Count) return tifFile; |
| | | |
| | | string oldTif = Path.Combine(dirPath, args.dircode + "_old.tif"); |
| | | if (File.Exists(oldTif)) File.Delete(oldTif); |
| | | File.Move(tifFile, oldTif); |
| | | WriteText(txtFile, news, oldTif); |
| | | } |
| | | else |
| | | { |
| | | if (File.Exists(tifFile)) File.Delete(tifFile); |
| | | WriteText(txtFile, metas, null); |
| | | } |
| | | |
| | | string cmd = string.Format("python \"{0}\" -qgz {1} -file \"{2}\" -out \"{3}\"", PyFile, Qgz, txtFile, tifFile); |
| | | err = Tools.ExecCmd(cmd, true); |
| | | err = Tools.ExecCmd(cmd, true, false); |
| | | |
| | | return tifFile; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message); |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | err = ex.Message; |
| | | return null; |
| | | } |
| | | finally |
| | | { |
| | | if (!string.IsNullOrEmpty(txtFile) && File.Exists(txtFile)) |
| | | { |
| | | File.Delete(txtFile); |
| | | } |
| | | if (!string.IsNullOrEmpty(txtFile) && File.Exists(txtFile)) File.Delete(txtFile); |
| | | |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | string tifFile = Path.Combine(dirPath, args.dircode + ".tif"); |
| | | string oldTif = Path.Combine(dirPath, args.dircode + "_old.tif"); |
| | | if (File.Exists(tifFile) && File.Exists(oldTif)) File.Delete(oldTif); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 写文本文件 |
| | | /// </summary> |
| | | private static void WriteText(string txtFile, List<SysMeta> list) |
| | | private static void WriteText(string txtFile, List<SysMeta> list, string tif) |
| | | { |
| | | string uploadFolder = Tools.GetSetting("uploadFolder"); |
| | | |
| | | List<string> files = new List<string>(); |
| | | if (!string.IsNullOrEmpty(tif)) files.Add(tif); |
| | | foreach (SysMeta meta in list) |
| | | { |
| | | string filePath = Path.Combine(uploadFolder, meta.path); |
| | | if (File.Exists(filePath)) files.Add(filePath); |
| | | } |
| | | string str = string.Join("\n", files); |
| | | |
| | | string str = string.Join("\r\n", files); |
| | | File.WriteAllText(txtFile, str); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成高程切片 |
| | | /// 获取地形最大级别 |
| | | /// </summary> |
| | | private static void Generate(XYZArgs args, string tifFile, ref string err) |
| | | private static int GetTerrainMaxLevel(XYZArgs args, string tifFile) |
| | | { |
| | | string dirPath = GetTerrainPath(args.dircode).Replace("\\", "/"); |
| | | string name = "ctb_" + ExportUtil.DateStr; |
| | | string ctbPath = Tools.GetSetting("ctbPath"); |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | |
| | | string runDocker = string.Format("docker run -id --name {0} -v \"{1}\":\"/data\" tumgis/ctb-quantized-mesh", name, dirPath); |
| | | string createMesh = string.Format("docker exec {0} ctb-tile -f Mesh -C -N -s {1} -e {2} -o /data /data/{3}.tif", name, args.max, args.min, args.dircode); // Mesh, Terrain |
| | | string createLayer = string.Format("docker exec {0} ctb-tile -f Mesh -C -N -s {1} -e {2} -l -o /data /data/{3}.tif", name, args.max, args.min, args.dircode); // Mesh, Terrain |
| | | string stop = string.Format("docker stop {0}", name); |
| | | string rm = string.Format("docker rm {0}", name); |
| | | string gdal_data = string.Format("set GDAL_DATA={0}\\data", ctbPath); |
| | | string createLayer = string.Format("{0}\\ctb-tile.exe -l -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode); |
| | | |
| | | List<string> list = new List<string> { runDocker, createMesh, createLayer, stop, rm }; |
| | | err = Tools.ExecCmd(list); |
| | | Tools.ExecCmd(new List<string>() { gdal_data, createLayer }); |
| | | |
| | | string layerJson = Path.Combine(dirPath, "layer.json"); |
| | | if (!File.Exists(layerJson)) return DEFAULT_MAX_LEVEL; |
| | | |
| | | string[] lines = File.ReadAllLines(layerJson, Encoding.UTF8); |
| | | |
| | | int level = -1; |
| | | foreach (string line in lines) |
| | | { |
| | | if (line.IndexOf("startX") > -1) level++; |
| | | } |
| | | if (File.Exists(layerJson)) File.Delete(layerJson); |
| | | |
| | | return level; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | string ctbPath = Tools.GetSetting("ctbPath"); |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | int maxLevel = GetTerrainMaxLevel(args, tifFile); |
| | | |
| | | string gdal_data = string.Format("set GDAL_DATA={0}\\data", ctbPath); |
| | | string createMesh = string.Format("{0}\\ctb-tile.exe -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode); |
| | | string createLayer = string.Format("{0}\\ctb-tile.exe -l -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode); |
| | | // -N 顶点法线, -C 强制创建缺失根瓦片, -R 不覆盖现有文件 |
| | | string createMesh = string.Format("{0}\\ctb-tile.exe -R -C -s {4} -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode, maxLevel); |
| | | string createLayer = string.Format("{0}\\ctb-tile.exe -l -s {4} -o \"{1}\" -f Mesh \"{2}\\{3}.tif\"", ctbPath, dirPath, dirPath, args.dircode, maxLevel); |
| | | |
| | | List<string> list = new List<string>() { gdal_data, createMesh, createLayer }; |
| | | err = Tools.ExecCmd(list); |
| | |
| | | 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 d_0_0_0 = Path.Combine(dirPath, "0", "0", "0.terrain"); |
| | | File.Copy(s_0_0_0, d_0_0_0, true); |
| | | if (!File.Exists(d_0_0_0)) File.Copy(s_0_0_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"); |
| | | File.Copy(s_0_1_0, d_0_1_0, true); |
| | | if (!File.Exists(d_0_1_0)) File.Copy(s_0_1_0, d_0_1_0, true); |
| | | |
| | | string layerJson = Path.Combine(dirPath, "layer.json"); |
| | | string[] lines = File.ReadAllLines(layerJson, Encoding.UTF8); |
| | | lines[12] = " [ {\"endX\":1,\"endY\":0,\"startX\":0,\"startY\":0}],[{\"endX\":3,\"endY\":1,\"startX\":2,\"startY\":1} ]"; |
| | | //lines[12] = " [ { \"startX\": 0, \"startY\": 0, \"endX\": 1, \"endY\": 0 } ]"; |
| | | for (int i = 0, c = lines.Length; i < c; i++) |
| | | { |
| | | if (lines[i].IndexOf("startX") > -1) |
| | | { |
| | | lines[i] = " [ { \"startX\": 0, \"startY\": 0, \"endX\": 1, \"endY\": 0 } ]"; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | File.WriteAllLines(layerJson, lines, Encoding.UTF8); |
| | | } |
| | |
| | | /// </summary> |
| | | private static int InsertToDB(List<SysMeta> metas, XYZArgs args) |
| | | { |
| | | if (PubDBHelper.IsPublish(args.dircode, "DEM")) return 0; |
| | | //if (PubDBHelper.IsPublish(args.dircode, "DEM")) return 1; |
| | | int pubid = PubDBHelper.GetPushlishId(args.dircode, "DEM"); |
| | | if (pubid > 0) // 更新发布 |
| | | { |
| | | List<int> ids = PubDBHelper.GetPublishMetaId(pubid); |
| | | foreach (SysMeta m in metas) |
| | | { |
| | | if (!ids.Contains(m.id)) PubDBHelper.InsertMetaPub(m.id, pubid, args.userId); |
| | | } |
| | | string geom = GetPointZ(args); |
| | | PubDBHelper.UpdatePublish(pubid, args.name, args.userId, geom); |
| | | |
| | | return pubid; |
| | | } |
| | | |
| | | SysMeta meta = metas[0]; |
| | | meta.type = "DEM"; |
| | | meta.name = args.name; |
| | | meta.dircode = args.dircode; |
| | | |
| | | SysPublish sys = Tools.NewPublish(meta, args, GetReleaseUrl(args.dircode), "3d\\terrain\\" + args.dircode); |
| | | sys.geom = GetPointZ(args); |
| | | |
| | | int pubid = PubDBHelper.InsertPublish(sys); |
| | | pubid = PubDBHelper.InsertPublish(sys); |
| | | if (pubid > 0) |
| | | { |
| | | sys.id = pubid; |
| | |
| | | |
| | | return pubid; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取中心点 |
| | | /// </summary> |
| | | private static string GetPointZ(XYZArgs args) |
| | | { |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | string txtFile = Path.Combine(dirPath, args.dircode + "_cs.txt"); |
| | | if (!File.Exists(txtFile)) return null; |
| | | |
| | | string[] strs = File.ReadAllLines(txtFile, Encoding.UTF8); |
| | | // File.Delete(txtFile); // 删除坐标文件 |
| | | |
| | | if (null == strs || strs.Length == 0) return null; |
| | | string[] str = strs[0].Split(new string[] { ", " }, StringSplitOptions.None); |
| | | |
| | | int i = 18; |
| | | for (; i > -1; i--) |
| | | { |
| | | string path = Path.Combine(dirPath, i.ToString()); |
| | | if (Directory.Exists(path)) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return string.Format("ST_GeomFromText('POINT Z ({0} {1} {2})')", str[1], str[0], i); |
| | | } |
| | | |
| | | /*/// <summary> |
| | | /// 生成高程切片 * |
| | | /// </summary> |
| | | private static void Generate(XYZArgs args, string tifFile, ref string err) |
| | | { |
| | | string dirPath = GetTerrainPath(args.dircode).Replace("\\", "/"); |
| | | string name = "ctb_" + ExportUtil.DateStr; |
| | | |
| | | string runDocker = string.Format("docker run -id --name {0} -v \"{1}\":\"/data\" tumgis/ctb-quantized-mesh", name, dirPath); |
| | | string createMesh = string.Format("docker exec {0} ctb-tile -f Mesh -C -N -s {1} -e {2} -o /data /data/{3}.tif", name, args.max, args.min, args.dircode); // Mesh, Terrain |
| | | string createLayer = string.Format("docker exec {0} ctb-tile -f Mesh -C -N -s {1} -e {2} -l -o /data /data/{3}.tif", name, args.max, args.min, args.dircode); // Mesh, Terrain |
| | | string stop = string.Format("docker stop {0}", name); |
| | | string rm = string.Format("docker rm {0}", name); |
| | | |
| | | List<string> list = new List<string> { runDocker, createMesh, createLayer, stop, rm }; |
| | | err = Tools.ExecCmd(list); |
| | | }*/ |
| | | } |
| | | } |