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 +++++++++++++++++++++++++++++++++++++++ TEWin/FrmTool.cs | 2 +- 2 files changed, 40 insertions(+), 1 deletions(-) diff --git a/TEWin/FrmTool.cs b/TEWin/FrmTool.cs index 8357666..2fcf483 100644 --- a/TEWin/FrmTool.cs +++ b/TEWin/FrmTool.cs @@ -13,7 +13,7 @@ { FrmWin win; - List<string> codes = new List<string> { "閲嶇疆榧犳爣", "鎵撳紑鏂规", "淇濆瓨鏂规", "鐭㈤噺鏁版嵁", "褰卞儚鏁版嵁", "鍦板舰鏁版嵁", "妯″瀷鏁版嵁(osgb)", "妯″瀷鏁版嵁(obj)", "缂栬緫鏁版嵁", "鐐归噺绠�", "鍧″悜鍒嗘瀽", "绾块噺绠�", "闈㈤噺绠�", "浣撻噺绠�", "瑙掗噺绠�", "绌洪棿缁熻", "绌洪棿鍒嗘瀽", "鍓栭潰鍒嗘瀽", "鍧″害鍒嗘瀽", "绛夊�肩嚎", "鍓栧垏鍒嗘瀽", "鍦扮悊鍦烘櫙浜у搧缁勮", "浼犵粺4D浜у搧娲剧敓", "鎵撳紑fly" }; + List<string> codes = new List<string> { "閲嶇疆榧犳爣", "鎵撳紑鏂规", "淇濆瓨鏂规", "鐭㈤噺鏁版嵁", "褰卞儚鏁版嵁", "鍦板舰鏁版嵁", "妯″瀷鏁版嵁(osgb)", "妯″瀷鏁版嵁(obj)", "缂栬緫鏁版嵁", "鐐归噺绠�", "鍧″悜鍒嗘瀽", "绾块噺绠�", "闈㈤噺绠�", "浣撻噺绠�", "瑙掗噺绠�", "绌洪棿缁熻", "绌洪棿鍒嗘瀽", "鍓栭潰鍒嗘瀽", "鍧″害鍒嗘瀽", "绛夊�肩嚎", "鍓栧垏鍒嗘瀽", "鍦扮悊鍦烘櫙浜у搧缁勮", "浼犵粺4D浜у搧娲剧敓", "鎵撳紑fly", "鍔犺浇shp" }; public FrmTool(FrmWin win) { 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