| | |
| | | { |
| | | private static string pyFile; |
| | | |
| | | private static int terrainMaxLevel = 0; |
| | | |
| | | /// <summary> |
| | | /// 地形最大级别 |
| | | /// </summary> |
| | | public static int TERRAIN_MAX_LEVEL |
| | | { |
| | | get |
| | | { |
| | | if (0 == terrainMaxLevel) |
| | | { |
| | | string str = Tools.GetSetting("terrainMaxLevel"); |
| | | if (!int.TryParse(str, out terrainMaxLevel)) |
| | | { |
| | | terrainMaxLevel = 14; |
| | | } |
| | | } |
| | | |
| | | return terrainMaxLevel; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 默认最大文件大小:5GB |
| | | /// </summary> |
| | | public static long DEFAULT_MAX_SIZE = 5L * 1024 * 1024 * 1024; |
| | | |
| | | /// <summary> |
| | | /// 获取Python文件 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | public static string GetReleaseUrl(string dircode) |
| | | { |
| | | return "http://{host}/LFData/3d/terrain/" + dircode; |
| | | return "{host}/LFData/3d/terrain/" + dircode; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | try |
| | | { |
| | | List<SysMeta> metas = XYZUtils.SelectMetas(args.ids, "and type in ('tif', 'tiff')"); |
| | | if (null == metas || metas.Count == 0) return null; |
| | | if (null == metas || metas.Count == 0) |
| | | { |
| | | LogOut.Info("TerraUtils:找不到元数据。"); |
| | | return null; |
| | | } |
| | | |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | //if (Directory.Exists(dirPath)) Tools.DelPath(dirPath); // 已存在的,删除 |
| | | |
| | | tifFile = Merge(metas, args, ref err); |
| | | if (!File.Exists(tifFile)) return null; |
| | | if (!File.Exists(tifFile)) |
| | | { |
| | | LogOut.Info("TerraUtils:找不到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); |
| | | |
| | | if (!File.Exists(json)) return null; |
| | | if (!File.Exists(json)) |
| | | { |
| | | LogOut.Info("TerraUtils:找不到layer.json文件。"); |
| | | return null; |
| | | } |
| | | Complement(args); |
| | | |
| | | List<int> ids = new List<int>(); |
| | |
| | | } |
| | | else |
| | | { |
| | | if (File.Exists(tifFile)) File.Delete(tifFile); |
| | | //if (File.Exists(tifFile)) File.Delete(tifFile); |
| | | WriteText(txtFile, metas, null); |
| | | if (File.Exists(tifFile)) return tifFile; |
| | | } |
| | | |
| | | string cmd = string.Format("python \"{0}\" -qgz {1} -file \"{2}\" -out \"{3}\"", PyFile, Qgz, txtFile, tifFile); |
| | | err = Tools.ExecCmd(cmd, true, false); |
| | | SysTask task = TaskDBHelper.CreateTask(args, "DEM", "高程镶嵌(DEM)"); |
| | | err = Tools.ExecCmd(task, cmd, true); |
| | | |
| | | task = TaskDBHelper.SelectById(task.id); |
| | | if (null == task || task.status != 2) LogOut.Info("TerraUtils:任务为空或状态不为2。"); |
| | | |
| | | return tifFile; |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取地形最大级别 |
| | | /// </summary> |
| | | private static int GetTerrainMaxLevel(XYZArgs args, string tifFile) |
| | | { |
| | | FileInfo fi = new FileInfo(tifFile); |
| | | if (fi.Length > DEFAULT_MAX_SIZE) return TERRAIN_MAX_LEVEL; |
| | | |
| | | string ctbPath = Tools.GetSetting("ctbPath"); |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | |
| | | 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); |
| | | |
| | | Tools.ExecCmd(new List<string>() { gdal_data, createLayer }); |
| | | |
| | | string layerJson = Path.Combine(dirPath, "layer.json"); |
| | | if (!File.Exists(layerJson)) return TERRAIN_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 > TERRAIN_MAX_LEVEL ? TERRAIN_MAX_LEVEL : level; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建高程切片 |
| | | /// </summary> |
| | | private static void CreateTerrain(XYZArgs args, string tifFile, ref string err) |
| | | { |
| | | 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 -R -C -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); |
| | | SysTask task = TaskDBHelper.CreateTask(args, "DEM", "高程数据(DEM)"); |
| | | err = Tools.ExecCmd(task, list); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | string layerJson = Path.Combine(dirPath, "layer.json"); |
| | | string[] lines = File.ReadAllLines(layerJson, Encoding.UTF8); |
| | | lines[12] = " [ {\"endX\":1,\"endY\":0,\"startX\":0,\"startY\":0} ]"; |
| | | //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); |
| | | } |
| | |
| | | if (!ids.Contains(m.id)) PubDBHelper.InsertMetaPub(m.id, pubid, args.userId); |
| | | } |
| | | string geom = GetPointZ(args); |
| | | if (!string.IsNullOrEmpty(geom)) PubDBHelper.UpdatePublishGeom(pubid, geom); |
| | | 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); |
| | |
| | | if (!File.Exists(txtFile)) return null; |
| | | |
| | | string[] strs = File.ReadAllLines(txtFile, Encoding.UTF8); |
| | | File.Delete(txtFile); |
| | | // File.Delete(txtFile); // 删除坐标文件 |
| | | |
| | | if (null == strs || strs.Length == 0) return null; |
| | | string[] str = strs[0].Split(new string[] { ", " }, StringSplitOptions.None); |