管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-03 3cfb6aa02516135fb174ab1b30620f2007924663
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using TerraExplorerX;
using TETree;
using TEWin.CS;
 
namespace TEWin
{
    public partial class FrmWin : Form
    {
        #region 成员变量+构造函数+事件
        string fly;
 
        FrmTree tree;
 
        FrmTool tool;
 
        bool isAngle;
 
        int angleCount;
 
        double angleSize;
 
        public SGWorld71 SG;
 
        ITerrainLabel71 angleLabel;
 
        ITerrainPolyline71 angleLine;
 
        string angleGroupName = "角量算";
 
        string shpGroupName = "矢量数据";
 
        string mainUrl = Application.StartupPath;
 
        System.Timers.Timer timer;
 
        public FrmWin()
        {
            InitializeComponent();
            //this.KeyPreview = true;
            this.Load += FrmWeb_Load;
            //this.KeyDown += FrmWin_KeyDown;
            this.FormClosed += FrmWin_FormClosed;
 
            timer = new System.Timers.Timer(1500);
            timer.Elapsed += timer_Elapsed;
        }
 
        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            MoveWinPosition("MeshLayerTool", 583, 304);
        }
 
        void FrmWin_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.F1)
            {
                MoveWinPosition("MeshLayerTool", 400, 400);
            }
        }
 
        void FrmWeb_Load(object sender, EventArgs e)
        {
            try
            {
                LogOut.Info("开始运行..");
                bool isTest = "1" == ConfigurationManager.AppSettings["isTest"];
 
                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))
                {
                    LogOut.Error("Fly文件不存在:" + this.fly);
                    return;
                }
 
                SG = new SGWorld71();
                SG.OnLoadFinished += SG_OnLoadFinished;
 
                tree = new FrmTree();
                tree.Show(this);
 
                if (isTest)
                {
                    this.FormBorderStyle = FormBorderStyle.Sizable;
                    tree.FormBorderStyle = FormBorderStyle.Sizable;
                    tool = new FrmTool(this);
                    tool.Show();
 
                    SG.Open(this.fly);
                }
                //else
                //{
                //    this.WindowState = FormWindowState.Maximized;
                //    tree.WindowState = FormWindowState.Maximized;
                //}
 
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
 
        void SG_OnLoadFinished(bool bSuccess)
        {
            this.SG.OnLoadFinished -= SG_OnLoadFinished;
        }
 
        void FrmWin_FormClosed(object sender, FormClosedEventArgs e)
        {
            LogOut.Info("关闭程序.");
        }
        #endregion
 
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x64:
                    InvokeByCode(m.WParam.ToInt32()); break;
                case 0x4A:
                    MessageBox.Show("Test."); break;
                default:
                    base.DefWndProc(ref m); break;
            }
        }
 
        public void InvokeProc(int code)
        {
            Message m = new Message();
            m.Msg = 0x64; // m.Msg = 0x4A;
            m.WParam = new IntPtr(code);
 
            this.DefWndProc(ref m);
        }
 
        public void InvokeByCode(int code)
        {
            switch (code)
            {
                case 0xc0: // 重置鼠标模式
                    SG.Window.SetInputMode(0); break;
                case 0xc1: // 打开数据方案/打开显示场景
                    SG.Command.Execute(1001, null); break;
                case 0xc2: // 保存数据方案/保存显示场景
                    SG.Command.Execute(1003, null); break;
                case 0xc3: // 矢量数据(默认为*.shp,支持Excel)
                    SG.Command.Execute(1013, 5); break;
                case 0xc4: // 影像数据(默认为*.tif)
                    SG.Command.Execute(1014, 9); break;
                case 0xc5: // 地形数据(默认为*.tif)
                    SG.Command.Execute(1014, 26); break;
                case 0xc6: // 模型数据(*.osgb)
                    ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); // SG.Command.Execute(2342, null);
                    //RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer
                    RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer
                    timer.Stop();
                    timer.Start();
                    break;
                case 0xc7: // 模型数据(*.obj)
                    SG.Command.Execute(1012, 13); break;
                case 0xc8: // 编辑数据(选择对象,开启编辑)
                    SG.Command.Execute(1021, null); break;
                case 0xc9: // 点量算(坐标+高程)
                    SG.Command.Execute(1023, null); break;
                case 0xca: // 点量算(坡度+坡向)
                    this.ShowHtmlByid(1149, 24); break;
                case 0xcb: // 线量算
                    this.ShowHtmlByid(1034, 0); break; // SG.Command.Execute(2356, null); break;
                case 0xcc: // 面量算
                    // if (SG.Command.IsChecked(2359, null)) SG.Window.SetInputMode(0); else SG.Command.Execute(2359, null); break;
                    this.ShowHtmlByid(1037, 0); break;
                case 0xcd: // 体量算(挖填方)
                    this.ShowHtmlByid(1045, 0); break;
                case 0xce: // 角量算
                    AngleMeasurement(); break;
                case 0xcf: // 空间统计
                    SpaceStatistics(); break;
                case 0xd0: // 空间分析
                    SpatialAnalysis(); break;
                case 0xd1: // DEM分析(剖面分析)
                    this.ShowHtmlByid(1149, 28); break;
                case 0xd2: // DEM分析(坡度分析)
                    this.ShowHtmlByid(1093, 0); break;
                case 0xd3: // DEM分析(等值线)
                    SG.Command.Execute(1039, null); break;
                case 0xd4: // 三维模型分析(剖切分析)
                    this.ShowHtmlByid(1149, 39); break;
                case 0xd5: // 地理场景产品组装(抽取指定区域并发布离线数据包)
                    SG.Command.Execute(1028, null); break;
                case 0xd6: // 传统4D产品派生(集成osgblab)
                    InvokeOsgbLab(); break;
                case 0xd7: // 打开fly
                    SG.Open(this.fly); break;
                case 0xd8: // 加载shp
                    LoadShp(); break;
                case 0xd9: // 读取shp
                    ReadShp(); break;
                case 0xda: // 按照属性显示
                    DisplayByAttribute(0, "按照属性显示"); break;
                case 0xdb: // 按照属性设置颜色
                    DisplayByAttribute(1, "按照属性设置颜色"); break;
            }
        }
 
        #region user32.dll
        public const int SWP_NOSIZE = 0x0001;
 
        public const int SWP_NOMOVE = 0x0002;
 
        public const int SWP_NOZORDER = 0x0004;
 
        public const int SWP_SHOWWINDOW = 0x0040;
 
        public const int HWND_TOPMOST = -1;
 
        public const int HWND_NOTOPMOST = -2;
 
        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
 
        [DllImport("user32.dll", SetLastError = true)]
        static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
 
        [Serializable]
        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }
 
        public void MoveWinPosition(String name, int left, int right)
        {
            Process[] processes = Process.GetProcessesByName(name);
            if (processes.Length > 0)
            {
                Process process = processes[0];
                IntPtr hWnd = process.MainWindowHandle;
 
                // 获取窗体的坐标
                RECT rect;
                GetWindowRect(hWnd, out rect);
 
                if (rect.Left < 0 || rect.Left > 1920 || rect.Top < 0 || rect.Top > 1080)
                {
                    timer.Stop();
                    // 移动窗口到屏幕上的位置:
                    SetWindowPos(hWnd, IntPtr.Zero, left, right, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
                }
            }
        }
 
        public static void Main()
        {
            // 获取指定窗体的句柄
            //IntPtr hWnd = // 获取窗体句柄的方法,例如FindWindow或者通过进程名获取
            // 获取窗体的坐标
            //RECT rect;
            //GetWindowRect(hWnd, out rect);
            //Console.WriteLine("窗体坐标: 左上角({0}, {1}), 右下角({2}, {3})", rect.Left, rect.Top, rect.Right, rect.Bottom);
        }
        #endregion
 
        public void ShowHtmlByid(int id, int arg)
        {
            switch (id)
            {
                case 1034:
                    this.ShowHtml("距离测量", mainUrl + @"\Resources\DistanceMeasurement\distanceMeasurement.html", 20, 20, 400, 275);
                    break;
                case 1037:
                    this.ShowHtml("面积测量", mainUrl + @"/Resources\AreaMeasurement\AreaMeasurement.html", 20, 20, 400, 205);
                    break;
                case 1149:
                    switch (arg)
                    {
                        case 24:
                            this.ShowHtml("坡向分析", mainUrl + @"\Resources\SlopeCursor\SlopeCursor.html", 20, 20, 400, 330); break;
                        case 28:
                            this.ShowHtml("剖面分析", mainUrl + @"\Resources\TerrainProfile\TerrainProfile.html", 20, 20, 400, 265); break;
                        case 39:
                            this.ShowHtml("剖切分析", mainUrl + @"\Resources\CrossSection\CrossSection.html", 20, 20, 400, 225); break;
                    }
                    break;
                case 1093:
                    this.ShowHtml("坡度分析", mainUrl + @"\Resources\SlopeMapQuery\SlopeMapQuery.html", 20, 20, 350, 365);
                    break;
                case 1045:
                    this.ShowHtml("体积分析", mainUrl + @"\Resources\Volume\Volume.html", 20, 20, 350, 225);
                    break;
            }
        }
 
        public void ShowHtml(string tile, string url, int left, int top, int width, int height)
        {
            if (SG.Window.GetPopupByCaption(tile) != null)
            {
                SG.Window.RemovePopupByCaption(tile);
            }
 
            var popup = SG.Creator.CreatePopupMessage(tile, url, left, top, width, height);
            popup.AllowResize = true;
            popup.ShowCaption = true;
            popup.AllowDrag = true;
            popup.Width = width;
            popup.Height = height;
 
            SG.Window.ShowPopup(popup);
        }
 
        public void RunExe(string path, string args, bool noWindow = true)
        {
            Process p = new Process();
            p.StartInfo.FileName = path;
            if (!string.IsNullOrEmpty(args)) p.StartInfo.Arguments = args;
            p.StartInfo.CreateNoWindow = noWindow;
            p.StartInfo.UseShellExecute = false;
            p.Start();
        }
 
        public static string ExecCmd(List<string> list)
        {
            string str = null;
            Process p = null;
            try
            {
                p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.Start();
 
                StreamWriter si = p.StandardInput;
                StreamReader se = p.StandardError;
 
                LogOut.Info("cmd = " + string.Join(",", list));
                si.AutoFlush = true;
                foreach (string cmd in list)
                {
                    si.WriteLine(cmd);
                }
                si.WriteLine("exit");
 
                str = se.ReadToEnd();
                se.Close();
                si.Close();
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                str = ex.Message;
            }
            finally
            {
                if (p != null)
                {
                    p.Close();
                }
            }
 
            return str;
        }
 
        #region 角量算
        private void AngleMeasurement()
        {
            if (isAngle)
            {
                DeleteGroup(angleGroupName);
                RmAngleEvent();
                isAngle = false;
                return;
            }
 
            isAngle = true;
            AddAngleEvent();
        }
 
        private string GetGroupId(string groupName)
        {
            string gid = SG.ProjectTree.FindItem(groupName);
            if (!string.IsNullOrEmpty(gid)) return gid;
 
            return SG.ProjectTree.CreateLockedGroup(groupName);
        }
 
        private void DeleteGroup(string groupName)
        {
            try
            {
                string gid = SG.ProjectTree.FindItem(groupName);
                if (!string.IsNullOrEmpty(gid))
                {
                    SG.ProjectTree.DeleteItem(gid);
                }
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
 
        private void AddAngleEvent()
        {
            RmAngleEvent();
 
            SG.OnFrame += Angle_OnFrame;
            SG.OnLButtonDown += Angle_OnLButtonDown;
            SG.OnRButtonUp += Angle_OnRButtonUp;
            SG.Window.SetInputMode(MouseInputMode.MI_COM_CLIENT);
        }
 
        private void RmAngleEvent()
        {
            SG.OnFrame -= Angle_OnFrame;
            SG.OnLButtonDown -= Angle_OnLButtonDown;
            SG.OnRButtonUp -= Angle_OnRButtonUp;
            SG.Window.SetInputMode(MouseInputMode.MI_FREE_FLIGHT);
        }
 
        void Angle_OnFrame()
        {
            if (null == angleLine) return;
 
            try
            {
                var mouseInfo = SG.Window.GetMouseInfo();
                var CursorCoord = SG.Window.PixelToWorld(mouseInfo.X, mouseInfo.Y, WorldPointType.WPT_DEFAULT);
                if (CursorCoord == null) return;
 
                ILineString line = (ILineString)(angleLine.Geometry);
                IPoint p = (IPoint)line.Points[line.Points.Count - 1];
                p.X = CursorCoord.Position.X;
                p.Y = CursorCoord.Position.Y;
                p.Z = 0;
 
                if (angleCount % 3 == 2)
                {
                    IPoint firstPoint = (IPoint)line.Points[line.Points.Count - 3];
                    IPoint secondPoint = (IPoint)line.Points[line.Points.Count - 2];
                    IPoint nowPoint = (IPoint)line.Points[line.Points.Count - 1];
                    var firstPosition = SG.Creator.CreatePosition(firstPoint.X, firstPoint.Y);
                    var secondPosition = SG.Creator.CreatePosition(secondPoint.X, secondPoint.Y);
                    var nowPosition = SG.Creator.CreatePosition(nowPoint.X, nowPoint.Y);
 
                    nowPosition = SG.CoordServices.GetAimingAngles(nowPosition, secondPosition);
                    secondPosition = SG.CoordServices.GetAimingAngles(firstPosition, secondPosition);
                    if (secondPosition.Yaw > nowPosition.Yaw)
                    {
                        angleSize = secondPosition.Yaw - nowPosition.Yaw;
                        if (angleSize > 180) angleSize = 360 - secondPosition.Yaw + nowPosition.Yaw;
                    }
                    else
                    {
                        angleSize = nowPosition.Yaw - secondPosition.Yaw;
                        if (angleSize > 180) angleSize = 360 + secondPosition.Yaw - nowPosition.Yaw;
                    }
                    angleSize = Math.Round(angleSize, 2);
                    angleLabel.Text = angleSize.ToString() + "°";
                }
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
 
        bool Angle_OnLButtonDown(int Flags, int X, int Y)
        {
            try
            {
                var CursorCoord = SG.Window.PixelToWorld(X, Y, WorldPointType.WPT_DEFAULT);
                if (CursorCoord == null) return false;
 
                var gid = GetGroupId(angleGroupName);
                if (angleLine == null)
                {
                    IList<double> lineVertex = new List<double>();
                    lineVertex.Add(CursorCoord.Position.X);
                    lineVertex.Add(CursorCoord.Position.Y);
                    lineVertex.Add(0);
                    lineVertex.Add(CursorCoord.Position.X);
                    lineVertex.Add(CursorCoord.Position.Y);
                    lineVertex.Add(0);
 
                    double[] px = new double[lineVertex.Count];
                    lineVertex.CopyTo(px, 0);
                    var myGeometry = SG.Creator.GeometryCreator.CreateLineStringGeometry(px);
 
                    angleLine = SG.Creator.CreatePolyline(myGeometry, SG.Creator.CreateColor(255, 255, 0, 255), AltitudeTypeCode.ATC_TERRAIN_RELATIVE, gid, angleCount.ToString());
                    angleLine.LineStyle.Width = -2;
                    angleLine.Geometry.StartEdit();
                    angleCount++;
 
                    return true;
                }
 
                if (angleCount % 3 == 1)
                {
                    angleLabel = SG.Creator.CreateLabel(CursorCoord.Position, angleSize.ToString(), "", null, gid, angleCount.ToString());
                    var LableColor = SG.Creator.CreateColor();
                    LableColor.FromHTMLColor("#FFFF00");
                    LableColor.SetAlpha(0.6);
                    angleLabel.Style.TextColor = LableColor;
                    angleLabel.Style.Bold = true;
                    angleLabel.Style.FontName = "黑体";
                    angleLabel.Style.FontSize = 12;
                    // angleLabel.Style.LineToGround = true;
                    angleLabel.Style.LineToGroundType = LineType.LINE_TYPE_TO_GROUND;
                    angleLabel.Style.Scale = 5000;
                }
 
                if (angleCount % 3 == 2) angleLabel.Text = angleSize.ToString() + "°";
                angleCount++;
 
                ILineString line = (ILineString)(angleLine.Geometry);
                IPoint p = (IPoint)line.Points[line.Points.Count - 1];
                p.X = CursorCoord.Position.X; ;
                p.Y = CursorCoord.Position.Y;
                p.Z = 0;
                line.Points.AddPoint(CursorCoord.Position.X, CursorCoord.Position.Y, 0);
                if (angleCount == 3)
                {
                    angleSize = 0;
                    angleCount = 0;
                    angleLine = null;
                    angleLabel = null;
                }
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
 
            return true;
        }
 
        bool Angle_OnRButtonUp(int Flags, int X, int Y)
        {
            DeleteGroup(angleGroupName);
            RmAngleEvent();
            angleCount = 0;
            angleSize = 0;
            isAngle = false;
 
            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, 285);
        }
 
        private void SpatialAnalysis()
        {
            this.ShowHtml("空间分析", mainUrl + @"\Resources\SpatialQuery\SpatialQuery.html", 20, 20, 420, 285);
        }
 
        private void InvokeOsgbLab()
        {
            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
            RunExe(GetAbsolutePath("osgblabPath"), null, false);
        }
 
        private void DisplayByAttribute(int type, String name)
        {
            this.ShowHtml(name, mainUrl + @"\Resources\DisplayByAttribute\DisplayByAttribute.html?Type=" + type + "&lang=2052", 20, 20, 365, 355);
        }
 
        #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
    }
}