管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-06-21 d9c6232dac8c1af6586d116fe558d154feb46011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using ExportMap.db;
using ExportMap.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
 
namespace ExportMap.cs
{
    public class OsgbUtils
    {
        /// <summary>
        /// 获取路径
        /// </summary>
        public static string GetPath(int id)
        {
            return Path.Combine(SGUtils.LFData, "3d\\3dtiles\\osgb", id.ToString());
        }
 
        /// <summary>
        /// 获取发布地址
        /// </summary>
        public static string GetReleaseUrl(SysMeta meta)
        {
            return "http://{host}/LFData/3d/3dtiles/osgb/" + meta.id + "/tileset.json";
        }
 
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="args">XYZ参数</param>
        /// <param name="err">错误信息</param>
        /// <returns>数据发布ID集合</returns>
        public static List<int> Generate(XYZArgs args, ref string err)
        {
            try
            {
                List<SysMeta> list = XYZUtils.SelectMetas(args.ids, "and type = 'osgb'");
                if (null == list || list.Count == 0) return null;
 
                string d3tilesPath = Tools.GetSetting("d3tilesPath");
                string uploadFolder = Tools.GetSetting("uploadFolder");
 
                List<int> ids = new List<int>();
                foreach (SysMeta meta in list)
                {
                    string osgbPath = Path.Combine(uploadFolder, meta.path);
                    if (!Directory.Exists(osgbPath)) continue;
 
                    meta.ismeta = 0; // 0-倾斜摄影数据
                    string outPath = GetPath(meta.id);
                    string jsonFile = Path.Combine(outPath, "tileset.json");
 
                    if (args.isNew && Directory.Exists(outPath)) Tools.DelPath(outPath);
                    if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);
                    if (File.Exists(jsonFile)) File.Delete(jsonFile);
 
                    string cmd = string.Format("{0}\\3dtile.exe -f osgb -i \"{1}\" -o \"{2}\"", d3tilesPath, osgbPath, outPath);
                    err = Tools.ExecCmd(cmd, false, false);
 
                    if (File.Exists(jsonFile))
                    {
                        string path = jsonFile.Replace(Tools.GetSetting("lfData") + "\\", "");
                        int pubid = InsertToDB(meta, args, path);
                        if (pubid > 0) ids.Add(pubid);
                    }
                }
 
                return ids;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                err = ex.Message;
                return null;
            }
        }
 
        /// <summary>
        /// 插入数据库
        /// </summary>
        private static int InsertToDB(SysMeta meta, XYZArgs args, string path)
        {
            if (PubDBHelper.IsPublish(meta.id)) return 0;
 
            SysPublish sys = Tools.NewPublish(meta, args, GetReleaseUrl(meta), path);
 
            int pubid = PubDBHelper.InsertPublish(sys);
            if (pubid > 0)
            {
                sys.id = pubid;
                PubDBHelper.InsertLayer(sys, meta);
                PubDBHelper.InsertMetaPub(meta.id, pubid, args.userId);
            }
 
            return pubid;
        }
    }
}