From 614480aec772ce65205fa9d674e1ee8c623f375f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 24 四月 2024 10:12:53 +0800 Subject: [PATCH] 加载shp文件 --- TEWin/FrmWin.cs | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs index 6f74974..9757f88 100644 --- a/TEWin/FrmWin.cs +++ b/TEWin/FrmWin.cs @@ -38,6 +38,8 @@ string angleGroupName = "瑙掗噺绠�"; + string shpGroupName = "鐭㈤噺鏁版嵁"; + string mainUrl = Application.StartupPath; public FrmWin() @@ -178,6 +180,8 @@ InvokeOsgbLab(); break; case 0xd7: // 鎵撳紑fly SG.Open(this.fly); break; + case 0xd8: // 鍔犺浇shp + LoadShp(); break; } } @@ -492,5 +496,40 @@ ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" }); RunExe(GetAbsolutePath("osgblabPath"), null, false); } + + private void LoadShp() + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Shapefile鏂囦欢 (*.shp)|*.shp"; + dialog.RestoreDirectory = true; + + if (dialog.ShowDialog() == DialogResult.OK) + { + LoadShp(dialog.FileName); + } + } + + private void LoadShp(string shpFile) + { + 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); + } + + 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; + } } } -- Gitblit v1.9.3