管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-07-23 a55f5510720c2eda302c771021e84c7bd2ee47c3
TEWin/FrmWin.cs
@@ -24,21 +24,23 @@
        FrmTool tool;
        string mainUrl;
        bool isAngle;
        int angleCount;
        double angleSize;
        public SGWorld71 SG;
        private bool isAngle;
        ITerrainLabel71 angleLabel;
        private int angleCount;
        ITerrainPolyline71 angleLine;
        private double angleSize;
        string angleGroupName = "角量算";
        private ITerrainLabel71 angleLabel;
        string shpGroupName = "矢量数据";
        private ITerrainPolyline71 angleLine;
        private string angleGroupName = "角量算";
        string mainUrl = Application.StartupPath;
        public FrmWin()
        {
@@ -52,10 +54,8 @@
            try
            {
                LogOut.Info("开始运行..");
                mainUrl = Application.StartupPath;
                bool isTest = "1" == ConfigurationManager.AppSettings["isTest"];
                //this.fly = isTest ? ConfigurationManager.AppSettings["testFly"] : Path.Combine(Application.StartupPath, "Resources\\sample.fly");
                this.fly = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"];
                if (!this.fly.Contains(":\\")) this.fly = Path.Combine(Application.StartupPath, this.fly);
                if (!File.Exists(this.fly))
@@ -147,7 +147,7 @@
                    break;
                case 0xc7: // 模型数据(*.obj)
                    SG.Command.Execute(1012, 13); break;
                case 0xc8: // 基础编辑(选择对象,开启编辑)
                case 0xc8: // 编辑数据(选择对象,开启编辑)
                    SG.Command.Execute(1021, null); break;
                case 0xc9: // 点量算(坐标+高程)
                    SG.Command.Execute(1023, null); break;
@@ -180,6 +180,10 @@
                    InvokeOsgbLab(); break;
                case 0xd7: // 打开fly
                    SG.Open(this.fly); break;
                case 0xd8: // 加载shp
                    LoadShp(); break;
                case 0xd9: // 读取shp
                    ReadShp(); break;
            }
        }
@@ -234,7 +238,7 @@
        {
            Process p = new Process();
            p.StartInfo.FileName = path;
            p.StartInfo.Arguments = args;
            if (!string.IsNullOrEmpty(args)) p.StartInfo.Arguments = args;
            p.StartInfo.CreateNoWindow = noWindow;
            p.StartInfo.UseShellExecute = false;
            p.Start();
@@ -286,7 +290,7 @@
            return str;
        }
        #region 角量算+空间统计+空间分析+osgblab
        #region 角量算
        private void AngleMeasurement()
        {
            if (isAngle)
@@ -470,10 +474,18 @@
            return true;
        }
        #endregion
        private string GetAbsolutePath(string key)
        {
            string str = ConfigurationManager.AppSettings[key];
            return str.Contains(":\\") ? str : Path.Combine(Application.StartupPath, str);
        }
        private void SpaceStatistics()
        {
            this.ShowHtml("空间统计", mainUrl + @"\Resources\SpaceStatistics\SpaceStatistics.html", 20, 20, 420, 260);
            this.ShowHtml("空间统计", mainUrl + @"\Resources\SpaceStatistics\SpaceStatistics.html", 20, 20, 420, 285);
        }
        private void SpatialAnalysis()
@@ -483,7 +495,109 @@
        private void InvokeOsgbLab()
        {
            //
            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
            RunExe(GetAbsolutePath("osgblabPath"), null, false);
        }
        #region 加载shp + 读取shp
        private void LoadShp()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Shapefile文件 (*.shp)|*.shp";
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string shpFile = dialog.FileName;
                if (LoadShp(shpFile))
                {
                    sendShpFile(shpFile);
                }
            }
        }
        private bool LoadShp(string shpFile)
        {
            try
            {
                string gid = GetGroupIdByName(shpGroupName);
                string conn = "FileName=" + shpFile + ";TEPlugName=OGR;"; // 连接字符串
                string shpName = Path.GetFileNameWithoutExtension(shpFile);
                IFeatureLayer71 layer = SG.Creator.CreateFeatureLayer(shpName, conn, gid); // 加载shp
                layer.Refresh();
                SG.Navigate.FlyTo(layer.ID);
                return true;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return false;
            }
        }
        private string GetGroupIdByName(string groupName)
        {
            string gid = SG.ProjectTree.FindItem(groupName);
            if (string.IsNullOrEmpty(gid) || !SG.ProjectTree.IsGroup(gid))
            {
                gid = SG.ProjectTree.CreateGroup(groupName, SG.ProjectTree.RootID);
            }
            return gid;
        }
        private void sendShpFile(string shpFile)
        {
            try
            {
                string shpTxtPath = GetShpTxtPath();
                using (StreamWriter sw = new StreamWriter(shpTxtPath, false))
                {
                    sw.Write(shpFile.Replace("\\", "/"));
                }
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        private void ReadShp()
        {
            try
            {
                string shpTxtPath = GetShpTxtPath();
                if (string.IsNullOrEmpty(shpTxtPath) || !File.Exists(shpTxtPath))
                {
                    return;
                }
                string shpFile = File.ReadAllText(shpTxtPath);
                if (string.IsNullOrEmpty(shpFile) || !shpFile.ToLower().EndsWith(".shp") || !File.Exists(shpFile))
                {
                    return;
                }
                LoadShp(shpFile);
                File.Delete(shpTxtPath);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        private string GetShpTxtPath()
        {
            string shpTxtPath = ConfigurationManager.AppSettings["shpTxtPath"];
            if (!shpTxtPath.Contains(":\\"))
            {
                shpTxtPath = Path.Combine(Application.StartupPath, shpTxtPath);
            }
            return shpTxtPath;
        }
        #endregion
    }